PageRenderTime 40ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/autoscaling_example.yaml

https://gitlab.com/cgaikwad/heat-templates
YAML | 216 lines | 208 code | 4 blank | 4 comment | 0 complexity | ed3babe1efc2aa919fada4aa4101dbc7 MD5 | raw file
  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. sed -i "/Deny from All/d" /etc/httpd/conf.d/wordpress.conf
  89. sed -i "s/Require local/Require all granted/" /etc/httpd/conf.d/wordpress.conf
  90. sed -i s/database_name_here/$db_name/ /etc/wordpress/wp-config.php
  91. sed -i s/username_here/$db_user/ /etc/wordpress/wp-config.php
  92. sed -i s/password_here/$db_password/ /etc/wordpress/wp-config.php
  93. sed -i s/localhost/$db_host/ /etc/wordpress/wp-config.php
  94. systemctl restart httpd.service
  95. params:
  96. $db_name: {get_param: database_name}
  97. $db_user: {get_param: database_user}
  98. $db_password: {get_attr: [database_password, value]}
  99. $db_host: {get_attr: [db, first_address]}
  100. web_server_scaleup_policy:
  101. type: OS::Heat::ScalingPolicy
  102. properties:
  103. adjustment_type: change_in_capacity
  104. auto_scaling_group_id: {get_resource: asg}
  105. cooldown: 60
  106. scaling_adjustment: 1
  107. web_server_scaledown_policy:
  108. type: OS::Heat::ScalingPolicy
  109. properties:
  110. adjustment_type: change_in_capacity
  111. auto_scaling_group_id: {get_resource: asg}
  112. cooldown: 60
  113. scaling_adjustment: -1
  114. cpu_alarm_high:
  115. type: OS::Ceilometer::Alarm
  116. properties:
  117. description: Scale-up if the average CPU > 50% for 1 minute
  118. meter_name: cpu_util
  119. statistic: avg
  120. period: 60
  121. evaluation_periods: 1
  122. threshold: 50
  123. alarm_actions:
  124. - {get_attr: [web_server_scaleup_policy, alarm_url]}
  125. matching_metadata: {'metadata.user_metadata.stack': {get_param: "OS::stack_id"}}
  126. comparison_operator: gt
  127. cpu_alarm_low:
  128. type: OS::Ceilometer::Alarm
  129. properties:
  130. description: Scale-down if the average CPU < 15% for 10 minutes
  131. meter_name: cpu_util
  132. statistic: avg
  133. period: 600
  134. evaluation_periods: 1
  135. threshold: 15
  136. alarm_actions:
  137. - {get_attr: [web_server_scaledown_policy, alarm_url]}
  138. matching_metadata: {'metadata.user_metadata.stack': {get_param: "OS::stack_id"}}
  139. comparison_operator: lt
  140. monitor:
  141. type: OS::Neutron::HealthMonitor
  142. properties:
  143. type: TCP
  144. delay: 5
  145. max_retries: 5
  146. timeout: 5
  147. pool:
  148. type: OS::Neutron::Pool
  149. properties:
  150. protocol: HTTP
  151. monitors: [{get_resource: monitor}]
  152. subnet_id: {get_param: subnet_id}
  153. lb_method: ROUND_ROBIN
  154. vip:
  155. protocol_port: 80
  156. lb:
  157. type: OS::Neutron::LoadBalancer
  158. properties:
  159. protocol_port: 80
  160. pool_id: {get_resource: pool}
  161. # assign a floating ip address to the load balancer
  162. # pool.
  163. lb_floating:
  164. type: OS::Neutron::FloatingIP
  165. properties:
  166. floating_network_id: {get_param: external_network_id}
  167. port_id: {get_attr: [pool, vip, port_id]}
  168. outputs:
  169. scale_up_url:
  170. description: >
  171. This URL is the webhook to scale up the autoscaling group. You
  172. can invoke the scale-up operation by doing an HTTP POST to this
  173. URL; no body nor extra headers are needed.
  174. value: {get_attr: [web_server_scaleup_policy, alarm_url]}
  175. scale_dn_url:
  176. description: >
  177. This URL is the webhook to scale down the autoscaling group.
  178. You can invoke the scale-down operation by doing an HTTP POST to
  179. this URL; no body nor extra headers are needed.
  180. value: {get_attr: [web_server_scaledown_policy, alarm_url]}
  181. pool_ip_address:
  182. value: {get_attr: [pool, vip, address]}
  183. description: The IP address of the load balancing pool
  184. website_url:
  185. value:
  186. str_replace:
  187. template: http://host/wordpress/
  188. params:
  189. host: { get_attr: [lb_floating, floating_ip_address] }
  190. description: >
  191. This URL is the "external" URL that can be used to access the
  192. Wordpress site.
  193. ceilometer_query:
  194. value:
  195. str_replace:
  196. template: >
  197. ceilometer statistics -m cpu_util
  198. -q metadata.user_metadata.stack=stackval -p 600 -a avg
  199. params:
  200. stackval: { get_param: "OS::stack_id" }
  201. description: >
  202. This is a Ceilometer query for statistics on the cpu_util meter
  203. Samples about OS::Nova::Server instances in this stack. The -q
  204. parameter selects Samples according to the subject's metadata.
  205. When a VM's metadata includes an item of the form metering.X=Y,
  206. the corresponding Ceilometer resource has a metadata item of the
  207. form user_metadata.X=Y and samples about resources so tagged can
  208. be queried with a Ceilometer query term of the form
  209. metadata.user_metadata.X=Y. In this case the nested stacks give
  210. their VMs metadata that is passed as a nested stack parameter,
  211. and this stack passes a metadata of the form metering.stack=Y,
  212. where Y is this stack's ID.