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 ##############################################################################
14 from apex.common import utils
15 from apex.common.constants import (
22 from apex import NetworkSettings
25 class NetworkDataException(Exception):
29 def create_network_data(ns, target=None):
31 Creates network data file for deployments
32 :param ns: Network Settings
33 :param target: Target file to write
34 :return: list of networks and properties
37 if not isinstance(ns, NetworkSettings):
38 raise NetworkDataException('Invalid network settings given')
42 # TODO(trozet) change this all to be dynamic after TripleO bug
43 # https://bugs.launchpad.net/tripleo/+bug/1720849 is fixed
45 for net in nets.keys():
46 if net == ADMIN_NETWORK:
47 # we dont need to add ctlplane network to network data
49 elif net == EXTERNAL_NETWORK:
50 network = nets[net][0]
51 net_name = net.title()
52 net_lower = net.lower()
53 elif net == API_NETWORK:
55 net_name = 'InternalApi'
56 net_lower = 'internal_api'
59 net_name = net.title()
60 net_lower = net.lower()
61 # TODO(trozet): add ipv6 support
62 tmp_net = {'name': net_name,
63 'name_lower': net_lower,
64 'vip': net != TENANT_NETWORK,
65 'enabled': net in ns.enabled_network_list}
66 if 'gateway' in network:
67 tmp_net['gateway_ip'] = str(network['gateway'])
68 if 'overcloud_ip_range' in network:
69 net_range = network['overcloud_ip_range']
70 tmp_net['allocation_pools'] = [{'start': str(net_range[0]),
71 'end': str(net_range[1])}]
72 elif tmp_net['enabled']:
73 logging.error("overcloud ip range is missing and must be provided "
74 "in network settings when network is enabled for "
75 "network {}".format(net))
76 raise NetworkDataException("overcloud_ip_range missing from "
77 "network: {}".format(net))
79 tmp_net['ip_subnet'] = str(network['cidr'])
80 elif tmp_net['enabled']:
81 logging.error("cidr is missing and must be provided in network "
82 "settings when network is enabled for network "
84 raise NetworkDataException("cidr is null for network {}".format(
87 network_data.append(copy.deepcopy(tmp_net))
89 # have to do this due to the aforementioned bug
91 'name': 'StorageMgmt',
93 'name_lower': 'storage_mgmt',
94 'ip_subnet': '172.16.3.0/24',
95 'allocation_pools': [{'start': '172.16.3.4', 'end': '172.16.3.250'}],
98 network_data.append(storage_mgmt_net)
100 logging.debug("Writing network data to {}".format(target))
101 utils.dump_yaml(network_data, target)
102 logging.debug("Network data parsed as:\n "
103 "{}".format(pprint.pformat(network_data)))