summaryrefslogtreecommitdiffstats
path: root/lib/python
diff options
context:
space:
mode:
authorTim Rozet <trozet@redhat.com>2016-11-30 15:37:12 -0500
committerTim Rozet <trozet@redhat.com>2016-12-02 14:27:30 -0500
commitffeea8b7aff158a65b5f8c7baf445c6f2206790f (patch)
tree410b0d3ffc8b4c6a49864717fb1db4c7c14599dd /lib/python
parent71b677dcf162eb6eb22f116ee1b08714efb24db3 (diff)
Fixes using single network (previously called flat) for deploy
Also contains various network parsing fixes. JIRA: APEX-361 Change-Id: I5e40ed67267d5ded85adc2982a8726ebbceaeae5 Signed-off-by: Tim Rozet <trozet@redhat.com>
Diffstat (limited to 'lib/python')
-rw-r--r--lib/python/apex/deploy_settings.py2
-rw-r--r--lib/python/apex/inventory.py2
-rw-r--r--lib/python/apex/network_environment.py41
-rw-r--r--lib/python/apex/network_settings.py28
4 files changed, 38 insertions, 35 deletions
diff --git a/lib/python/apex/deploy_settings.py b/lib/python/apex/deploy_settings.py
index a27d13f1..963520a6 100644
--- a/lib/python/apex/deploy_settings.py
+++ b/lib/python/apex/deploy_settings.py
@@ -38,7 +38,7 @@ class DeploySettings(dict):
"""
def __init__(self, filename):
init_dict = {}
- if type(filename) is str:
+ if isinstance(filename, str):
with open(filename, 'r') as deploy_settings_file:
init_dict = yaml.safe_load(deploy_settings_file)
else:
diff --git a/lib/python/apex/inventory.py b/lib/python/apex/inventory.py
index 37143566..711eb18f 100644
--- a/lib/python/apex/inventory.py
+++ b/lib/python/apex/inventory.py
@@ -22,7 +22,7 @@ class Inventory(dict):
"""
def __init__(self, source, ha=True, virtual=False):
init_dict = {}
- if type(source) is str:
+ if isinstance(source, str):
with open(source, 'r') as inventory_file:
yaml_dict = yaml.safe_load(inventory_file)
# collapse node identifiers from the structure
diff --git a/lib/python/apex/network_environment.py b/lib/python/apex/network_environment.py
index b931a758..4fc6f583 100644
--- a/lib/python/apex/network_environment.py
+++ b/lib/python/apex/network_environment.py
@@ -21,6 +21,7 @@ from .common.constants import (
COMPUTE_PRE,
PRE_CONFIG_DIR
)
+from .network_settings import NetworkSettings
HEAT_NONE = 'OS::Heat::None'
PORTS = '/ports'
@@ -63,15 +64,13 @@ class NetworkEnvironment(dict):
Create Network Environment according to Network Settings
"""
init_dict = {}
- if type(filename) is str:
+ if isinstance(filename, str):
with open(filename, 'r') as net_env_fh:
init_dict = yaml.safe_load(net_env_fh)
super().__init__(init_dict)
- try:
- enabled_nets = net_settings.enabled_network_list
- except:
- raise NetworkEnvException('Invalid Network Setting object')
+ if not isinstance(net_settings, NetworkSettings):
+ raise NetworkEnvException('Invalid Network Settings object')
self._set_tht_dir()
@@ -86,19 +85,21 @@ class NetworkEnvironment(dict):
nets[ADMIN_NETWORK]['installer_vm']['ip']
self[param_def]['DnsServers'] = net_settings['dns_servers']
- if EXTERNAL_NETWORK in enabled_nets:
- external_cidr = nets[EXTERNAL_NETWORK][0]['cidr']
+ if EXTERNAL_NETWORK in net_settings.enabled_network_list:
+ external_cidr = net_settings.get_network(EXTERNAL_NETWORK)['cidr']
self[param_def]['ExternalNetCidr'] = str(external_cidr)
- if type(nets[EXTERNAL_NETWORK][0]['installer_vm']['vlan']) is int:
+ external_vlan = self._get_vlan(net_settings.get_network(
+ EXTERNAL_NETWORK))
+ if isinstance(external_vlan, int):
self[param_def]['NeutronExternalNetworkBridge'] = '""'
- self[param_def]['ExternalNetworkVlanID'] = \
- nets[EXTERNAL_NETWORK][0]['installer_vm']['vlan']
- external_range = nets[EXTERNAL_NETWORK][0]['overcloud_ip_range']
+ self[param_def]['ExternalNetworkVlanID'] = external_vlan
+ external_range = net_settings.get_network(EXTERNAL_NETWORK)[
+ 'overcloud_ip_range']
self[param_def]['ExternalAllocationPools'] = \
[{'start': str(external_range[0]),
'end': str(external_range[1])}]
self[param_def]['ExternalInterfaceDefaultRoute'] = \
- nets[EXTERNAL_NETWORK][0]['gateway']
+ net_settings.get_network(EXTERNAL_NETWORK)['gateway']
if external_cidr.version == 6:
postfix = '/external_v6.yaml'
@@ -110,7 +111,7 @@ class NetworkEnvironment(dict):
# apply resource registry update for EXTERNAL_RESOURCES
self._config_resource_reg(EXTERNAL_RESOURCES, postfix)
- if TENANT_NETWORK in enabled_nets:
+ if TENANT_NETWORK in net_settings.enabled_network_list:
tenant_range = nets[TENANT_NETWORK]['overcloud_ip_range']
self[param_def]['TenantAllocationPools'] = \
[{'start': str(tenant_range[0]),
@@ -123,7 +124,7 @@ class NetworkEnvironment(dict):
postfix = '/tenant.yaml'
tenant_vlan = self._get_vlan(nets[TENANT_NETWORK])
- if type(tenant_vlan) is int:
+ if isinstance(tenant_vlan, int):
self[param_def]['TenantNetworkVlanID'] = tenant_vlan
else:
postfix = '/noop.yaml'
@@ -131,7 +132,7 @@ class NetworkEnvironment(dict):
# apply resource registry update for TENANT_RESOURCES
self._config_resource_reg(TENANT_RESOURCES, postfix)
- if STORAGE_NETWORK in enabled_nets:
+ if STORAGE_NETWORK in net_settings.enabled_network_list:
storage_range = nets[STORAGE_NETWORK]['overcloud_ip_range']
self[param_def]['StorageAllocationPools'] = \
[{'start': str(storage_range[0]),
@@ -143,7 +144,7 @@ class NetworkEnvironment(dict):
else:
postfix = '/storage.yaml'
storage_vlan = self._get_vlan(nets[STORAGE_NETWORK])
- if type(storage_vlan) is int:
+ if isinstance(storage_vlan, int):
self[param_def]['StorageNetworkVlanID'] = storage_vlan
else:
postfix = '/noop.yaml'
@@ -151,7 +152,7 @@ class NetworkEnvironment(dict):
# apply resource registry update for STORAGE_RESOURCES
self._config_resource_reg(STORAGE_RESOURCES, postfix)
- if API_NETWORK in enabled_nets:
+ if API_NETWORK in net_settings.enabled_network_list:
api_range = nets[API_NETWORK]['overcloud_ip_range']
self[param_def]['InternalApiAllocationPools'] = \
[{'start': str(api_range[0]),
@@ -163,7 +164,7 @@ class NetworkEnvironment(dict):
else:
postfix = '/internal_api.yaml'
api_vlan = self._get_vlan(nets[API_NETWORK])
- if type(api_vlan) is int:
+ if isinstance(api_vlan, int):
self[param_def]['InternalApiNetworkVlanID'] = api_vlan
else:
postfix = '/noop.yaml'
@@ -184,9 +185,9 @@ class NetworkEnvironment(dict):
self[param_def][flag] = True
def _get_vlan(self, network):
- if type(network['nic_mapping'][CONTROLLER]['vlan']) is int:
+ if isinstance(network['nic_mapping'][CONTROLLER]['vlan'], int):
return network['nic_mapping'][CONTROLLER]['vlan']
- elif type(network['nic_mapping'][COMPUTE]['vlan']) is int:
+ elif isinstance(network['nic_mapping'][COMPUTE]['vlan'], int):
return network['nic_mapping'][COMPUTE]['vlan']
else:
return 'native'
diff --git a/lib/python/apex/network_settings.py b/lib/python/apex/network_settings.py
index 951000dc..64065ca7 100644
--- a/lib/python/apex/network_settings.py
+++ b/lib/python/apex/network_settings.py
@@ -14,7 +14,6 @@ import ipaddress
from copy import copy
from . import ip_utils
-from .common import utils
from .common.constants import (
CONTROLLER,
COMPUTE,
@@ -42,7 +41,7 @@ class NetworkSettings(dict):
"""
def __init__(self, filename):
init_dict = {}
- if type(filename) is str:
+ if isinstance(filename, str):
with open(filename, 'r') as network_settings_file:
init_dict = yaml.safe_load(network_settings_file)
else:
@@ -55,7 +54,7 @@ class NetworkSettings(dict):
def merge(pri, sec):
for key, val in sec.items():
if key in pri:
- if type(val) is dict:
+ if isinstance(val, dict):
merge(pri[key], val)
# else
# do not overwrite what's already there
@@ -71,7 +70,14 @@ class NetworkSettings(dict):
def get_network(self, network):
if network == EXTERNAL_NETWORK and self['networks'][network]:
- return self['networks'][network][0]
+ for net in self['networks'][network]:
+ if 'public' in net:
+ return net
+
+ raise NetworkSettingsException("The external network, "
+ "'public', should be defined "
+ "when external networks are "
+ "enabled")
else:
return self['networks'][network]
@@ -92,10 +98,7 @@ class NetworkSettings(dict):
if _network.get('enabled', True):
logging.info("{} enabled".format(network))
self._config_required_settings(network)
- if network == EXTERNAL_NETWORK:
- nicmap = _network['nic_mapping']
- else:
- nicmap = _network['nic_mapping']
+ nicmap = _network['nic_mapping']
iface = nicmap[CONTROLLER]['members'][0]
self._config_ip_range(network=network,
interface=iface,
@@ -137,7 +140,7 @@ class NetworkSettings(dict):
if interfaces:
interface = interfaces[0]
- if type(_role.get('vlan', 'native')) is not int and \
+ if not isinstance(_role.get('vlan', 'native'), int) and \
any(y == interface for x, y in self.nics[role].items()):
raise NetworkSettingsException(
"Duplicate {} already specified for "
@@ -183,7 +186,6 @@ class NetworkSettings(dict):
ip = ipaddress.ip_address(_network['installer_vm']['ip'])
nic_if = ip_utils.get_interface(ucloud_if_list[0], ip.version)
if nic_if:
- ucloud_if_list = [nic_if]
logging.info("{}_bridged_interface: {}".
format(network, nic_if))
else:
@@ -312,16 +314,16 @@ class NetworkSettings(dict):
flatten lists to delim separated strings
flatten dics to underscored key names and string values
"""
- if type(obj) is list:
+ if isinstance(obj, list):
return "{}=\'{}\'\n".format(name,
delim.join(map(lambda x: str(x),
obj)))
- elif type(obj) is dict:
+ elif isinstance(obj, dict):
flat_str = ''
for k in obj:
flat_str += flatten("{}_{}".format(name, k), obj[k])
return flat_str
- elif type(obj) is str:
+ elif isinstance(obj, str):
return "{}='{}'\n".format(name, obj)
else:
return "{}={}\n".format(name, str(obj))