mariadb_003.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 MariaDB
  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.common import filtered_hosts
  22. from packstack.modules.documentation import update_params_usage
  23. # ------------- MariaDB Packstack Plugin Initialization --------------
  24. PLUGIN_NAME = "MariaDB"
  25. PLUGIN_NAME_COLORED = utils.color_text(PLUGIN_NAME, 'blue')
  26. def initConfig(controller):
  27. params = [
  28. {"CMD_OPTION": "mariadb-host",
  29. "PROMPT": "Enter the IP address of the MariaDB server",
  30. "OPTION_LIST": [],
  31. "VALIDATORS": [validators.validate_ssh],
  32. "DEFAULT_VALUE": utils.get_localhost_ip(),
  33. "MASK_INPUT": False,
  34. "LOOSE_VALIDATION": True,
  35. "CONF_NAME": "CONFIG_MARIADB_HOST",
  36. "USE_DEFAULT": False,
  37. "NEED_CONFIRM": False,
  38. "CONDITION": False,
  39. "DEPRECATES": ['CONFIG_MYSQL_HOST']},
  40. {"CMD_OPTION": "mariadb-user",
  41. "USAGE": "Username for the MariaDB admin user",
  42. "PROMPT": "Enter the username for the MariaDB admin user",
  43. "OPTION_LIST": [],
  44. "VALIDATORS": [validators.validate_not_empty],
  45. "DEFAULT_VALUE": "root",
  46. "MASK_INPUT": False,
  47. "LOOSE_VALIDATION": False,
  48. "CONF_NAME": "CONFIG_MARIADB_USER",
  49. "USE_DEFAULT": True,
  50. "NEED_CONFIRM": False,
  51. "CONDITION": False,
  52. "DEPRECATES": ['CONFIG_MYSQL_USER']},
  53. {"CMD_OPTION": "mariadb-pw",
  54. "USAGE": "Password for the MariaDB admin user",
  55. "PROMPT": "Enter the password for the MariaDB admin user",
  56. "OPTION_LIST": [],
  57. "VALIDATORS": [validators.validate_not_empty],
  58. "PROCESSORS": [processors.process_password],
  59. "DEFAULT_VALUE": "PW_PLACEHOLDER",
  60. "MASK_INPUT": True,
  61. "LOOSE_VALIDATION": True,
  62. "CONF_NAME": "CONFIG_MARIADB_PW",
  63. "USE_DEFAULT": False,
  64. "NEED_CONFIRM": True,
  65. "CONDITION": False,
  66. "DEPRECATES": ['CONFIG_MYSQL_PW']},
  67. ]
  68. update_params_usage(basedefs.PACKSTACK_DOC, params, sectioned=False)
  69. group = {"GROUP_NAME": "MARIADB",
  70. "DESCRIPTION": "MariaDB Config parameters",
  71. "PRE_CONDITION": lambda x: 'yes',
  72. "PRE_CONDITION_MATCH": "yes",
  73. "POST_CONDITION": False,
  74. "POST_CONDITION_MATCH": True}
  75. controller.addGroup(group, params)
  76. def initSequences(controller):
  77. mariadbsteps = [
  78. {'title': 'Preparing MariaDB entries',
  79. 'functions': [create_manifest]}
  80. ]
  81. controller.addSequence("Installing MariaDB", [], [], mariadbsteps)
  82. # -------------------------- step functions --------------------------
  83. def create_manifest(config, messages):
  84. if config['CONFIG_MARIADB_INSTALL'] == 'y':
  85. host = config['CONFIG_MARIADB_HOST']
  86. else:
  87. host = config['CONFIG_CONTROLLER_HOST']
  88. if config['CONFIG_IP_VERSION'] == 'ipv6':
  89. config['CONFIG_MARIADB_HOST_URL'] = "[%s]" % host
  90. else:
  91. config['CONFIG_MARIADB_HOST_URL'] = host
  92. fw_details = dict()
  93. for host in filtered_hosts(config, exclude=False, dbhost=True):
  94. key = "mariadb_%s" % host
  95. fw_details.setdefault(key, {})
  96. fw_details[key]['host'] = "%s" % host
  97. fw_details[key]['service_name'] = "mariadb"
  98. fw_details[key]['chain'] = "INPUT"
  99. fw_details[key]['ports'] = ['3306']
  100. fw_details[key]['proto'] = "tcp"
  101. config['FIREWALL_MARIADB_RULES'] = fw_details