dashboard_500.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 OpenStack Horizon
  16. """
  17. import os
  18. import uuid
  19. from packstack.installer import basedefs
  20. from packstack.installer import exceptions
  21. from packstack.installer import utils
  22. from packstack.installer import validators
  23. from packstack.modules.documentation import update_params_usage
  24. from packstack.modules.ospluginutils import generate_ssl_cert
  25. from packstack.modules.ospluginutils import deliver_ssl_file
  26. # ------------- Horizon Packstack Plugin Initialization --------------
  27. PLUGIN_NAME = "OS-Horizon"
  28. PLUGIN_NAME_COLORED = utils.color_text(PLUGIN_NAME, 'blue')
  29. def initConfig(controller):
  30. params = [
  31. {"CMD_OPTION": "os-horizon-ssl",
  32. "PROMPT": "Would you like to set up Horizon communication over https",
  33. "OPTION_LIST": ["y", "n"],
  34. "VALIDATORS": [validators.validate_options],
  35. "DEFAULT_VALUE": "n",
  36. "MASK_INPUT": False,
  37. "LOOSE_VALIDATION": True,
  38. "CONF_NAME": "CONFIG_HORIZON_SSL",
  39. "USE_DEFAULT": False,
  40. "NEED_CONFIRM": False,
  41. "CONDITION": False},
  42. {"CMD_OPTION": "os-horizon-secretkey",
  43. "PROMPT": "Horizon Secret Encryption Key",
  44. "OPTION_LIST": [],
  45. "VALIDATORS": [validators.validate_not_empty],
  46. "DEFAULT_VALUE": uuid.uuid4().hex,
  47. "MASK_INPUT": True,
  48. "LOOSE_VALIDATION": False,
  49. "CONF_NAME": "CONFIG_HORIZON_SECRET_KEY",
  50. "USE_DEFAULT": True,
  51. "NEED_CONFIRM": False,
  52. "CONDITION": False},
  53. ]
  54. update_params_usage(basedefs.PACKSTACK_DOC, params, sectioned=False)
  55. group = {"GROUP_NAME": "OSHORIZON",
  56. "DESCRIPTION": "OpenStack Horizon Config parameters",
  57. "PRE_CONDITION": "CONFIG_HORIZON_INSTALL",
  58. "PRE_CONDITION_MATCH": "y",
  59. "POST_CONDITION": False,
  60. "POST_CONDITION_MATCH": True}
  61. controller.addGroup(group, params)
  62. params = [
  63. {"CMD_OPTION": "os-ssl-cert",
  64. "PROMPT": ("Enter the path to a PEM encoded certificate to be used "
  65. "on the https server, leave blank if one should be "
  66. "generated, this certificate should not require "
  67. "a passphrase"),
  68. "OPTION_LIST": [],
  69. "VALIDATORS": [],
  70. "DEFAULT_VALUE": '',
  71. "MASK_INPUT": False,
  72. "LOOSE_VALIDATION": True,
  73. "CONF_NAME": "CONFIG_HORIZON_SSL_CERT",
  74. "USE_DEFAULT": False,
  75. "NEED_CONFIRM": False,
  76. "CONDITION": False,
  77. "DEPRECATES": ['CONFIG_SSL_CERT']},
  78. {"CMD_OPTION": "os-ssl-key",
  79. "PROMPT": ("Enter the SSL keyfile corresponding to the certificate "
  80. "if one was entered"),
  81. "OPTION_LIST": [],
  82. "VALIDATORS": [],
  83. "DEFAULT_VALUE": "",
  84. "MASK_INPUT": False,
  85. "LOOSE_VALIDATION": True,
  86. "CONF_NAME": "CONFIG_HORIZON_SSL_KEY",
  87. "USE_DEFAULT": False,
  88. "NEED_CONFIRM": False,
  89. "CONDITION": False,
  90. "DEPRECATES": ['CONFIG_SSL_KEY']},
  91. {"CMD_OPTION": "os-ssl-cachain",
  92. "PROMPT": ("Enter the CA chain file corresponding to the certificate "
  93. "if one was entered"),
  94. "OPTION_LIST": [],
  95. "VALIDATORS": [],
  96. "DEFAULT_VALUE": "",
  97. "MASK_INPUT": False,
  98. "LOOSE_VALIDATION": True,
  99. "CONF_NAME": "CONFIG_HORIZON_SSL_CACERT",
  100. "USE_DEFAULT": False,
  101. "NEED_CONFIRM": False,
  102. "CONDITION": False,
  103. "DEPRECATES": ['CONFIG_SSL_CACHAIN']},
  104. ]
  105. update_params_usage(basedefs.PACKSTACK_DOC, params, sectioned=False)
  106. group = {"GROUP_NAME": "OSSSL",
  107. "DESCRIPTION": "SSL Config parameters",
  108. "PRE_CONDITION": "CONFIG_HORIZON_SSL",
  109. "PRE_CONDITION_MATCH": "y",
  110. "POST_CONDITION": False,
  111. "POST_CONDITION_MATCH": True}
  112. controller.addGroup(group, params)
  113. def initSequences(controller):
  114. if controller.CONF['CONFIG_HORIZON_INSTALL'] != 'y':
  115. return
  116. steps = [
  117. {'title': 'Preparing Horizon entries',
  118. 'functions': [create_manifest]}
  119. ]
  120. controller.addSequence("Installing OpenStack Horizon", [], [], steps)
  121. # -------------------------- step functions --------------------------
  122. def create_manifest(config, messages):
  123. horizon_host = config['CONFIG_CONTROLLER_HOST']
  124. proto = "http"
  125. config["CONFIG_HORIZON_PORT"] = 80
  126. sslmanifestdata = ''
  127. if config["CONFIG_HORIZON_SSL"] == 'y':
  128. config["CONFIG_HORIZON_PORT"] = 443
  129. proto = "https"
  130. # Are we using the users cert/key files
  131. if config["CONFIG_HORIZON_SSL_CERT"]:
  132. ssl_cert_file = config["CONFIG_HORIZON_SSL_CERT"]
  133. ssl_key_file = config["CONFIG_HORIZON_SSL_KEY"]
  134. ssl_chain_file = config["CONFIG_HORIZON_SSL_CACERT"]
  135. if not os.path.exists(ssl_cert_file):
  136. raise exceptions.ParamValidationError(
  137. "The file %s doesn't exist" % ssl_cert_file)
  138. if not os.path.exists(ssl_key_file):
  139. raise exceptions.ParamValidationError(
  140. "The file %s doesn't exist" % ssl_key_file)
  141. if not os.path.exists(ssl_chain_file):
  142. raise exceptions.ParamValidationError(
  143. "The file %s doesn't exist" % ssl_chain_file)
  144. final_cert = open(ssl_cert_file, 'rt').read()
  145. final_key = open(ssl_key_file, 'rt').read()
  146. final_cacert = open(ssl_chain_file, 'rt').read()
  147. host = config['CONFIG_CONTROLLER_HOST']
  148. deliver_ssl_file(final_cacert, ssl_chain_file, host)
  149. deliver_ssl_file(final_cert, ssl_cert_file, host)
  150. deliver_ssl_file(final_key, ssl_key_file, host)
  151. else:
  152. ssl_cert_file = config["CONFIG_HORIZON_SSL_CERT"] = (
  153. '/etc/pki/tls/certs/ssl_dashboard.crt'
  154. )
  155. ssl_key_file = config["CONFIG_HORIZON_SSL_KEY"] = (
  156. '/etc/pki/tls/private/ssl_dashboard.key'
  157. )
  158. cacert = config['CONFIG_SSL_CACERT']
  159. config["CONFIG_HORIZON_SSL_CACERT"] = cacert
  160. ssl_host = config['CONFIG_CONTROLLER_HOST']
  161. service = 'dashboard'
  162. generate_ssl_cert(config, ssl_host, service, ssl_key_file,
  163. ssl_cert_file)
  164. messages.append(
  165. "%sNOTE%s : A certificate was generated to be used for ssl, "
  166. "You should change the ssl certificate configured in "
  167. "/etc/httpd/conf.d/ssl.conf on %s to use a CA signed cert."
  168. % (utils.COLORS['red'], utils.COLORS['nocolor'], horizon_host))
  169. config["CONFIG_HORIZON_NEUTRON_LB"] = False
  170. config["CONFIG_HORIZON_NEUTRON_FW"] = False
  171. config["CONFIG_HORIZON_NEUTRON_VPN"] = False
  172. if config['CONFIG_NEUTRON_INSTALL'] == 'y':
  173. if config["CONFIG_LBAAS_INSTALL"] == 'y':
  174. config["CONFIG_HORIZON_NEUTRON_LB"] = True
  175. if config["CONFIG_NEUTRON_FWAAS"] == 'y':
  176. config["CONFIG_HORIZON_NEUTRON_FW"] = True
  177. if config["CONFIG_NEUTRON_VPNAAS"] == 'y':
  178. config["CONFIG_HORIZON_NEUTRON_VPN"] = True
  179. msg = ("To access the OpenStack Dashboard browse to %s://%s/dashboard .\n"
  180. "Please, find your login credentials stored in the keystonerc_admin"
  181. " in your home directory."
  182. % (proto, config['CONFIG_CONTROLLER_HOST']))
  183. messages.append(msg)