1 heat_template_version: 2013-05-23
2 description: AutoScaling Wordpress
6 description: Image used for servers
9 description: SSH key to connect to the servers
12 description: flavor used by the web servers
15 description: flavor used by the db server
18 description: Network used by the server
21 description: subnet on which the load balancer will be located
24 description: Name of the wordpress DB
28 description: Name of the wordpress user
32 description: UUID of a Neutron external network
35 type: OS::Heat::RandomString
36 database_root_password:
37 type: OS::Heat::RandomString
39 type: OS::Nova::Server
41 flavor: {get_param: database_flavor}
42 image: {get_param: image}
43 key_name: {get_param: key}
44 networks: [{network: {get_param: network} }]
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";
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]}
67 type: OS::Heat::AutoScalingGroup
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"}}
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
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
96 systemctl restart httpd.service
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
105 adjustment_type: change_in_capacity
106 auto_scaling_group_id: {get_resource: asg}
108 scaling_adjustment: 1
109 web_server_scaledown_policy:
110 type: OS::Heat::ScalingPolicy
112 adjustment_type: change_in_capacity
113 auto_scaling_group_id: {get_resource: asg}
115 scaling_adjustment: -1
117 type: OS::Ceilometer::Alarm
119 description: Scale-up if the average CPU > 50% for 1 minute
123 evaluation_periods: 1
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
130 type: OS::Ceilometer::Alarm
132 description: Scale-down if the average CPU < 15% for 10 minutes
136 evaluation_periods: 1
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
143 type: OS::Neutron::HealthMonitor
150 type: OS::Neutron::Pool
153 monitors: [{get_resource: monitor}]
154 subnet_id: {get_param: subnet_id}
155 lb_method: ROUND_ROBIN
159 type: OS::Neutron::LoadBalancer
162 pool_id: {get_resource: pool}
164 # assign a floating ip address to the load balancer
167 type: OS::Neutron::FloatingIP
169 floating_network_id: {get_param: external_network_id}
170 port_id: {get_attr: [pool, vip, port_id]}
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]}
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]}
186 value: {get_attr: [pool, vip, address]}
187 description: The IP address of the load balancing pool
191 template: http://host/wordpress/
193 host: { get_attr: [lb_floating, floating_ip_address] }
195 This URL is the "external" URL that can be used to access the
201 ceilometer statistics -m cpu_util
202 -q metadata.user_metadata.stack=stackval -p 600 -a avg
204 stackval: { get_param: "OS::stack_id" }
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.