summaryrefslogtreecommitdiff
path: root/hot/mistral/templates/autoscaling_using_mistral.yaml
blob: 444c64d79fd97d52c40d04cba1119c8f1b8dc34f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
heat_template_version: 2015-04-30

description: >
  Example of using mistral resources for autoscale testing. In this template
  workflows are used to get ip of the server and to load/release cpu and
  triggers allow to execute these workflows (every 10 minutes by default).

parameters:
  flavor:
    type: string
    default: m1.heat
    description: Name or ID of flavor

  image:
    type: string
    default: cirros-0.3.4-x86_64-uec
    description: Name or ID of image

  security_group_name:
    type: string

  user:
    type: string
    default: cirros
    description: User to access instances

  password:
    type: string
    default: 'gocubsgo'
    description: Password to access instances

  pattern_release:
    type: string
    default: "0,20,40 * * * *"
    description: Time to execute workflow wf_release_cpu

  pattern_load:
    type: string
    default: "10,30,50 * * * *"
    description: Time to execute workflow wf_load_cpu

  remaining_executions:
    type: number
    default: 3
    description: The number of occurrences after which the triggers should be deleted.

resources:
  my_asg:
    type: OS::Heat::AutoScalingGroup
    properties:
      resource:
        type: NovaNetwork::Server
        properties:
          image: { get_param: image }
          flavor: { get_param: flavor }
          security_group: {get_param: security_group_name}
          metadata: {"metering.stack": {get_param: "OS::stack_id"}}
      min_size: 1
      max_size: 2

  scale_up_policy:
    type: OS::Heat::ScalingPolicy
    properties:
      adjustment_type: change_in_capacity
      auto_scaling_group_id: {get_resource: my_asg}
      cooldown: 60
      scaling_adjustment: 1

  scale_down_policy:
    type: OS::Heat::ScalingPolicy
    properties:
      adjustment_type: change_in_capacity
      auto_scaling_group_id: {get_resource: my_asg}
      cooldown: 60
      scaling_adjustment: '-1'

  cpu_alarm_high:
    type: OS::Ceilometer::Alarm
    properties:
      description: Scale-up if the average CPU > 50% for 1 minute
      meter_name: cpu_util
      statistic: avg
      period: 60
      evaluation_periods: 1
      threshold: 50
      alarm_actions:
        - {get_attr: [scale_up_policy, alarm_url]}
      matching_metadata: {'metadata.user_metadata.stack': {get_param: "OS::stack_id"}}
      comparison_operator: gt

  cpu_alarm_low:
    type: OS::Ceilometer::Alarm
    properties:
      description: Scale-down if the average CPU < 15% for 1 minutes
      meter_name: cpu_util
      statistic: avg
      period: 60
      evaluation_periods: 1
      threshold: 15
      alarm_actions:
        - {get_attr: [scale_down_policy, alarm_url]}
      matching_metadata: {'metadata.user_metadata.stack': {get_param: "OS::stack_id"}}
      comparison_operator: lt

  wf_load_cpu:
    type: OS::Mistral::Workflow
    properties:
      type: direct
      tasks:
        - name: get_output
          action: heat.stacks_get stack_id=<% $.stack_id %>
          publish:
            vm_ip: <% $.get_output._info.outputs[0].output_value %>
          on_success:
            - run_ssh
        - name: run_ssh
          action: std.ssh cmd='cat /dev/urandom | gzip -9 > /dev/null &' host=<% $.vm_ip %> username=<% $.user %> password=<% $.password %>
      input: {'user': {get_param: user}, 'password': {get_param: password}, 'stack_id': {get_param: "OS::stack_id"}}

  wf_release_cpu:
    type: OS::Mistral::Workflow
    properties:
      type: direct
      tasks:
        - name: get_output
          action: heat.stacks_get stack_id=<% $.stack_id %>
          publish:
            vm_ip: <% $.get_output._info.outputs[0].output_value %>
          on_success:
            - run_ssh
        - name: run_ssh
          action: std.ssh cmd="kill -9 $(ps aux | grep 'cat /dev/urandom' | awk '{print $1}')" host=<% $.vm_ip %> username=<% $.user %> password=<% $.password %>
      input: {'user': {get_param: user}, 'password': {get_param: password}, 'stack_id': {get_param: "OS::stack_id"}}

  trigger_load_cpu:
    type: OS::Mistral::CronTrigger
    properties:
      count: {get_param: remaining_executions}
      pattern: {get_param: pattern_load}
      workflow: {get_attr: [wf_load_cpu, data]}

  trigger_release_cpu:
    type: OS::Mistral::CronTrigger
    properties:
      count: {get_param: remaining_executions}
      pattern: {get_param: pattern_release}
      workflow: {get_attr: [wf_release_cpu, data]}

outputs:
  servers_ips:
    value: {get_attr: [my_asg, outputs, ip]}

  next_load:
    value: {get_attr: [trigger_load_cpu, next_execution_time]}
    description: Time of the next execution of trigger_load_cpu

  next_release:
    value: {get_attr: [trigger_release_cpu, next_execution_time]}
    description: Time of the next execution of trigger_release_cpu