summaryrefslogtreecommitdiffstats
path: root/apex/overcloud/config.py
blob: e48b254f327962392385c795c8eb3a29258ce35d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
##############################################################################
# Copyright (c) 2017 Tim Rozet (trozet@redhat.com) and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

"""
Utilities for generating overcloud configuration
"""

import logging
import os

from jinja2 import Environment
from jinja2 import FileSystemLoader
from apex.common.exceptions import ApexDeployException


def create_nic_template(network_settings, deploy_settings, role, template_dir,
                        target_dir):
    """
    Creates NIC heat template files
    :param ns: Network settings
    :param ds: Deploy Settings
    :param role: controller or compute
    :param template_dir: directory where base templates are stored
    :param target_dir: to store rendered nic template
    :return:
    """
    # TODO(trozet): rather than use Jinja2 to build these files, use with py
    if role not in ['controller', 'compute']:
        raise ApexDeployException("Invalid type for overcloud node: {"
                                  "}".format(type))
    logging.info("Creating template for {}".format(role))
    template_file = 'nics-template.yaml.jinja2'
    nets = network_settings.get('networks')
    env = Environment(loader=FileSystemLoader(template_dir), autoescape=True)
    template = env.get_template(template_file)
    ds = deploy_settings.get('deploy_options')
    ext_net = 'br-ex'
    ovs_dpdk_br = ''
    if ds['dataplane'] == 'fdio':
        nets['tenant']['nic_mapping'][role]['phys_type'] = 'vpp_interface'
        if ds['sdn_controller'] == 'opendaylight' and role == 'compute':
            nets['external'][0]['nic_mapping'][role]['phys_type'] = \
                'vpp_interface'
            ext_net = 'vpp_interface'
    elif ds['dataplane'] == 'ovs_dpdk':
        ovs_dpdk_br = 'br-phy'
    if (ds.get('performance', {}).get(role.title(), {}).get('vpp', {})
            .get('uio-driver')):
        nets['tenant']['nic_mapping'][role]['uio-driver'] =\
            ds['performance'][role.title()]['vpp']['uio-driver']
        if ds['sdn_controller'] == 'opendaylight' and role == 'compute':
            nets['external'][0]['nic_mapping'][role]['uio-driver'] =\
                ds['performance'][role.title()]['vpp']['uio-driver']
    if (ds.get('performance', {}).get(role.title(), {}).get('vpp', {})
            .get('interface-options')):
        nets['tenant']['nic_mapping'][role]['interface-options'] =\
            ds['performance'][role.title()]['vpp']['interface-options']

    if role == 'controller' and ds.get('sfc', None):
        ext_net = 'interface'

    template_output = template.render(
        nets=nets,
        role=role,
        external_net_af=network_settings.get_ip_addr_family(),
        external_net_type=ext_net,
        ovs_dpdk_bridge=ovs_dpdk_br)

    logging.debug("Template output: {}".format(template_output))
    target = os.path.join(target_dir, "{}.yaml".format(role))
    with open(target, "w") as f:
        f.write(template_output)
    logging.info("Wrote template {}".format(target))