neutron_350.py 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  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 Neutron
  16. """
  17. import re
  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 import output_messages
  23. from packstack.installer.utils import split_hosts
  24. from packstack.modules import common
  25. from packstack.modules.documentation import update_params_usage
  26. from packstack.modules.ospluginutils import generate_ssl_cert
  27. # ------------- Neutron Packstack Plugin Initialization --------------
  28. PLUGIN_NAME = "OS-Neutron"
  29. PLUGIN_NAME_COLORED = utils.color_text(PLUGIN_NAME, 'blue')
  30. def initConfig(controller):
  31. conf_params = {
  32. "NEUTRON": [
  33. {"CMD_OPTION": "os-neutron-ks-password",
  34. "PROMPT": "Enter the password for Neutron Keystone access",
  35. "OPTION_LIST": [],
  36. "VALIDATORS": [validators.validate_not_empty],
  37. "DEFAULT_VALUE": "PW_PLACEHOLDER",
  38. "PROCESSORS": [processors.process_password],
  39. "MASK_INPUT": True,
  40. "LOOSE_VALIDATION": False,
  41. "CONF_NAME": "CONFIG_NEUTRON_KS_PW",
  42. "USE_DEFAULT": False,
  43. "NEED_CONFIRM": True,
  44. "CONDITION": False},
  45. {"CMD_OPTION": "os-neutron-db-password",
  46. "PROMPT": "Enter the password for Neutron DB access",
  47. "OPTION_LIST": [],
  48. "VALIDATORS": [validators.validate_not_empty],
  49. "DEFAULT_VALUE": "PW_PLACEHOLDER",
  50. "PROCESSORS": [processors.process_password],
  51. "MASK_INPUT": True,
  52. "LOOSE_VALIDATION": False,
  53. "CONF_NAME": "CONFIG_NEUTRON_DB_PW",
  54. "USE_DEFAULT": False,
  55. "NEED_CONFIRM": True,
  56. "CONDITION": False},
  57. {"CMD_OPTION": "os-neutron-l3-ext-bridge",
  58. "PROMPT": ("Enter the ovs bridge the Neutron L3 agent will use "
  59. "for external traffic, or 'provider' if using "
  60. "provider networks."),
  61. "OPTION_LIST": [],
  62. "VALIDATORS": [],
  63. "DEFAULT_VALUE": "br-ex",
  64. "MASK_INPUT": False,
  65. "LOOSE_VALIDATION": True,
  66. "CONF_NAME": "CONFIG_NEUTRON_L3_EXT_BRIDGE",
  67. "USE_DEFAULT": False,
  68. "NEED_CONFIRM": False,
  69. "CONDITION": False},
  70. {"CMD_OPTION": "os-neutron-metadata-pw",
  71. "PROMPT": "Enter Neutron metadata agent password",
  72. "OPTION_LIST": [],
  73. "VALIDATORS": [validators.validate_not_empty],
  74. "DEFAULT_VALUE": "PW_PLACEHOLDER",
  75. "PROCESSORS": [processors.process_password],
  76. "MASK_INPUT": True,
  77. "LOOSE_VALIDATION": False,
  78. "CONF_NAME": "CONFIG_NEUTRON_METADATA_PW",
  79. "USE_DEFAULT": False,
  80. "NEED_CONFIRM": True,
  81. "CONDITION": False},
  82. {"CMD_OPTION": "os-neutron-lbaas-install",
  83. "PROMPT": "Should Packstack install Neutron LBaaS",
  84. "OPTION_LIST": ["y", "n"],
  85. "VALIDATORS": [validators.validate_options],
  86. "DEFAULT_VALUE": "n",
  87. "MASK_INPUT": False,
  88. "LOOSE_VALIDATION": False,
  89. "CONF_NAME": "CONFIG_LBAAS_INSTALL",
  90. "USE_DEFAULT": False,
  91. "NEED_CONFIRM": False,
  92. "CONDITION": False},
  93. {"CMD_OPTION": "os-neutron-metering-agent-install",
  94. "PROMPT": ("Should Packstack install Neutron L3 Metering agent"),
  95. "OPTION_LIST": ["y", "n"],
  96. "VALIDATORS": [validators.validate_options],
  97. "DEFAULT_VALUE": "y",
  98. "MASK_INPUT": False,
  99. "LOOSE_VALIDATION": False,
  100. "CONF_NAME": "CONFIG_NEUTRON_METERING_AGENT_INSTALL",
  101. "USE_DEFAULT": False,
  102. "NEED_CONFIRM": False,
  103. "CONDITION": False},
  104. {"CMD_OPTION": "neutron-fwaas",
  105. "PROMPT": "Would you like to configure neutron FWaaS?",
  106. "OPTION_LIST": ["y", "n"],
  107. "VALIDATORS": [validators.validate_options],
  108. "DEFAULT_VALUE": "n",
  109. "MASK_INPUT": False,
  110. "LOOSE_VALIDATION": True,
  111. "CONF_NAME": "CONFIG_NEUTRON_FWAAS",
  112. "USE_DEFAULT": False,
  113. "NEED_CONFIRM": False,
  114. "CONDITION": False},
  115. {"CMD_OPTION": "os-neutron-vpnaas-install",
  116. "PROMPT": "Would you like to configure neutron VPNaaS?",
  117. "OPTION_LIST": ["y", "n"],
  118. "VALIDATORS": [validators.validate_options],
  119. "DEFAULT_VALUE": "n",
  120. "MASK_INPUT": False,
  121. "LOOSE_VALIDATION": True,
  122. "CONF_NAME": "CONFIG_NEUTRON_VPNAAS",
  123. "USE_DEFAULT": False,
  124. "NEED_CONFIRM": False,
  125. "CONDITION": False},
  126. ],
  127. "NEUTRON_LB_AGENT": [
  128. {"CMD_OPTION": "os-neutron-lb-interface-mappings",
  129. "PROMPT": ("Enter a comma separated list of interface mappings "
  130. "for the Neutron linuxbridge plugin"),
  131. "OPTION_LIST": [],
  132. "VALIDATORS": [],
  133. "DEFAULT_VALUE": "",
  134. "MASK_INPUT": False,
  135. "LOOSE_VALIDATION": True,
  136. "CONF_NAME": "CONFIG_NEUTRON_LB_INTERFACE_MAPPINGS",
  137. "USE_DEFAULT": False,
  138. "NEED_CONFIRM": False,
  139. "CONDITION": False},
  140. ],
  141. "NEUTRON_OVS_AGENT": [
  142. {"CMD_OPTION": "os-neutron-ovs-bridge-mappings",
  143. "PROMPT": ("Enter a comma separated list of bridge mappings for "
  144. "the Neutron openvswitch plugin"),
  145. "OPTION_LIST": [],
  146. "VALIDATORS": [],
  147. "DEFAULT_VALUE": "extnet:br-ex",
  148. "MASK_INPUT": False,
  149. "LOOSE_VALIDATION": True,
  150. "CONF_NAME": "CONFIG_NEUTRON_OVS_BRIDGE_MAPPINGS",
  151. "USE_DEFAULT": False,
  152. "NEED_CONFIRM": False,
  153. "CONDITION": False},
  154. {"CMD_OPTION": "os-neutron-ovs-bridge-interfaces",
  155. "PROMPT": ("Enter a comma separated list of OVS bridge:interface "
  156. "pairs for the Neutron openvswitch plugin"),
  157. "OPTION_LIST": [],
  158. "VALIDATORS": [],
  159. "DEFAULT_VALUE": "",
  160. "MASK_INPUT": False,
  161. "LOOSE_VALIDATION": True,
  162. "CONF_NAME": "CONFIG_NEUTRON_OVS_BRIDGE_IFACES",
  163. "USE_DEFAULT": False,
  164. "NEED_CONFIRM": False,
  165. "CONDITION": False},
  166. {"CMD_OPTION": "os-neutron-ovs-bridges-compute",
  167. "PROMPT": ("Enter a comma separated list of bridges for the "
  168. "Neutron OVS plugin in compute nodes. They must "
  169. "be included in os-neutron-ovs-bridge-mappings and "
  170. "os-neutron-ovs-bridge-interfaces."),
  171. "OPTION_LIST": [],
  172. "VALIDATORS": [],
  173. "DEFAULT_VALUE": "",
  174. "MASK_INPUT": False,
  175. "LOOSE_VALIDATION": True,
  176. "CONF_NAME": "CONFIG_NEUTRON_OVS_BRIDGES_COMPUTE",
  177. "USE_DEFAULT": False,
  178. "NEED_CONFIRM": False,
  179. "CONDITION": False},
  180. {"CMD_OPTION": "os-neutron-ovs-external-physnet",
  181. "PROMPT": ("Enter the name of the physical external network as"
  182. "defined in bridge mappings"),
  183. "OPTION_LIST": [],
  184. "VALIDATORS": [],
  185. "DEFAULT_VALUE": "extnet",
  186. "MASK_INPUT": False,
  187. "LOOSE_VALIDATION": True,
  188. "CONF_NAME": "CONFIG_NEUTRON_OVS_EXTERNAL_PHYSNET",
  189. "USE_DEFAULT": False,
  190. "NEED_CONFIRM": False,
  191. "CONDITION": False},
  192. ],
  193. "NEUTRON_OVS_AGENT_TUNNEL": [
  194. {"CMD_OPTION": "os-neutron-ovs-tunnel-if",
  195. "PROMPT": ("Enter interface with IP to override the default "
  196. "tunnel local_ip"),
  197. "OPTION_LIST": [],
  198. "VALIDATORS": [],
  199. "DEFAULT_VALUE": "",
  200. "MASK_INPUT": False,
  201. "LOOSE_VALIDATION": True,
  202. "CONF_NAME": "CONFIG_NEUTRON_OVS_TUNNEL_IF",
  203. "USE_DEFAULT": False,
  204. "NEED_CONFIRM": False,
  205. "CONDITION": False},
  206. {"CMD_OPTION": "os-neutron-ovs-tunnel-subnets",
  207. "PROMPT": ("Enter comma separated list of subnets used for "
  208. "tunneling to make them allowed by IP filtering."),
  209. "OPTION_LIST": [],
  210. "VALIDATORS": [],
  211. "DEFAULT_VALUE": "",
  212. "MASK_INPUT": False,
  213. "LOOSE_VALIDATION": True,
  214. "CONF_NAME": "CONFIG_NEUTRON_OVS_TUNNEL_SUBNETS",
  215. "USE_DEFAULT": False,
  216. "NEED_CONFIRM": False,
  217. "CONDITION": False},
  218. ],
  219. "NEUTRON_OVS_AGENT_VXLAN": [
  220. {"CMD_OPTION": "os-neutron-ovs-vxlan-udp-port",
  221. "CONF_NAME": "CONFIG_NEUTRON_OVS_VXLAN_UDP_PORT",
  222. "PROMPT": "Enter VXLAN UDP port number",
  223. "OPTION_LIST": [],
  224. "VALIDATORS": [validators.validate_port],
  225. "DEFAULT_VALUE": 4789,
  226. "MASK_INPUT": False,
  227. "LOOSE_VALIDATION": True,
  228. "USE_DEFAULT": False,
  229. "NEED_CONFIRM": False,
  230. "CONDITION": False},
  231. ],
  232. "NEUTRON_ML2_PLUGIN": [
  233. {"CMD_OPTION": "os-neutron-ml2-type-drivers",
  234. "CONF_NAME": "CONFIG_NEUTRON_ML2_TYPE_DRIVERS",
  235. "PROMPT": ("Enter a comma separated list of network type driver "
  236. "entrypoints"),
  237. "OPTION_LIST": ["local", "flat", "vlan", "gre", "vxlan"],
  238. "VALIDATORS": [validators.validate_multi_options],
  239. "DEFAULT_VALUE": "vxlan,flat",
  240. "MASK_INPUT": False,
  241. "LOOSE_VALIDATION": False,
  242. "USE_DEFAULT": False,
  243. "NEED_CONFIRM": False,
  244. "CONDITION": False},
  245. {"CMD_OPTION": "os-neutron-ml2-tenant-network-types",
  246. "CONF_NAME": "CONFIG_NEUTRON_ML2_TENANT_NETWORK_TYPES",
  247. "PROMPT": ("Enter a comma separated ordered list of "
  248. "network_types to allocate as tenant networks"),
  249. "OPTION_LIST": ["local", "vlan", "gre", "vxlan"],
  250. "VALIDATORS": [validators.validate_multi_options],
  251. "DEFAULT_VALUE": "vxlan",
  252. "MASK_INPUT": False,
  253. "LOOSE_VALIDATION": False,
  254. "USE_DEFAULT": False,
  255. "NEED_CONFIRM": False,
  256. "CONDITION": False},
  257. {"CMD_OPTION": "os-neutron-ml2-mechanism-drivers",
  258. "CONF_NAME": "CONFIG_NEUTRON_ML2_MECHANISM_DRIVERS",
  259. "PROMPT": ("Enter a comma separated ordered list of networking "
  260. "mechanism driver entrypoints"),
  261. "OPTION_LIST": ["logger", "test", "linuxbridge", "openvswitch",
  262. "hyperv", "ncs", "arista", "cisco_nexus",
  263. "mlnx", "l2population", "sriovnicswitch"],
  264. "VALIDATORS": [validators.validate_multi_options],
  265. "DEFAULT_VALUE": "openvswitch",
  266. "MASK_INPUT": False,
  267. "LOOSE_VALIDATION": False,
  268. "USE_DEFAULT": False,
  269. "NEED_CONFIRM": False,
  270. "CONDITION": False},
  271. {"CMD_OPTION": "os-neutron-ml2-flat-networks",
  272. "CONF_NAME": "CONFIG_NEUTRON_ML2_FLAT_NETWORKS",
  273. "PROMPT": ("Enter a comma separated list of physical_network "
  274. "names with which flat networks can be created"),
  275. "OPTION_LIST": [],
  276. "VALIDATORS": [],
  277. "DEFAULT_VALUE": "*",
  278. "MASK_INPUT": False,
  279. "LOOSE_VALIDATION": False,
  280. "USE_DEFAULT": False,
  281. "NEED_CONFIRM": False,
  282. "CONDITION": False},
  283. {"CMD_OPTION": "os-neutron-ml2-vlan-ranges",
  284. "CONF_NAME": "CONFIG_NEUTRON_ML2_VLAN_RANGES",
  285. "PROMPT": ("Enter a comma separated list of physical_network "
  286. "names usable for VLAN"),
  287. "OPTION_LIST": [],
  288. "VALIDATORS": [],
  289. "DEFAULT_VALUE": "",
  290. "MASK_INPUT": False,
  291. "LOOSE_VALIDATION": False,
  292. "USE_DEFAULT": False,
  293. "NEED_CONFIRM": False,
  294. "CONDITION": False},
  295. {"CMD_OPTION": "os-neutron-ml2-tunnel-id-ranges",
  296. "CONF_NAME": "CONFIG_NEUTRON_ML2_TUNNEL_ID_RANGES",
  297. "PROMPT": ("Enter a comma separated list of <tun_min>:<tun_max> "
  298. "tuples enumerating ranges of GRE tunnel IDs that "
  299. "are available for tenant network allocation"),
  300. "OPTION_LIST": [],
  301. "VALIDATORS": [],
  302. "DEFAULT_VALUE": "",
  303. "MASK_INPUT": False,
  304. "LOOSE_VALIDATION": False,
  305. "USE_DEFAULT": False,
  306. "NEED_CONFIRM": False,
  307. "CONDITION": False},
  308. {"CMD_OPTION": "os-neutron-ml2-vxlan-group",
  309. "CONF_NAME": "CONFIG_NEUTRON_ML2_VXLAN_GROUP",
  310. "PROMPT": "Enter a multicast group for VXLAN",
  311. "OPTION_LIST": [],
  312. "VALIDATORS": [],
  313. "DEFAULT_VALUE": "",
  314. "MASK_INPUT": False,
  315. "LOOSE_VALIDATION": False,
  316. "USE_DEFAULT": False,
  317. "NEED_CONFIRM": False,
  318. "CONDITION": False},
  319. {"CMD_OPTION": "os-neutron-ml2-vni-ranges",
  320. "CONF_NAME": "CONFIG_NEUTRON_ML2_VNI_RANGES",
  321. "PROMPT": ("Enter a comma separated list of <vni_min>:<vni_max> "
  322. "tuples enumerating ranges of VXLAN VNI IDs that are "
  323. "available for tenant network allocation"),
  324. "OPTION_LIST": [],
  325. "VALIDATORS": [],
  326. "DEFAULT_VALUE": "10:100",
  327. "MASK_INPUT": False,
  328. "LOOSE_VALIDATION": False,
  329. "USE_DEFAULT": False,
  330. "NEED_CONFIRM": False,
  331. "CONDITION": False},
  332. # We need to ask for this only in case of ML2 plugins
  333. {"CMD_OPTION": "os-neutron-l2-agent",
  334. "PROMPT": ("Enter the name of the L2 agent to be used "
  335. "with Neutron"),
  336. "OPTION_LIST": ["linuxbridge", "openvswitch"],
  337. "VALIDATORS": [validators.validate_options],
  338. "DEFAULT_VALUE": "openvswitch",
  339. "MASK_INPUT": False,
  340. "LOOSE_VALIDATION": False,
  341. "CONF_NAME": "CONFIG_NEUTRON_L2_AGENT",
  342. "USE_DEFAULT": False,
  343. "NEED_CONFIRM": False,
  344. "CONDITION": False},
  345. {"CMD_OPTION": "os-neutron-ml2-supported-pci-vendor-devs",
  346. "CONF_NAME": "CONFIG_NEUTRON_ML2_SUPPORTED_PCI_VENDOR_DEVS",
  347. "PROMPT": ("Enter a comma separated list of supported PCI "
  348. "vendor devices, defined by vendor_id:product_id "
  349. "according to the PCI ID Repository."),
  350. "OPTION_LIST": [],
  351. "VALIDATORS": [],
  352. "DEFAULT_VALUE": ['15b3:1004', '8086:10ca'],
  353. "MASK_INPUT": False,
  354. "LOOSE_VALIDATION": False,
  355. "USE_DEFAULT": False,
  356. "NEED_CONFIRM": False,
  357. "CONDITION": False},
  358. {"CMD_OPTION": "os-neutron-ml2-sriov-interface-mappings",
  359. "PROMPT": ("Enter a comma separated list of interface mappings "
  360. "for the Neutron ML2 sriov agent"),
  361. "OPTION_LIST": [],
  362. "VALIDATORS": [],
  363. "DEFAULT_VALUE": "",
  364. "MASK_INPUT": False,
  365. "LOOSE_VALIDATION": True,
  366. "CONF_NAME": "CONFIG_NEUTRON_ML2_SRIOV_INTERFACE_MAPPINGS",
  367. "USE_DEFAULT": False,
  368. "NEED_CONFIRM": False,
  369. "CONDITION": False},
  370. ],
  371. }
  372. update_params_usage(basedefs.PACKSTACK_DOC, conf_params)
  373. conf_groups = [
  374. {"GROUP_NAME": "NEUTRON",
  375. "DESCRIPTION": "Neutron config",
  376. "PRE_CONDITION": "CONFIG_NEUTRON_INSTALL",
  377. "PRE_CONDITION_MATCH": "y",
  378. "POST_CONDITION": False,
  379. "POST_CONDITION_MATCH": True},
  380. {"GROUP_NAME": "NEUTRON_ML2_PLUGIN",
  381. "DESCRIPTION": "Neutron ML2 plugin config",
  382. "PRE_CONDITION": neutron_install,
  383. "PRE_CONDITION_MATCH": True,
  384. "POST_CONDITION": False,
  385. "POST_CONDITION_MATCH": True},
  386. {"GROUP_NAME": "NEUTRON_LB_AGENT",
  387. "DESCRIPTION": "Neutron LB agent config",
  388. "PRE_CONDITION": use_ml2_with_linuxbridge,
  389. "PRE_CONDITION_MATCH": True,
  390. "POST_CONDITION": False,
  391. "POST_CONDITION_MATCH": True},
  392. {"GROUP_NAME": "NEUTRON_OVS_AGENT",
  393. "DESCRIPTION": "Neutron OVS agent config",
  394. "PRE_CONDITION": use_ml2_with_ovs,
  395. "PRE_CONDITION_MATCH": True,
  396. "POST_CONDITION": False,
  397. "POST_CONDITION_MATCH": True},
  398. {"GROUP_NAME": "NEUTRON_OVS_AGENT_TUNNEL",
  399. "DESCRIPTION": "Neutron OVS agent config for tunnels",
  400. "PRE_CONDITION": use_ml2_with_ovs,
  401. "PRE_CONDITION_MATCH": True,
  402. "POST_CONDITION": False,
  403. "POST_CONDITION_MATCH": True},
  404. {"GROUP_NAME": "NEUTRON_OVS_AGENT_VXLAN",
  405. "DESCRIPTION": "Neutron OVS agent config for VXLAN",
  406. "PRE_CONDITION": use_openvswitch_vxlan,
  407. "PRE_CONDITION_MATCH": True,
  408. "POST_CONDITION": False,
  409. "POST_CONDITION_MATCH": True},
  410. ]
  411. for group in conf_groups:
  412. params = conf_params[group["GROUP_NAME"]]
  413. controller.addGroup(group, params)
  414. def initSequences(controller):
  415. config = controller.CONF
  416. if config['CONFIG_NEUTRON_INSTALL'] != 'y':
  417. return
  418. if config['CONFIG_IRONIC_INSTALL'] == 'y':
  419. config['CONFIG_NEUTRON_ML2_TYPE_DRIVERS'] += ', flat'
  420. config['CONFIG_NEUTRON_ML2_TENANT_NETWORK_TYPES'] += ', flat'
  421. if 'openvswitch' not in config['CONFIG_NEUTRON_ML2_MECHANISM_DRIVERS']:
  422. config['CONFIG_NEUTRON_ML2_MECHANISM_DRIVERS'] += 'openvswitch'
  423. config['CONFIG_NEUTRON_ML2_FLAT_NETWORKS'] = 'physnet1'
  424. if use_ml2_with_sriovnicswitch(config):
  425. if ('openvswitch' not in config['CONFIG_NEUTRON_ML2_MECHANISM_DRIVERS']
  426. and 'linuxbridge' not in
  427. config['CONFIG_NEUTRON_ML2_MECHANISM_DRIVERS']):
  428. config['CONFIG_NEUTRON_ML2_MECHANISM_DRIVERS'] += ', openvswitch'
  429. plugin_db = 'neutron'
  430. plugin_path = 'neutron.plugins.ml2.plugin.Ml2Plugin'
  431. # values modification
  432. for key in ('CONFIG_NEUTRON_ML2_TYPE_DRIVERS',
  433. 'CONFIG_NEUTRON_ML2_TENANT_NETWORK_TYPES',
  434. 'CONFIG_NEUTRON_ML2_MECHANISM_DRIVERS',
  435. 'CONFIG_NEUTRON_ML2_FLAT_NETWORKS',
  436. 'CONFIG_NEUTRON_ML2_VLAN_RANGES',
  437. 'CONFIG_NEUTRON_ML2_TUNNEL_ID_RANGES',
  438. 'CONFIG_NEUTRON_ML2_VNI_RANGES'):
  439. if config[key] == '':
  440. config[key] = []
  441. else:
  442. config[key] = [i.strip() for i in config[key].split(',') if i]
  443. key = 'CONFIG_NEUTRON_ML2_VXLAN_GROUP'
  444. config[key] = "%s" % config[key] if config[key] else ''
  445. config['CONFIG_NEUTRON_L2_DBNAME'] = plugin_db
  446. config['CONFIG_NEUTRON_CORE_PLUGIN'] = plugin_path
  447. global api_hosts, network_hosts, compute_hosts, q_hosts
  448. api_hosts = split_hosts(config['CONFIG_CONTROLLER_HOST'])
  449. network_hosts = split_hosts(config['CONFIG_NETWORK_HOSTS'])
  450. compute_hosts = set()
  451. if config['CONFIG_NOVA_INSTALL'] == 'y':
  452. compute_hosts = split_hosts(config['CONFIG_COMPUTE_HOSTS'])
  453. q_hosts = api_hosts | network_hosts | compute_hosts
  454. neutron_steps = [
  455. {'title': 'Preparing Neutron LBaaS Agent entries',
  456. 'functions': [create_lbaas_manifests]},
  457. {'title': 'Preparing Neutron API entries',
  458. 'functions': [create_manifests]},
  459. {'title': 'Preparing Neutron L3 entries',
  460. 'functions': [create_l3_manifests]},
  461. {'title': 'Preparing Neutron L2 Agent entries',
  462. 'functions': [create_l2_agent_manifests]},
  463. {'title': 'Preparing Neutron DHCP Agent entries',
  464. 'functions': [create_dhcp_manifests]},
  465. {'title': 'Preparing Neutron Metering Agent entries',
  466. 'functions': [create_metering_agent_manifests]},
  467. {'title': 'Checking if NetworkManager is enabled and running',
  468. 'functions': [check_nm_status]},
  469. ]
  470. controller.addSequence("Installing OpenStack Neutron", [], [],
  471. neutron_steps)
  472. # ------------------------- helper functions -------------------------
  473. def neutron_install(config):
  474. return config['CONFIG_NEUTRON_INSTALL'] == 'y'
  475. def use_ml2_with_linuxbridge(config):
  476. ml2_used = (neutron_install(config) and
  477. config["CONFIG_NEUTRON_L2_AGENT"] == 'linuxbridge')
  478. return ml2_used
  479. def use_ml2_with_ovs(config):
  480. return (neutron_install(config) and
  481. config["CONFIG_NEUTRON_L2_AGENT"] == 'openvswitch')
  482. def use_openvswitch_vxlan(config):
  483. ml2_vxlan = (
  484. use_ml2_with_ovs(config) and
  485. 'vxlan' in config['CONFIG_NEUTRON_ML2_TENANT_NETWORK_TYPES']
  486. )
  487. return ml2_vxlan
  488. def use_openvswitch_gre(config):
  489. ml2_vxlan = (
  490. use_ml2_with_ovs(config) and
  491. 'gre' in config['CONFIG_NEUTRON_ML2_TENANT_NETWORK_TYPES']
  492. )
  493. return ml2_vxlan
  494. def use_ml2_with_sriovnicswitch(config):
  495. ml2_sriovnic = (
  496. use_ml2_with_ovs(config) and
  497. 'sriovnicswitch' in config['CONFIG_NEUTRON_ML2_MECHANISM_DRIVERS']
  498. )
  499. return ml2_sriovnic
  500. def get_if_driver(config):
  501. agent = config['CONFIG_NEUTRON_L2_AGENT']
  502. if agent == "openvswitch":
  503. return 'neutron.agent.linux.interface.OVSInterfaceDriver'
  504. elif agent == 'linuxbridge':
  505. return 'neutron.agent.linux.interface.BridgeInterfaceDriver'
  506. def find_mapping(haystack, needle):
  507. return needle in [x.split(':')[1].strip() for x in get_values(haystack)]
  508. def get_values(val):
  509. return [x.strip() for x in val.split(',')] if val else []
  510. def tunnel_fw_details(config, host, src, fw_details):
  511. key = "neutron_tunnel_%s_%s" % (host, src)
  512. fw_details.setdefault(key, {})
  513. fw_details[key]['host'] = "%s" % src
  514. fw_details[key]['service_name'] = "neutron tunnel port"
  515. fw_details[key]['chain'] = "INPUT"
  516. if use_openvswitch_vxlan(config):
  517. fw_details[key]['proto'] = 'udp'
  518. tun_port = ("%s" % config['CONFIG_NEUTRON_OVS_VXLAN_UDP_PORT'])
  519. else:
  520. fw_details[key]['proto'] = 'gre'
  521. tun_port = None
  522. fw_details[key]['ports'] = tun_port
  523. # -------------------------- step functions --------------------------
  524. def create_manifests(config, messages):
  525. global q_hosts
  526. service_plugins = []
  527. service_providers = []
  528. if config['CONFIG_LBAAS_INSTALL'] == 'y':
  529. lbaas_plugin = ('neutron_lbaas.services.loadbalancer.plugin.'
  530. 'LoadBalancerPluginv2')
  531. service_plugins.append(lbaas_plugin)
  532. lbaas_sp = ('LOADBALANCERV2:Haproxy:neutron_lbaas.drivers.haproxy.'
  533. 'plugin_driver.HaproxyOnHostPluginDriver:default')
  534. service_providers.append(lbaas_sp)
  535. # ML2 uses the L3 Router service plugin to implement l3 agent
  536. service_plugins.append('router')
  537. if config['CONFIG_NEUTRON_METERING_AGENT_INSTALL'] == 'y':
  538. service_plugins.append('metering')
  539. if config['CONFIG_NEUTRON_FWAAS'] == 'y':
  540. service_plugins.append('firewall')
  541. fwaas_sp = ('FIREWALL:Iptables:neutron.agent.linux.iptables_firewall.'
  542. 'OVSHybridIptablesFirewallDriver:default')
  543. service_providers.append(fwaas_sp)
  544. if config['CONFIG_NEUTRON_VPNAAS'] == 'y':
  545. service_plugins.append('vpnaas')
  546. vpnaas_sp = ('VPN:libreswan:neutron_vpnaas.services.vpn.'
  547. 'service_drivers.ipsec.IPsecVPNDriver:default')
  548. service_providers.append(vpnaas_sp)
  549. config['SERVICE_PLUGINS'] = (service_plugins if service_plugins
  550. else 'undef')
  551. config['SERVICE_PROVIDERS'] = (service_providers if service_providers
  552. else [])
  553. config['FIREWALL_DRIVER'] = ("neutron.agent.linux.iptables_firewall."
  554. "OVSHybridIptablesFirewallDriver")
  555. plugin_manifest = 'neutron_ml2_plugin'
  556. if config['CONFIG_AMQP_ENABLE_SSL'] == 'y':
  557. ssl_cert_file = config['CONFIG_NEUTRON_SSL_CERT'] = (
  558. '/etc/pki/tls/certs/ssl_amqp_neutron.crt'
  559. )
  560. ssl_key_file = config['CONFIG_NEUTRON_SSL_KEY'] = (
  561. '/etc/pki/tls/private/ssl_amqp_neutron.key'
  562. )
  563. service = 'neutron'
  564. for host in q_hosts:
  565. if config['CONFIG_AMQP_ENABLE_SSL'] == 'y':
  566. generate_ssl_cert(config, host, service, ssl_key_file,
  567. ssl_cert_file)
  568. if host in api_hosts:
  569. # Firewall
  570. fw_details = dict()
  571. key = "neutron_server_%s" % host
  572. fw_details.setdefault(key, {})
  573. fw_details[key]['host'] = "ALL"
  574. fw_details[key]['service_name'] = "neutron server"
  575. fw_details[key]['chain'] = "INPUT"
  576. fw_details[key]['ports'] = ['9696']
  577. fw_details[key]['proto'] = "tcp"
  578. config['FIREWALL_NEUTRON_SERVER_RULES'] = fw_details
  579. # We also need to open VXLAN/GRE port for agent
  580. if use_openvswitch_vxlan(config) or use_openvswitch_gre(config):
  581. if config['CONFIG_IP_VERSION'] == 'ipv6':
  582. msg = output_messages.WARN_IPV6_OVS
  583. messages.append(utils.color_text(msg % host, 'red'))
  584. fw_details = dict()
  585. if (config['CONFIG_NEUTRON_OVS_TUNNEL_SUBNETS']):
  586. tunnel_subnets = map(
  587. str.strip,
  588. config['CONFIG_NEUTRON_OVS_TUNNEL_SUBNETS'].split(',')
  589. )
  590. cf_fw_nt_key = ("FIREWALL_NEUTRON_TUNNEL_RULES_%s" % host)
  591. for subnet in tunnel_subnets:
  592. tunnel_fw_details(config, host, subnet, fw_details)
  593. config[cf_fw_nt_key] = fw_details
  594. else:
  595. cf_fw_nt_key = ("FIREWALL_NEUTRON_TUNNEL_RULES_%s" % host)
  596. for n_host in network_hosts | compute_hosts:
  597. if config['CONFIG_NEUTRON_OVS_TUNNEL_IF']:
  598. if config['CONFIG_USE_SUBNETS'] == 'y':
  599. iface = common.cidr_to_ifname(
  600. config['CONFIG_NEUTRON_OVS_TUNNEL_IF'],
  601. n_host, config)
  602. else:
  603. iface = config['CONFIG_NEUTRON_OVS_TUNNEL_IF']
  604. ifip = ("ipaddress_%s" % iface)
  605. ifip = re.sub('[\.\-\:]', '_', ifip)
  606. try:
  607. src_host = config['HOST_DETAILS'][n_host][ifip]
  608. except KeyError:
  609. raise KeyError('Couldn\'t detect ipaddress of '
  610. 'interface %s on node %s' %
  611. (iface, n_host))
  612. else:
  613. src_host = n_host
  614. tunnel_fw_details(config, host, src_host, fw_details)
  615. config[cf_fw_nt_key] = fw_details
  616. def create_l3_manifests(config, messages):
  617. global network_hosts
  618. if config['CONFIG_NEUTRON_L3_EXT_BRIDGE'] == 'provider':
  619. config['CONFIG_NEUTRON_L3_EXT_BRIDGE'] = ''
  620. for host in network_hosts:
  621. config['CONFIG_NEUTRON_L3_HOST'] = host
  622. config['CONFIG_NEUTRON_L3_INTERFACE_DRIVER'] = get_if_driver(config)
  623. if config['CONFIG_NEUTRON_L2_AGENT'] == 'openvswitch':
  624. ext_bridge = config['CONFIG_NEUTRON_L3_EXT_BRIDGE']
  625. mapping = find_mapping(
  626. config['CONFIG_NEUTRON_OVS_BRIDGE_MAPPINGS'],
  627. ext_bridge) if ext_bridge else None
  628. if (ext_bridge and not mapping):
  629. config['CONFIG_NEUTRON_OVS_BRIDGE'] = ext_bridge
  630. config['CONFIG_NEUTRON_OVS_BRIDGE_CREATE'] = 'y'
  631. else:
  632. config['CONFIG_NEUTRON_OVS_BRIDGE_CREATE'] = 'n'
  633. else:
  634. config['CONFIG_NEUTRON_OVS_BRIDGE_CREATE'] = 'n'
  635. def create_dhcp_manifests(config, messages):
  636. global network_hosts
  637. for host in network_hosts:
  638. config["CONFIG_NEUTRON_DHCP_HOST"] = host
  639. config['CONFIG_NEUTRON_DHCP_INTERFACE_DRIVER'] = get_if_driver(config)
  640. # Firewall Rules for dhcp in
  641. fw_details = dict()
  642. key = "neutron_dhcp_in_%s" % host
  643. fw_details.setdefault(key, {})
  644. fw_details[key]['host'] = "ALL"
  645. fw_details[key]['service_name'] = "neutron dhcp in"
  646. fw_details[key]['chain'] = "INPUT"
  647. fw_details[key]['ports'] = ['67']
  648. fw_details[key]['proto'] = "udp"
  649. config['FIREWALL_NEUTRON_DHCPIN_RULES'] = fw_details
  650. # Firewall Rules for dhcp out
  651. fw_details = dict()
  652. key = "neutron_dhcp_out_%s" % host
  653. fw_details.setdefault(key, {})
  654. fw_details[key]['host'] = "ALL"
  655. fw_details[key]['service_name'] = "neutron dhcp out"
  656. fw_details[key]['chain'] = "OUTPUT"
  657. fw_details[key]['ports'] = ['68']
  658. fw_details[key]['proto'] = "udp"
  659. config['FIREWALL_NEUTRON_DHCPOUT_RULES'] = fw_details
  660. def create_lbaas_manifests(config, messages):
  661. global network_hosts
  662. if not config['CONFIG_LBAAS_INSTALL'] == 'y':
  663. return
  664. for host in network_hosts:
  665. config['CONFIG_NEUTRON_LBAAS_INTERFACE_DRIVER'] = get_if_driver(config)
  666. def create_metering_agent_manifests(config, messages):
  667. global network_hosts
  668. if not config['CONFIG_NEUTRON_METERING_AGENT_INSTALL'] == 'y':
  669. return
  670. for host in network_hosts:
  671. config['CONFIG_NEUTRON_METERING_IFCE_DRIVER'] = get_if_driver(config)
  672. def create_l2_agent_manifests(config, messages):
  673. global network_hosts, compute_hosts
  674. agent = config["CONFIG_NEUTRON_L2_AGENT"]
  675. # CONFIG_NEUTRON_ML2_MECHANISM_DRIVERS will be available only for ML2
  676. # plugin deployment, but we need CONFIG_NEUTRON_USE_L2POPULATION also
  677. # for other plugin template generation
  678. if ('l2population' in
  679. config.get('CONFIG_NEUTRON_ML2_MECHANISM_DRIVERS', [])):
  680. config['CONFIG_NEUTRON_USE_L2POPULATION'] = True
  681. else:
  682. config['CONFIG_NEUTRON_USE_L2POPULATION'] = False
  683. if agent == "openvswitch":
  684. ovs_type = 'CONFIG_NEUTRON_ML2_TYPE_DRIVERS'
  685. ovs_type = config.get(ovs_type, 'local')
  686. tunnel = use_openvswitch_vxlan(config) or use_openvswitch_gre(config)
  687. config["CONFIG_NEUTRON_OVS_TUNNELING"] = tunnel
  688. tunnel_types = set(ovs_type) & set(['gre', 'vxlan'])
  689. config["CONFIG_NEUTRON_OVS_TUNNEL_TYPES"] = list(tunnel_types)
  690. bm_arr = get_values(config["CONFIG_NEUTRON_OVS_BRIDGE_MAPPINGS"])
  691. iface_arr = get_values(config["CONFIG_NEUTRON_OVS_BRIDGE_IFACES"])
  692. # The CONFIG_NEUTRON_OVS_BRIDGE_MAPPINGS parameter contains a
  693. # comma-separated list of bridge mappings. Since the puppet module
  694. # expects this parameter to be an array, this parameter must be
  695. # properly formatted by packstack, then consumed by the puppet module.
  696. # For example, the input string 'A, B' should formatted as '['A','B']'.
  697. config["CONFIG_NEUTRON_OVS_BRIDGE_MAPPINGS"] = bm_arr
  698. config["CONFIG_NEUTRON_OVS_BRIDGE_IFACES"] = []
  699. # Bridge configuration and mappings for compute nodes can be different.
  700. # Parameter CONFIG_NEUTRON_OVS_BRIDGES_COMPUTE contains the list of
  701. # bridge names, included in bridge mappings and bridge interfaces, that
  702. # must be created in compute nodes.
  703. brd_arr_cmp = get_values(config["CONFIG_NEUTRON_OVS_BRIDGES_COMPUTE"])
  704. if_arr_cmp = []
  705. mapp_arr_cmp = []
  706. for brd in brd_arr_cmp:
  707. if_arr_cmp.append(common.find_pair_with(iface_arr, brd, 0))
  708. mapp_arr_cmp.append(common.find_pair_with(bm_arr, brd, 1))
  709. config["CONFIG_NEUTRON_OVS_BRIDGE_MAPPINGS_COMPUTE"] = mapp_arr_cmp
  710. config["CONFIG_NEUTRON_OVS_BRIDGE_IFACES_COMPUTE"] = []
  711. no_local_types = set(ovs_type) & set(['gre', 'vxlan', 'vlan', 'flat'])
  712. no_tunnel_types = set(ovs_type) & set(['vlan', 'flat'])
  713. elif agent == "linuxbridge":
  714. host_var = 'CONFIG_NEUTRON_LB_HOST'
  715. else:
  716. raise KeyError("Unknown layer2 agent")
  717. for host in network_hosts | compute_hosts:
  718. # NICs connected to OVS bridges can be required in network nodes if
  719. # vlan, flat, vxlan or gre are enabled. For compute nodes, they are
  720. # only required if vlan or flat are enabled.
  721. if (
  722. agent == "openvswitch" and (
  723. (host in network_hosts and no_local_types)
  724. or no_tunnel_types)
  725. ):
  726. if config['CONFIG_USE_SUBNETS'] == 'y':
  727. iface_arr = [
  728. common.cidr_to_ifname(i, host, config) for i in iface_arr
  729. ]
  730. if_arr_cmp = [
  731. common.cidr_to_ifname(i, host, config) for i in if_arr_cmp
  732. ]
  733. config["CONFIG_NEUTRON_OVS_BRIDGE_IFACES"] = iface_arr
  734. config["CONFIG_NEUTRON_OVS_BRIDGE_IFACES_COMPUTE"] = if_arr_cmp
  735. config['CREATE_BRIDGES'] = 'y'
  736. else:
  737. config['CREATE_BRIDGES'] = 'n'
  738. def check_nm_status(config, messages):
  739. hosts_with_nm = []
  740. for host in common.filtered_hosts(config):
  741. server = utils.ScriptRunner(host)
  742. server.append("systemctl")
  743. rc, out = server.execute(can_fail=False)
  744. server.clear()
  745. if rc < 1:
  746. server.append("systemctl is-enabled NetworkManager")
  747. rc, is_enabled = server.execute(can_fail=False)
  748. is_enabled = is_enabled.strip("\n ")
  749. server.clear()
  750. server.append("systemctl is-active NetworkManager")
  751. rc, is_active = server.execute(can_fail=False)
  752. is_active = is_active.strip("\n ")
  753. if is_enabled == "enabled" or is_active == "active":
  754. hosts_with_nm.append(host)
  755. else:
  756. server.clear()
  757. server.append("service NetworkManager status")
  758. rc, out = server.execute(can_fail=False)
  759. if rc < 1:
  760. hosts_with_nm.append(host)
  761. server.clear()
  762. if hosts_with_nm:
  763. hosts_list = ', '.join("%s" % x for x in hosts_with_nm)
  764. msg = output_messages.WARN_NM_ENABLED
  765. messages.append(utils.color_text(msg % hosts_list, 'yellow'))