Merge "Change destination of snmp mibs files from /usr/share/mibs/ietf to /usr/share...
[apex.git] / apex / overcloud / config.py
1 ##############################################################################
2 # Copyright (c) 2017 Tim Rozet (trozet@redhat.com) and others.
3 #
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 ##############################################################################
9
10 """
11 Utilities for generating overcloud configuration
12 """
13
14 import logging
15 import os
16
17 from jinja2 import Environment
18 from jinja2 import FileSystemLoader
19 from apex.common.exceptions import ApexDeployException
20
21
22 def create_nic_template(network_settings, deploy_settings, role, template_dir,
23                         target_dir):
24     """
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
31     :return:
32     """
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: {"
36                                   "}".format(type))
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')
43     ext_net = 'br-ex'
44     ovs_dpdk_br = ''
45     if ds['dataplane'] == 'fdio':
46         nets['tenant']['nic_mapping'][role]['phys_type'] = 'vpp_interface'
47         if ds['sdn_controller'] == 'opendaylight':
48             nets['external'][0]['nic_mapping'][role]['phys_type'] = \
49                 'vpp_interface'
50             ext_net = 'vpp_interface'
51     elif ds['dataplane'] == 'ovs_dpdk':
52         ovs_dpdk_br = 'br-phy'
53     if (ds.get('performance', {}).get(role.title(), {}).get('vpp', {})
54             .get('uio-driver')):
55         nets['tenant']['nic_mapping'][role]['uio-driver'] =\
56             ds['performance'][role.title()]['vpp']['uio-driver']
57         if ds['sdn_controller'] == 'opendaylight':
58             nets['external'][0]['nic_mapping'][role]['uio-driver'] =\
59                 ds['performance'][role.title()]['vpp']['uio-driver']
60     if (ds.get('performance', {}).get(role.title(), {}).get('vpp', {})
61             .get('interface-options')):
62         nets['tenant']['nic_mapping'][role]['interface-options'] =\
63             ds['performance'][role.title()]['vpp']['interface-options']
64
65     template_output = template.render(
66         nets=nets,
67         role=role,
68         external_net_af=network_settings.get_ip_addr_family(),
69         external_net_type=ext_net,
70         ovs_dpdk_bridge=ovs_dpdk_br)
71
72     logging.debug("Template output: {}".format(template_output))
73     target = os.path.join(target_dir, "{}.yaml".format(role))
74     with open(target, "w") as f:
75         f.write(template_output)
76     logging.info("Wrote template {}".format(target))