1 ##############################################################################
2 # Copyright (c) 2017 Tim Rozet (trozet@redhat.com) and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
11 Utilities for generating overcloud configuration
17 from jinja2 import Environment
18 from jinja2 import FileSystemLoader
19 from apex.common.exceptions import ApexDeployException
22 def create_nic_template(network_settings, deploy_settings, role, template_dir,
25 Creates NIC heat template files
26 :param ns: Network settings
27 :param ds: Deploy Settings
28 :param role: controller or compute
29 :param template_dir: directory where base templates are stored
30 :param target_dir: to store rendered nic template
33 # TODO(trozet): rather than use Jinja2 to build these files, use with py
34 if role not in ['controller', 'compute']:
35 raise ApexDeployException("Invalid type for overcloud node: {"
37 logging.info("Creating template for {}".format(role))
38 template_file = 'nics-template.yaml.jinja2'
39 nets = network_settings.get('networks')
40 env = Environment(loader=FileSystemLoader(template_dir), autoescape=True)
41 template = env.get_template(template_file)
42 ds = deploy_settings.get('deploy_options')
45 if ds['dataplane'] == 'fdio':
46 nets['tenant']['nic_mapping'][role]['phys_type'] = 'vpp_interface'
47 if ds['sdn_controller'] == 'opendaylight':
49 nets['external'][0]['nic_mapping'][role]['phys_type'] = \
51 ext_net = 'vpp_interface'
52 if ds.get('dvr') is True:
53 nets['admin']['nic_mapping'][role]['phys_type'] = \
56 nets['external'][0]['nic_mapping'][role]['phys_type'] = \
58 elif ds['dataplane'] == 'ovs_dpdk':
59 ovs_dpdk_br = 'br-phy'
60 if (ds.get('performance', {}).get(role.title(), {}).get('vpp', {})
62 nets['tenant']['nic_mapping'][role]['uio-driver'] =\
63 ds['performance'][role.title()]['vpp']['uio-driver']
64 if ds['sdn_controller'] == 'opendaylight' and role == 'compute':
65 nets['external'][0]['nic_mapping'][role]['uio-driver'] =\
66 ds['performance'][role.title()]['vpp']['uio-driver']
67 if (ds.get('performance', {}).get(role.title(), {}).get('vpp', {})
68 .get('interface-options')):
69 nets['tenant']['nic_mapping'][role]['interface-options'] =\
70 ds['performance'][role.title()]['vpp']['interface-options']
72 template_output = template.render(
75 external_net_af=network_settings.get_ip_addr_family(),
76 external_net_type=ext_net,
77 ovs_dpdk_bridge=ovs_dpdk_br)
79 logging.debug("Template output: {}".format(template_output))
80 target = os.path.join(target_dir, "{}.yaml".format(role))
81 with open(target, "w") as f:
82 f.write(template_output)
83 logging.info("Wrote template {}".format(target))