Initial OpenECOMP MSO commit
[so.git] / asdc-controller / src / test / resources / resource-examples / autoscaling.yaml
1 heat_template_version: 2013-05-23 
2 description: AutoScaling Wordpress 
3 parameters: 
4  image: 
5    type: string 
6    description: Image used for servers 
7  key: 
8    type: string 
9    description: SSH key to connect to the servers 
10   flavor: 
11     type: string 
12     description: flavor used by the web servers 
13   database_flavor: 
14     type: string 
15     description: flavor used by the db server 
16   network: 
17     type: string 
18     description: Network used by the server 
19   subnet_id: 
20     type: string 
21     description: subnet on which the load balancer will be located 
22   database_name: 
23     type: string 
24     description: Name of the wordpress DB 
25     default: wordpress 
26   database_user: 
27     type: string 
28     description: Name of the wordpress user 
29     default: wordpress 
30   external_network_id: 
31     type: string 
32     description: UUID of a Neutron external network 
33 resources: 
34   database_password: 
35     type: OS::Heat::RandomString 
36   database_root_password: 
37     type: OS::Heat::RandomString 
38   db: 
39     type: OS::Nova::Server 
40     properties: 
41       flavor: {get_param: database_flavor} 
42       image: {get_param: image} 
43       key_name: {get_param: key} 
44       networks: [{network: {get_param: network} }] 
45       user_data_format: RAW 
46       user_data: 
47         str_replace: 
48           template: | 
49             #!/bin/bash -v 
50             yum -y install mariadb mariadb-server 
51             systemctl enable mariadb.service 
52             systemctl start mariadb.service 
53             mysqladmin -u root password $db_rootpassword 
54             cat << EOF | mysql -u root --password=$db_rootpassword 
55             CREATE DATABASE $db_name; 
56             GRANT ALL PRIVILEGES ON $db_name.* TO "$db_user"@"%" 
57             IDENTIFIED BY "$db_password"; 
58             FLUSH PRIVILEGES; 
59             EXIT 
60             EOF 
61           params: 
62             $db_rootpassword: {get_attr: [database_root_password, value]} 
63             $db_name: {get_param: database_name} 
64             $db_user: {get_param: database_user} 
65             $db_password: {get_attr: [database_password, value]} 
66   asg: 
67     type: OS::Heat::AutoScalingGroup 
68     properties: 
69       min_size: 1 
70       max_size: 3 
71       resource: 
72         type: lb_server.yaml 
73         properties: 
74           flavor: {get_param: flavor} 
75           image: {get_param: image} 
76           key_name: {get_param: key} 
77           network: {get_param: network} 
78           pool_id: {get_resource: pool} 
79           metadata: {"metering.stack": {get_param: "OS::stack_id"}} 
80           user_data: 
81             str_replace: 
82               template: | 
83                 #!/bin/bash -v 
84                 yum -y install httpd wordpress 
85                 systemctl enable httpd.service 
86                 systemctl start httpd.service 
87                 setsebool -P httpd_can_network_connect_db=1 
88  
89                 sed -i "/Deny from All/d" /etc/httpd/conf.d/wordpress.conf 
90                 sed -i "s/Require local/Require all granted/" /etc/httpd/conf.d/wordpress.conf 
91                 sed -i s/database_name_here/$db_name/ /etc/wordpress/wp-config.php 
92                 sed -i s/username_here/$db_user/ /etc/wordpress/wp-config.php 
93                 sed -i s/password_here/$db_password/ /etc/wordpress/wp-config.php 
94                 sed -i s/localhost/$db_host/ /etc/wordpress/wp-config.php 
95  
96                 systemctl restart httpd.service 
97               params: 
98                 $db_name: {get_param: database_name} 
99                 $db_user: {get_param: database_user} 
100                  $db_password: {get_attr: [database_password, value]} 
101                  $db_host: {get_attr: [db, first_address]} 
102    web_server_scaleup_policy: 
103      type: OS::Heat::ScalingPolicy 
104      properties: 
105        adjustment_type: change_in_capacity 
106        auto_scaling_group_id: {get_resource: asg} 
107        cooldown: 60 
108        scaling_adjustment: 1 
109    web_server_scaledown_policy: 
110      type: OS::Heat::ScalingPolicy 
111      properties: 
112        adjustment_type: change_in_capacity 
113        auto_scaling_group_id: {get_resource: asg} 
114        cooldown: 60 
115        scaling_adjustment: -1 
116    cpu_alarm_high: 
117      type: OS::Ceilometer::Alarm 
118      properties: 
119        description: Scale-up if the average CPU > 50% for 1 minute 
120        meter_name: cpu_util 
121        statistic: avg 
122        period: 60 
123        evaluation_periods: 1 
124        threshold: 50 
125        alarm_actions: 
126          - {get_attr: [web_server_scaleup_policy, alarm_url]} 
127        matching_metadata: {'metadata.user_metadata.stack': {get_param: "OS::stack_id"}} 
128        comparison_operator: gt 
129    cpu_alarm_low: 
130      type: OS::Ceilometer::Alarm 
131      properties: 
132        description: Scale-down if the average CPU < 15% for 10 minutes 
133        meter_name: cpu_util 
134        statistic: avg 
135        period: 600 
136        evaluation_periods: 1 
137        threshold: 15 
138        alarm_actions: 
139          - {get_attr: [web_server_scaledown_policy, alarm_url]} 
140        matching_metadata: {'metadata.user_metadata.stack': {get_param: "OS::stack_id"}} 
141        comparison_operator: lt 
142    monitor: 
143      type: OS::Neutron::HealthMonitor 
144      properties: 
145        type: TCP 
146        delay: 5 
147        max_retries: 5 
148        timeout: 5 
149    pool: 
150      type: OS::Neutron::Pool 
151      properties: 
152        protocol: HTTP 
153        monitors: [{get_resource: monitor}] 
154        subnet_id: {get_param: subnet_id} 
155        lb_method: ROUND_ROBIN 
156        vip: 
157          protocol_port: 80 
158    lb: 
159      type: OS::Neutron::LoadBalancer 
160      properties: 
161        protocol_port: 80 
162        pool_id: {get_resource: pool} 
163   
164    # assign a floating ip address to the load balancer 
165    # pool. 
166    lb_floating: 
167      type: OS::Neutron::FloatingIP 
168      properties: 
169        floating_network_id: {get_param: external_network_id} 
170        port_id: {get_attr: [pool, vip, port_id]} 
171   
172  outputs: 
173    scale_up_url: 
174      description: > 
175        This URL is the webhook to scale up the autoscaling group.  You 
176        can invoke the scale-up operation by doing an HTTP POST to this 
177        URL; no body nor extra headers are needed. 
178      value: {get_attr: [web_server_scaleup_policy, alarm_url]} 
179    scale_dn_url: 
180      description: > 
181        This URL is the webhook to scale down the autoscaling group. 
182        You can invoke the scale-down operation by doing an HTTP POST to 
183        this URL; no body nor extra headers are needed. 
184      value: {get_attr: [web_server_scaledown_policy, alarm_url]} 
185    pool_ip_address: 
186      value: {get_attr: [pool, vip, address]} 
187      description: The IP address of the load balancing pool 
188    website_url: 
189      value: 
190        str_replace: 
191          template: http://host/wordpress/ 
192          params: 
193            host: { get_attr: [lb_floating, floating_ip_address] } 
194      description: > 
195        This URL is the "external" URL that can be used to access the 
196        Wordpress site. 
197    ceilometer_query: 
198      value: 
199        str_replace: 
200          template: > 
201            ceilometer statistics -m cpu_util 
202            -q metadata.user_metadata.stack=stackval -p 600 -a avg 
203          params: 
204            stackval: { get_param: "OS::stack_id" } 
205      description: > 
206        This is a Ceilometer query for statistics on the cpu_util meter 
207        Samples about OS::Nova::Server instances in this stack.  The -q 
208        parameter selects Samples according to the subject's metadata. 
209        When a VM's metadata includes an item of the form metering.X=Y, 
210        the corresponding Ceilometer resource has a metadata item of the 
211        form user_metadata.X=Y and samples about resources so tagged can 
212        be queried with a Ceilometer query term of the form 
213        metadata.user_metadata.X=Y.  In this case the nested stacks give 
214        their VMs metadata that is passed as a nested stack parameter, 
215        and this stack passes a metadata of the form metering.stack=Y, 
216        where Y is this stack's ID.