ceilometer_800.py 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. # -*- coding: utf-8 -*-
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software
  9. # distributed under the License is distributed on an "AS IS" BASIS,
  10. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  11. # implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """
  15. Installs and configures Ceilometer
  16. """
  17. import uuid
  18. from packstack.installer import basedefs
  19. from packstack.installer import utils
  20. from packstack.installer import validators
  21. from packstack.installer import processors
  22. from packstack.modules.documentation import update_params_usage
  23. from packstack.modules.ospluginutils import generate_ssl_cert
  24. # ------------- Ceilometer Packstack Plugin Initialization --------------
  25. PLUGIN_NAME = "OS-Ceilometer"
  26. PLUGIN_NAME_COLORED = utils.color_text(PLUGIN_NAME, 'blue')
  27. def initConfig(controller):
  28. ceilometer_params = {
  29. "CEILOMETER": [
  30. {"CONF_NAME": "CONFIG_CEILOMETER_SECRET",
  31. "CMD_OPTION": "ceilometer-secret",
  32. "PROMPT": "Enter the Ceilometer secret key",
  33. "OPTION_LIST": [],
  34. "VALIDATORS": [validators.validate_not_empty],
  35. "DEFAULT_VALUE": uuid.uuid4().hex[:16],
  36. "MASK_INPUT": True,
  37. "LOOSE_VALIDATION": False,
  38. "USE_DEFAULT": True,
  39. "NEED_CONFIRM": True,
  40. "CONDITION": False},
  41. {"CONF_NAME": "CONFIG_CEILOMETER_KS_PW",
  42. "CMD_OPTION": "ceilometer-ks-passwd",
  43. "PROMPT": "Enter the password for the Ceilometer Keystone access",
  44. "OPTION_LIST": [],
  45. "VALIDATORS": [validators.validate_not_empty],
  46. "DEFAULT_VALUE": "PW_PLACEHOLDER",
  47. "PROCESSORS": [processors.process_password],
  48. "MASK_INPUT": True,
  49. "LOOSE_VALIDATION": False,
  50. "USE_DEFAULT": False,
  51. "NEED_CONFIRM": True,
  52. "CONDITION": False},
  53. {"CMD_OPTION": "ceilometer-service-name",
  54. "PROMPT": "Enter the Ceilometer service name.",
  55. "OPTION_LIST": ['ceilometer', 'httpd'],
  56. "VALIDATORS": [validators.validate_options],
  57. "DEFAULT_VALUE": "httpd",
  58. "MASK_INPUT": False,
  59. "LOOSE_VALIDATION": False,
  60. "CONF_NAME": 'CONFIG_CEILOMETER_SERVICE_NAME',
  61. "USE_DEFAULT": False,
  62. "NEED_CONFIRM": False,
  63. "CONDITION": False},
  64. {"CONF_NAME": "CONFIG_CEILOMETER_COORDINATION_BACKEND",
  65. "CMD_OPTION": "ceilometer-coordination-backend",
  66. "PROMPT": "Enter the coordination driver",
  67. "OPTION_LIST": ['redis', 'none'],
  68. "VALIDATORS": [validators.validate_options],
  69. "DEFAULT_VALUE": 'redis',
  70. "MASK_INPUT": False,
  71. "USE_DEFAULT": True,
  72. "NEED_CONFIRM": False,
  73. "CONDITION": False},
  74. {"CONF_NAME": "CONFIG_CEILOMETER_METERING_BACKEND",
  75. "CMD_OPTION": "ceilometer-metering-backend",
  76. "PROMPT": "Enter the metering backend to use",
  77. "OPTION_LIST": ['database', 'gnocchi'],
  78. "VALIDATORS": [validators.validate_options],
  79. "DEFAULT_VALUE": 'database',
  80. "MASK_INPUT": False,
  81. "USE_DEFAULT": True,
  82. "NEED_CONFIRM": False,
  83. "CONDITION": False},
  84. {"CONF_NAME": "CONFIG_CEILOMETER_EVENTS_BACKEND",
  85. "CMD_OPTION": "ceilometer-events-backend",
  86. "PROMPT": "Enter the events backend to use",
  87. "OPTION_LIST": ['database', 'panko'],
  88. "VALIDATORS": [validators.validate_options],
  89. "DEFAULT_VALUE": 'database',
  90. "MASK_INPUT": False,
  91. "USE_DEFAULT": False,
  92. "NEED_CONFIRM": False,
  93. "CONDITION": False},
  94. ],
  95. "MONGODB": [
  96. {"CMD_OPTION": "mongodb-host",
  97. "PROMPT": "Enter the host for the MongoDB server",
  98. "OPTION_LIST": [],
  99. "VALIDATORS": [validators.validate_ssh],
  100. "DEFAULT_VALUE": utils.get_localhost_ip(),
  101. "MASK_INPUT": False,
  102. "LOOSE_VALIDATION": True,
  103. "CONF_NAME": "CONFIG_MONGODB_HOST",
  104. "USE_DEFAULT": False,
  105. "NEED_CONFIRM": False,
  106. "CONDITION": False},
  107. ],
  108. "REDIS": [
  109. {"CMD_OPTION": "redis-host",
  110. "PROMPT": "Enter the host for the Redis server",
  111. "OPTION_LIST": [],
  112. "VALIDATORS": [validators.validate_ssh],
  113. "DEFAULT_VALUE": utils.get_localhost_ip(),
  114. "MASK_INPUT": False,
  115. "LOOSE_VALIDATION": False,
  116. "CONF_NAME": "CONFIG_REDIS_HOST",
  117. "USE_DEFAULT": False,
  118. "NEED_CONFIRM": False,
  119. "CONDITION": False,
  120. "DEPRECATES": ["CONFIG_REDIS_MASTER_HOST"]},
  121. {"CMD_OPTION": "redis-port",
  122. "PROMPT": "Enter the port of the redis server(s)",
  123. "OPTION_LIST": [],
  124. "VALIDATORS": [validators.validate_port],
  125. "DEFAULT_VALUE": 6379,
  126. "MASK_INPUT": False,
  127. "LOOSE_VALIDATION": False,
  128. "CONF_NAME": "CONFIG_REDIS_PORT",
  129. "USE_DEFAULT": False,
  130. "NEED_CONFIRM": False,
  131. "CONDITION": False},
  132. ],
  133. }
  134. update_params_usage(basedefs.PACKSTACK_DOC, ceilometer_params)
  135. ceilometer_groups = [
  136. {"GROUP_NAME": "CEILOMETER",
  137. "DESCRIPTION": "Ceilometer Config parameters",
  138. "PRE_CONDITION": "CONFIG_CEILOMETER_INSTALL",
  139. "PRE_CONDITION_MATCH": "y",
  140. "POST_CONDITION": False,
  141. "POST_CONDITION_MATCH": True},
  142. {"GROUP_NAME": "MONGODB",
  143. "DESCRIPTION": "MONGODB Config parameters",
  144. "PRE_CONDITION": "CONFIG_CEILOMETER_INSTALL",
  145. "PRE_CONDITION_MATCH": "y",
  146. "POST_CONDITION": False,
  147. "POST_CONDITION_MATCH": True},
  148. {"GROUP_NAME": "REDIS",
  149. "DESCRIPTION": "Redis Config parameters",
  150. "PRE_CONDITION": "CONFIG_CEILOMETER_COORDINATION_BACKEND",
  151. "PRE_CONDITION_MATCH": "redis",
  152. "POST_CONDITION": False,
  153. "POST_CONDITION_MATCH": True},
  154. ]
  155. for group in ceilometer_groups:
  156. paramList = ceilometer_params[group["GROUP_NAME"]]
  157. controller.addGroup(group, paramList)
  158. def initSequences(controller):
  159. if controller.CONF['CONFIG_CEILOMETER_INSTALL'] != 'y':
  160. return
  161. steps = [{'title': 'Preparing MongoDB entries',
  162. 'functions': [create_mongodb_manifest]},
  163. {'title': 'Preparing Redis entries',
  164. 'functions': [create_redis_manifest]},
  165. {'title': 'Preparing Ceilometer entries',
  166. 'functions': [create_manifest]}]
  167. controller.addSequence("Installing OpenStack Ceilometer", [], [],
  168. steps)
  169. # -------------------------- step functions --------------------------
  170. def create_manifest(config, messages):
  171. if config['CONFIG_AMQP_ENABLE_SSL'] == 'y':
  172. ssl_cert_file = config['CONFIG_CEILOMETER_SSL_CERT'] = (
  173. '/etc/pki/tls/certs/ssl_amqp_ceilometer.crt'
  174. )
  175. ssl_key_file = config['CONFIG_CEILOMETER_SSL_KEY'] = (
  176. '/etc/pki/tls/private/ssl_amqp_ceilometer.key'
  177. )
  178. ssl_host = config['CONFIG_CONTROLLER_HOST']
  179. service = 'ceilometer'
  180. generate_ssl_cert(config, ssl_host, service, ssl_key_file,
  181. ssl_cert_file)
  182. fw_details = dict()
  183. key = "ceilometer_api"
  184. fw_details.setdefault(key, {})
  185. fw_details[key]['host'] = "ALL"
  186. fw_details[key]['service_name'] = "ceilometer-api"
  187. fw_details[key]['chain'] = "INPUT"
  188. fw_details[key]['ports'] = ['8777']
  189. fw_details[key]['proto'] = "tcp"
  190. config['FIREWALL_CEILOMETER_RULES'] = fw_details
  191. def create_mongodb_manifest(config, messages):
  192. host = config['CONFIG_MONGODB_HOST']
  193. if config['CONFIG_IP_VERSION'] == 'ipv6':
  194. config['CONFIG_MONGODB_HOST_URL'] = "[%s]" % host
  195. else:
  196. config['CONFIG_MONGODB_HOST_URL'] = host
  197. fw_details = dict()
  198. key = "mongodb_server"
  199. fw_details.setdefault(key, {})
  200. fw_details[key]['host'] = "%s" % config['CONFIG_CONTROLLER_HOST']
  201. fw_details[key]['service_name'] = "mongodb-server"
  202. fw_details[key]['chain'] = "INPUT"
  203. fw_details[key]['ports'] = ['27017']
  204. fw_details[key]['proto'] = "tcp"
  205. config['FIREWALL_MONGODB_RULES'] = fw_details
  206. def create_redis_manifest(config, messages):
  207. if config['CONFIG_CEILOMETER_COORDINATION_BACKEND'] == 'redis':
  208. redis_host = config['CONFIG_REDIS_HOST']
  209. if config['CONFIG_IP_VERSION'] == 'ipv6':
  210. config['CONFIG_REDIS_HOST_URL'] = "[%s]" % redis_host
  211. else:
  212. config['CONFIG_REDIS_HOST_URL'] = redis_host
  213. # master
  214. master_clients = set([config['CONFIG_CONTROLLER_HOST']])
  215. config['FIREWALL_REDIS_RULES'] = _create_redis_firewall_rules(
  216. master_clients, config['CONFIG_REDIS_PORT'])
  217. # ------------------------- helper functions -------------------------
  218. def _create_redis_firewall_rules(hosts, port):
  219. fw_details = dict()
  220. for host in hosts:
  221. key = "redis service from %s" % host
  222. fw_details.setdefault(key, {})
  223. fw_details[key]['host'] = "%s" % host
  224. fw_details[key]['service_name'] = "redis service"
  225. fw_details[key]['chain'] = "INPUT"
  226. fw_details[key]['ports'] = port
  227. fw_details[key]['proto'] = "tcp"
  228. return fw_details