glance_200.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 Glance
  16. """
  17. from packstack.installer import basedefs
  18. from packstack.installer import validators
  19. from packstack.installer import processors
  20. from packstack.installer import utils
  21. from packstack.modules.documentation import update_params_usage
  22. from packstack.modules.ospluginutils import generate_ssl_cert
  23. # ------------- Glance Packstack Plugin Initialization --------------
  24. PLUGIN_NAME = "OS-Glance"
  25. PLUGIN_NAME_COLORED = utils.color_text(PLUGIN_NAME, 'blue')
  26. def initConfig(controller):
  27. params = [
  28. {"CMD_OPTION": "glance-db-passwd",
  29. "PROMPT": "Enter the password for the Glance DB access",
  30. "OPTION_LIST": [],
  31. "VALIDATORS": [validators.validate_not_empty],
  32. "PROCESSORS": [processors.process_password],
  33. "DEFAULT_VALUE": "PW_PLACEHOLDER",
  34. "MASK_INPUT": True,
  35. "LOOSE_VALIDATION": False,
  36. "CONF_NAME": "CONFIG_GLANCE_DB_PW",
  37. "USE_DEFAULT": False,
  38. "NEED_CONFIRM": True,
  39. "CONDITION": False},
  40. {"CMD_OPTION": "glance-ks-passwd",
  41. "PROMPT": "Enter the password for the Glance Keystone access",
  42. "OPTION_LIST": [],
  43. "VALIDATORS": [validators.validate_not_empty],
  44. "PROCESSORS": [processors.process_password],
  45. "DEFAULT_VALUE": "PW_PLACEHOLDER",
  46. "MASK_INPUT": True,
  47. "LOOSE_VALIDATION": False,
  48. "CONF_NAME": "CONFIG_GLANCE_KS_PW",
  49. "USE_DEFAULT": False,
  50. "NEED_CONFIRM": True,
  51. "CONDITION": False},
  52. {"CMD_OPTION": "glance-backend",
  53. "PROMPT": "Glance storage backend",
  54. "OPTION_LIST": ["file", "swift"],
  55. "VALIDATORS": [validators.validate_options],
  56. "PROCESSORS": [process_backend],
  57. "DEFAULT_VALUE": "file",
  58. "MASK_INPUT": False,
  59. "LOOSE_VALIDATION": False,
  60. "CONF_NAME": "CONFIG_GLANCE_BACKEND",
  61. "USE_DEFAULT": False,
  62. "NEED_CONFIRM": False,
  63. "CONDITION": False},
  64. ]
  65. update_params_usage(basedefs.PACKSTACK_DOC, params, sectioned=False)
  66. group = {"GROUP_NAME": "GLANCE",
  67. "DESCRIPTION": "Glance Config parameters",
  68. "PRE_CONDITION": "CONFIG_GLANCE_INSTALL",
  69. "PRE_CONDITION_MATCH": "y",
  70. "POST_CONDITION": False,
  71. "POST_CONDITION_MATCH": True}
  72. controller.addGroup(group, params)
  73. def initSequences(controller):
  74. conf = controller.CONF
  75. if conf['CONFIG_GLANCE_INSTALL'] != 'y':
  76. if conf['CONFIG_NOVA_INSTALL'] == 'y':
  77. raise RuntimeError('Glance is required to install Nova properly. '
  78. 'Please set CONFIG_GLANCE_INSTALL=y')
  79. return
  80. glancesteps = [
  81. {'title': 'Preparing Glance entries',
  82. 'functions': [create_manifest]}
  83. ]
  84. controller.addSequence("Installing OpenStack Glance", [], [], glancesteps)
  85. # ------------------------- helper functions -------------------------
  86. def process_backend(value, param_name, config):
  87. if value == 'swift' and config['CONFIG_SWIFT_INSTALL'] != 'y':
  88. return 'file'
  89. return value
  90. # -------------------------- step functions --------------------------
  91. def create_manifest(config, messages):
  92. if config['CONFIG_AMQP_ENABLE_SSL'] == 'y':
  93. ssl_host = config['CONFIG_STORAGE_HOST']
  94. ssl_cert_file = config['CONFIG_GLANCE_SSL_CERT'] = (
  95. '/etc/pki/tls/certs/ssl_amqp_glance.crt'
  96. )
  97. ssl_key_file = config['CONFIG_GLANCE_SSL_KEY'] = (
  98. '/etc/pki/tls/private/ssl_amqp_glance.key'
  99. )
  100. service = 'glance'
  101. generate_ssl_cert(config, ssl_host, service, ssl_key_file,
  102. ssl_cert_file)
  103. fw_details = dict()
  104. key = "glance_api"
  105. fw_details.setdefault(key, {})
  106. fw_details[key]['host'] = "ALL"
  107. fw_details[key]['service_name'] = "glance"
  108. fw_details[key]['chain'] = "INPUT"
  109. fw_details[key]['ports'] = ['9292']
  110. fw_details[key]['proto'] = "tcp"
  111. config['FIREWALL_GLANCE_RULES'] = fw_details