Install utility to deploy OpenStack on multiple hosts.
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

490 satır
19KB

  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 Provisioning for demo usage and testing
  16. """
  17. import json
  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.installer.core import arch
  23. from packstack.modules.documentation import update_params_usage
  24. # ------------- Provision Packstack Plugin Initialization --------------
  25. PLUGIN_NAME = "OS-Provision"
  26. PLUGIN_NAME_COLORED = utils.color_text(PLUGIN_NAME, 'blue')
  27. DEMO_IMAGE_NAME = 'cirros'
  28. DEMO_IMAGE_URL = (
  29. 'https://download.cirros-cloud.net/0.3.5/cirros-0.3.5-%s-disk.img'
  30. % (arch.cirros_arch())
  31. )
  32. DEMO_IMAGE_SSH_USER = 'cirros'
  33. DEMO_IMAGE_FORMAT = 'qcow2'
  34. UEC_IMAGE_NAME = 'cirros-uec'
  35. UEC_IMAGE_KERNEL_URL = (
  36. 'https://download.cirros-cloud.net/0.3.5/cirros-0.3.5-%s-kernel'
  37. % (arch.cirros_arch())
  38. )
  39. UEC_IMAGE_RAMDISK_URL = (
  40. 'https://download.cirros-cloud.net/0.3.5/cirros-0.3.5-%s-initramfs'
  41. % (arch.cirros_arch())
  42. )
  43. UEC_IMAGE_DISK_URL = (
  44. 'https://download.cirros-cloud.net/0.3.5/cirros-0.3.5-%s-disk.img'
  45. % (arch.cirros_arch())
  46. )
  47. def initConfig(controller):
  48. def process_tempest(param, param_name, config=None):
  49. if param == "":
  50. # In case of multinode installs by default we deploy
  51. # Tempest on network node
  52. return config['CONFIG_NETWORK_HOSTS'].split(',')[0]
  53. return param
  54. conf_params = {
  55. "PROVISION_INIT": [
  56. {"CMD_OPTION": "provision-demo",
  57. "PROMPT": ("Would you like to provision for demo usage "
  58. "and testing"),
  59. "OPTION_LIST": ["y", "n"],
  60. "VALIDATORS": [validators.validate_options],
  61. "DEFAULT_VALUE": "y",
  62. "MASK_INPUT": False,
  63. "LOOSE_VALIDATION": True,
  64. "CONF_NAME": "CONFIG_PROVISION_DEMO",
  65. "USE_DEFAULT": False,
  66. "NEED_CONFIRM": False,
  67. "CONDITION": False},
  68. {"CMD_OPTION": "provision-tempest",
  69. "PROMPT": ("Would you like to configure Tempest (OpenStack test "
  70. "suite). Note that provisioning is only supported for "
  71. "all-in-one installations."),
  72. "OPTION_LIST": ["y", "n"],
  73. "VALIDATORS": [validators.validate_options],
  74. "DEFAULT_VALUE": "n",
  75. "MASK_INPUT": False,
  76. "LOOSE_VALIDATION": True,
  77. "CONF_NAME": "CONFIG_PROVISION_TEMPEST",
  78. "USE_DEFAULT": False,
  79. "NEED_CONFIRM": False,
  80. "CONDITION": False},
  81. ],
  82. "PROVISION_DEMO": [
  83. {"CMD_OPTION": "provision-demo-floatrange",
  84. "PROMPT": "Enter the network address for the floating IP subnet",
  85. "OPTION_LIST": False,
  86. "VALIDATORS": False,
  87. "DEFAULT_VALUE": "172.24.4.0/24",
  88. "MASK_INPUT": False,
  89. "LOOSE_VALIDATION": True,
  90. "CONF_NAME": "CONFIG_PROVISION_DEMO_FLOATRANGE",
  91. "USE_DEFAULT": False,
  92. "NEED_CONFIRM": False,
  93. "CONDITION": False},
  94. {"CMD_OPTION": "provision-demo-allocation-pools",
  95. "PROMPT": ("Enter the allocation pools from the floating IP "
  96. "subnet, as JSON list [\"start=ip1,end=ip2\", ...]"),
  97. "OPTION_LIST": [],
  98. "VALIDATORS": [],
  99. "DEFAULT_VALUE": "[]",
  100. "MASK_INPUT": False,
  101. "LOOSE_VALIDATION": False,
  102. "CONF_NAME": "CONFIG_PROVISION_DEMO_ALLOCATION_POOLS",
  103. "USE_DEFAULT": False,
  104. "NEED_CONFIRM": False,
  105. "CONDITION": False},
  106. {"CMD_OPTION": "provision-image-name",
  107. "PROMPT": "Enter the name to be assigned to the demo image",
  108. "OPTION_LIST": False,
  109. "VALIDATORS": [validators.validate_not_empty],
  110. "DEFAULT_VALUE": DEMO_IMAGE_NAME,
  111. "MASK_INPUT": False,
  112. "LOOSE_VALIDATION": True,
  113. "CONF_NAME": "CONFIG_PROVISION_IMAGE_NAME",
  114. "USE_DEFAULT": False,
  115. "NEED_CONFIRM": False,
  116. "CONDITION": False},
  117. {"CMD_OPTION": "provision-image-url",
  118. "PROMPT": ("Enter the location of an image to be loaded "
  119. "into Glance"),
  120. "OPTION_LIST": False,
  121. "VALIDATORS": [validators.validate_not_empty],
  122. "DEFAULT_VALUE": DEMO_IMAGE_URL,
  123. "MASK_INPUT": False,
  124. "LOOSE_VALIDATION": True,
  125. "CONF_NAME": "CONFIG_PROVISION_IMAGE_URL",
  126. "USE_DEFAULT": False,
  127. "NEED_CONFIRM": False,
  128. "CONDITION": False},
  129. {"CMD_OPTION": "provision-image-format",
  130. "PROMPT": ("Enter the format of the demo image"),
  131. "OPTION_LIST": False,
  132. "VALIDATORS": [validators.validate_not_empty],
  133. "DEFAULT_VALUE": DEMO_IMAGE_FORMAT,
  134. "MASK_INPUT": False,
  135. "LOOSE_VALIDATION": True,
  136. "CONF_NAME": "CONFIG_PROVISION_IMAGE_FORMAT",
  137. "USE_DEFAULT": False,
  138. "NEED_CONFIRM": False,
  139. "CONDITION": False},
  140. {"CMD_OPTION": "provision-image-properties",
  141. "PROMPT": ("Enter the comma-separated list of key=value pairs "
  142. "to set as the properties of the demo image"),
  143. "OPTION_LIST": False,
  144. "VALIDATORS": [],
  145. "DEFAULT_VALUE": "",
  146. "MASK_INPUT": False,
  147. "LOOSE_VALIDATION": True,
  148. "CONF_NAME": "CONFIG_PROVISION_IMAGE_PROPERTIES",
  149. "USE_DEFAULT": False,
  150. "NEED_CONFIRM": False,
  151. "CONDITION": False},
  152. {"CMD_OPTION": "provision-image-ssh-user",
  153. "PROMPT": ("Enter the name of a user to use when connecting "
  154. "to the demo image via ssh"),
  155. "OPTION_LIST": False,
  156. "VALIDATORS": [validators.validate_not_empty],
  157. "DEFAULT_VALUE": DEMO_IMAGE_SSH_USER,
  158. "MASK_INPUT": False,
  159. "LOOSE_VALIDATION": True,
  160. "CONF_NAME": "CONFIG_PROVISION_IMAGE_SSH_USER",
  161. "USE_DEFAULT": False,
  162. "NEED_CONFIRM": False,
  163. "CONDITION": False},
  164. {"CMD_OPTION": "provision-uec-image-name",
  165. "PROMPT": "Enter the name to be assigned to the uec image used for tempest",
  166. "OPTION_LIST": False,
  167. "VALIDATORS": [validators.validate_not_empty],
  168. "DEFAULT_VALUE": UEC_IMAGE_NAME,
  169. "MASK_INPUT": False,
  170. "LOOSE_VALIDATION": True,
  171. "CONF_NAME": "CONFIG_PROVISION_UEC_IMAGE_NAME",
  172. "USE_DEFAULT": False,
  173. "NEED_CONFIRM": False,
  174. "CONDITION": False},
  175. {"CMD_OPTION": "provision-uec-kernel-url",
  176. "PROMPT": ("Enter the location of a uec kernel to be loaded "
  177. "into Glance"),
  178. "OPTION_LIST": False,
  179. "VALIDATORS": [validators.validate_not_empty],
  180. "DEFAULT_VALUE": UEC_IMAGE_KERNEL_URL,
  181. "MASK_INPUT": False,
  182. "LOOSE_VALIDATION": True,
  183. "CONF_NAME": "CONFIG_PROVISION_UEC_IMAGE_KERNEL_URL",
  184. "USE_DEFAULT": False,
  185. "NEED_CONFIRM": False,
  186. "CONDITION": False},
  187. {"CMD_OPTION": "provision-uec-ramdisk-url",
  188. "PROMPT": ("Enter the location of a uec ramdisk to be loaded "
  189. "into Glance"),
  190. "OPTION_LIST": False,
  191. "VALIDATORS": [validators.validate_not_empty],
  192. "DEFAULT_VALUE": UEC_IMAGE_RAMDISK_URL,
  193. "MASK_INPUT": False,
  194. "LOOSE_VALIDATION": True,
  195. "CONF_NAME": "CONFIG_PROVISION_UEC_IMAGE_RAMDISK_URL",
  196. "USE_DEFAULT": False,
  197. "NEED_CONFIRM": False,
  198. "CONDITION": False},
  199. {"CMD_OPTION": "provision-uec-disk-url",
  200. "PROMPT": ("Enter the location of a uec disk image to be loaded "
  201. "into Glance"),
  202. "OPTION_LIST": False,
  203. "VALIDATORS": [validators.validate_not_empty],
  204. "DEFAULT_VALUE": UEC_IMAGE_DISK_URL,
  205. "MASK_INPUT": False,
  206. "LOOSE_VALIDATION": True,
  207. "CONF_NAME": "CONFIG_PROVISION_UEC_IMAGE_DISK_URL",
  208. "USE_DEFAULT": False,
  209. "NEED_CONFIRM": False,
  210. "CONDITION": False},
  211. ],
  212. "PROVISION_TEMPEST": [
  213. {"CMD_OPTION": "tempest-host",
  214. "PROMPT": "Enter the host where to deploy Tempest",
  215. "OPTION_LIST": [],
  216. "VALIDATORS": [validators.validate_ssh],
  217. "DEFAULT_VALUE": "",
  218. "PROCESSORS": [process_tempest],
  219. "MASK_INPUT": False,
  220. "LOOSE_VALIDATION": True,
  221. "CONF_NAME": "CONFIG_TEMPEST_HOST",
  222. "USE_DEFAULT": False,
  223. "NEED_CONFIRM": False,
  224. "CONDITION": False},
  225. {"CMD_OPTION": "provision-tempest-user",
  226. "PROMPT": ("Enter the name of the Tempest Provisioning user "
  227. "(if blank, Tempest will be configured in a "
  228. "standalone mode) "),
  229. "OPTION_LIST": False,
  230. "VALIDATORS": False,
  231. "DEFAULT_VALUE": "",
  232. "MASK_INPUT": False,
  233. "LOOSE_VALIDATION": True,
  234. "CONF_NAME": "CONFIG_PROVISION_TEMPEST_USER",
  235. "USE_DEFAULT": False,
  236. "NEED_CONFIRM": False,
  237. "CONDITION": False},
  238. {"CMD_OPTION": "provision-tempest-user-passwd",
  239. "PROMPT": "Enter the password for the Tempest Provisioning user",
  240. "OPTION_LIST": [],
  241. "VALIDATORS": [validators.validate_not_empty],
  242. "DEFAULT_VALUE": "PW_PLACEHOLDER",
  243. "PROCESSORS": [processors.process_password],
  244. "MASK_INPUT": True,
  245. "LOOSE_VALIDATION": False,
  246. "CONF_NAME": "CONFIG_PROVISION_TEMPEST_USER_PW",
  247. "USE_DEFAULT": False,
  248. "NEED_CONFIRM": True,
  249. "CONDITION": False},
  250. {"CMD_OPTION": "provision-tempest-floatrange",
  251. "PROMPT": "Enter the network address for the floating IP subnet",
  252. "OPTION_LIST": False,
  253. "VALIDATORS": False,
  254. "DEFAULT_VALUE": "172.24.4.0/24",
  255. "MASK_INPUT": False,
  256. "LOOSE_VALIDATION": True,
  257. "CONF_NAME": "CONFIG_PROVISION_TEMPEST_FLOATRANGE",
  258. "USE_DEFAULT": False,
  259. "NEED_CONFIRM": False,
  260. "CONDITION": False},
  261. {"CMD_OPTION": "provision-tempest-flavor-name",
  262. "PROMPT": "What is the name of the primary Tempest flavor?",
  263. "OPTION_LIST": False,
  264. "VALIDATORS": [validators.validate_not_empty],
  265. "DEFAULT_VALUE": "m1.nano",
  266. "MASK_INPUT": False,
  267. "LOOSE_VALIDATION": True,
  268. "CONF_NAME": "CONFIG_PROVISION_TEMPEST_FLAVOR_NAME",
  269. "USE_DEFAULT": False,
  270. "NEED_CONFIRM": False,
  271. "CONDITION": False},
  272. {"CMD_OPTION": "provision-tempest-flavor-disk",
  273. "PROMPT": ("How much of disk space has "
  274. "the primary Tempest flavor (Gb)?"),
  275. "OPTION_LIST": False,
  276. "VALIDATORS": [validators.validate_integer],
  277. "DEFAULT_VALUE": "0",
  278. "MASK_INPUT": False,
  279. "LOOSE_VALIDATION": True,
  280. "CONF_NAME": "CONFIG_PROVISION_TEMPEST_FLAVOR_DISK",
  281. "USE_DEFAULT": False,
  282. "NEED_CONFIRM": False,
  283. "CONDITION": False},
  284. {"CMD_OPTION": "provision-tempest-flavor-ram",
  285. "PROMPT": "How much is the primary Tempest flavor's ram (Mb)?",
  286. "OPTION_LIST": False,
  287. "VALIDATORS": [validators.validate_integer],
  288. "DEFAULT_VALUE": "128",
  289. "MASK_INPUT": False,
  290. "LOOSE_VALIDATION": True,
  291. "CONF_NAME": "CONFIG_PROVISION_TEMPEST_FLAVOR_RAM",
  292. "USE_DEFAULT": False,
  293. "NEED_CONFIRM": False,
  294. "CONDITION": False},
  295. {"CMD_OPTION": "provision-tempest-flavor-vcpus",
  296. "PROMPT": "How many vcpus is in the primary Tempest flavor?",
  297. "OPTION_LIST": False,
  298. "VALIDATORS": [validators.validate_integer],
  299. "DEFAULT_VALUE": "1",
  300. "MASK_INPUT": False,
  301. "LOOSE_VALIDATION": True,
  302. "CONF_NAME": "CONFIG_PROVISION_TEMPEST_FLAVOR_VCPUS",
  303. "USE_DEFAULT": False,
  304. "NEED_CONFIRM": False,
  305. "CONDITION": False},
  306. {"CMD_OPTION": "provision-tempest-flavor-alt-name",
  307. "PROMPT": "What is the name of the alternative Tempest flavor?",
  308. "OPTION_LIST": False,
  309. "VALIDATORS": [validators.validate_not_empty],
  310. "DEFAULT_VALUE": "m1.micro",
  311. "MASK_INPUT": False,
  312. "LOOSE_VALIDATION": True,
  313. "CONF_NAME": "CONFIG_PROVISION_TEMPEST_FLAVOR_ALT_NAME",
  314. "USE_DEFAULT": False,
  315. "NEED_CONFIRM": False,
  316. "CONDITION": False},
  317. {"CMD_OPTION": "provision-tempest-flavor-alt-disk",
  318. "PROMPT": ("How much of disk space has "
  319. "the alternative Tempest flavor (Gb)?"),
  320. "OPTION_LIST": False,
  321. "VALIDATORS": [validators.validate_integer],
  322. "DEFAULT_VALUE": "0",
  323. "MASK_INPUT": False,
  324. "LOOSE_VALIDATION": True,
  325. "CONF_NAME": "CONFIG_PROVISION_TEMPEST_FLAVOR_ALT_DISK",
  326. "USE_DEFAULT": False,
  327. "NEED_CONFIRM": False,
  328. "CONDITION": False},
  329. {"CMD_OPTION": "provision-tempest-flavor-alt-ram",
  330. "PROMPT": "How much is the alternative Tempest flavor's ram?",
  331. "OPTION_LIST": False,
  332. "VALIDATORS": [validators.validate_integer],
  333. "DEFAULT_VALUE": "128",
  334. "MASK_INPUT": False,
  335. "LOOSE_VALIDATION": True,
  336. "CONF_NAME": "CONFIG_PROVISION_TEMPEST_FLAVOR_ALT_RAM",
  337. "USE_DEFAULT": False,
  338. "NEED_CONFIRM": False,
  339. "CONDITION": False},
  340. {"CMD_OPTION": "provision-tempest-flavor-alt-vcpus",
  341. "PROMPT": "How many vcpus has the alternative Tempest flavor?",
  342. "OPTION_LIST": False,
  343. "VALIDATORS": [validators.validate_integer],
  344. "DEFAULT_VALUE": "1",
  345. "MASK_INPUT": False,
  346. "LOOSE_VALIDATION": True,
  347. "CONF_NAME": "CONFIG_PROVISION_TEMPEST_FLAVOR_ALT_VCPUS",
  348. "USE_DEFAULT": False,
  349. "NEED_CONFIRM": False,
  350. "CONDITION": False},
  351. {"CMD_OPTION": "run-tempest",
  352. "PROMPT": ("Do you wish to run tempest?"),
  353. "OPTION_LIST": ["y", "n"],
  354. "VALIDATORS": [validators.validate_options],
  355. "DEFAULT_VALUE": "n",
  356. "MASK_INPUT": False,
  357. "LOOSE_VALIDATION": True,
  358. "CONF_NAME": "CONFIG_RUN_TEMPEST",
  359. "USE_DEFAULT": False,
  360. "NEED_CONFIRM": False,
  361. "CONDITION": False},
  362. {"CMD_OPTION": "run-tempest-tests",
  363. "PROMPT": ("What tempest tests should run ?"
  364. " (If blank, Tempest will run smoke tests)"),
  365. "OPTION_LIST": [],
  366. "VALIDATORS": False,
  367. "DEFAULT_VALUE": "smoke",
  368. "MASK_INPUT": False,
  369. "LOOSE_VALIDATION": True,
  370. "CONF_NAME": "CONFIG_RUN_TEMPEST_TESTS",
  371. "USE_DEFAULT": False,
  372. "NEED_CONFIRM": False,
  373. "CONDITION": False}
  374. ],
  375. "PROVISION_OVS_BRIDGE": [
  376. {"CMD_OPTION": "provision-ovs-bridge",
  377. "PROMPT": "Would you like to configure the external ovs bridge",
  378. "OPTION_LIST": ["y", "n"],
  379. "VALIDATORS": [validators.validate_options],
  380. "DEFAULT_VALUE": "y",
  381. "MASK_INPUT": False,
  382. "LOOSE_VALIDATION": True,
  383. "CONF_NAME": "CONFIG_PROVISION_OVS_BRIDGE",
  384. "USE_DEFAULT": False,
  385. "NEED_CONFIRM": False,
  386. "CONDITION": False,
  387. "DEPRECATES": ['CONFIG_PROVISION_ALL_IN_ONE_OVS_BRIDGE']},
  388. ],
  389. }
  390. update_params_usage(basedefs.PACKSTACK_DOC, conf_params)
  391. def check_provisioning_demo(config):
  392. return (config.get('CONFIG_PROVISION_DEMO', 'n') == 'y')
  393. def check_provisioning_tempest(config):
  394. return (config.get('CONFIG_PROVISION_TEMPEST', 'n') == 'y')
  395. def allow_all_in_one_ovs_bridge(config):
  396. return (config['CONFIG_NEUTRON_INSTALL'] == 'y')
  397. conf_groups = [
  398. {"GROUP_NAME": "PROVISION_INIT",
  399. "DESCRIPTION": "Provisioning demo config",
  400. "PRE_CONDITION": lambda x: 'yes',
  401. "PRE_CONDITION_MATCH": "yes",
  402. "POST_CONDITION": False,
  403. "POST_CONDITION_MATCH": True},
  404. {"GROUP_NAME": "PROVISION_DEMO",
  405. "DESCRIPTION": "Provisioning demo config",
  406. "PRE_CONDITION": check_provisioning_demo,
  407. "PRE_CONDITION_MATCH": True,
  408. "POST_CONDITION": False,
  409. "POST_CONDITION_MATCH": True},
  410. {"GROUP_NAME": "PROVISION_TEMPEST",
  411. "DESCRIPTION": "Provisioning tempest config",
  412. "PRE_CONDITION": check_provisioning_tempest,
  413. "PRE_CONDITION_MATCH": True,
  414. "POST_CONDITION": False,
  415. "POST_CONDITION_MATCH": True},
  416. {"GROUP_NAME": "PROVISION_OVS_BRIDGE",
  417. "DESCRIPTION": "Provisioning all-in-one ovs bridge config",
  418. "PRE_CONDITION": allow_all_in_one_ovs_bridge,
  419. "PRE_CONDITION_MATCH": True,
  420. "POST_CONDITION": False,
  421. "POST_CONDITION_MATCH": True},
  422. ]
  423. for group in conf_groups:
  424. paramList = conf_params[group["GROUP_NAME"]]
  425. controller.addGroup(group, paramList)
  426. # Due to group checking some parameters might not be initialized, but
  427. # provision.pp needs them all. So we will initialize them with default
  428. # values
  429. params = [
  430. controller.getParamByName('CONFIG_PROVISION_OVS_BRIDGE')
  431. ]
  432. for param in params:
  433. value = controller.CONF.get(param.CONF_NAME, param.DEFAULT_VALUE)
  434. controller.CONF[param.CONF_NAME] = value
  435. def initSequences(controller):
  436. config = controller.CONF
  437. # params modification
  438. key = 'CONFIG_PROVISION_DEMO_ALLOCATION_POOLS'
  439. value = config.get(key, "[]")
  440. config[key] = json.loads(value)
  441. if type(config[key]) is not list:
  442. raise KeyError("Key %s is not a list: %s" % (key, config[key]))