diff options
author | Tim Rozet <trozet@redhat.com> | 2016-11-30 15:37:12 -0500 |
---|---|---|
committer | Tim Rozet <trozet@redhat.com> | 2016-12-02 14:27:30 -0500 |
commit | ffeea8b7aff158a65b5f8c7baf445c6f2206790f (patch) | |
tree | 410b0d3ffc8b4c6a49864717fb1db4c7c14599dd /lib | |
parent | 71b677dcf162eb6eb22f116ee1b08714efb24db3 (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')
-rwxr-xr-x | lib/post-install-functions.sh | 19 | ||||
-rw-r--r-- | lib/python/apex/deploy_settings.py | 2 | ||||
-rw-r--r-- | lib/python/apex/inventory.py | 2 | ||||
-rw-r--r-- | lib/python/apex/network_environment.py | 41 | ||||
-rw-r--r-- | lib/python/apex/network_settings.py | 28 | ||||
-rwxr-xr-x | lib/undercloud-functions.sh | 2 |
6 files changed, 55 insertions, 39 deletions
diff --git a/lib/post-install-functions.sh b/lib/post-install-functions.sh index 1055994e..102b86f5 100755 --- a/lib/post-install-functions.sh +++ b/lib/post-install-functions.sh @@ -13,7 +13,10 @@ function configure_post_install { local opnfv_attach_networks ovs_ip ip_range net_cidr tmp_ip af external_network_ipv6 external_network_ipv6=False - opnfv_attach_networks="admin external" + opnfv_attach_networks="admin" + if [[ $enabled_network_list =~ "external" ]]; then + opnfv_attach_networks+=' external' + fi echo -e "${blue}INFO: Post Install Configuration Running...${reset}" @@ -94,8 +97,11 @@ else fi if [ "$external_network_ipv6" == "True" ]; then neutron subnet-create --name external-net --tenant-id \$(openstack project show service | grep id | awk '{ print \$4 }') external --ip_version 6 --ipv6_ra_mode slaac --ipv6_address_mode slaac --gateway ${external_gateway} --allocation-pool start=${external_floating_ip_range%%,*},end=${external_floating_ip_range##*,} ${external_cidr} -else +elif [[ "$enabled_network_list" =~ "external" ]]; then neutron subnet-create --name external-net --tenant-id \$(openstack project show service | grep id | awk '{ print \$4 }') --disable-dhcp external --gateway ${external_gateway} --allocation-pool start=${external_floating_ip_range%%,*},end=${external_floating_ip_range##*,} ${external_cidr} +else + # we re-use the introspection range for floating ips with single admin network + neutron subnet-create --name external-net --tenant-id \$(openstack project show service | grep id | awk '{ print \$4 }') --disable-dhcp external --gateway ${admin_gateway} --allocation-pool start=${admin_introspection_range%%,*},end=${admin_introspection_range##*,} ${admin_cidr} fi echo "Removing sahara endpoint and service" @@ -145,8 +151,13 @@ EOI # for virtual, we NAT external network through Undercloud # same goes for baremetal if only jumphost has external connectivity if [ "$virtual" == "TRUE" ] || ! test_overcloud_connectivity && [ "$external_network_ipv6" != "True" ]; then - if ! configure_undercloud_nat ${external_cidr}; then - echo -e "${red}ERROR: Unable to NAT undercloud with external net: ${external_cidr}${reset}" + if [[ "$enabled_network_list" =~ "external" ]]; then + nat_cidr=${external_cidr} + else + nat_cidr=${admin_cidr} + fi + if ! configure_undercloud_nat ${nat_cidr}; then + echo -e "${red}ERROR: Unable to NAT undercloud with external net: ${nat_cidr}${reset}" exit 1 else echo -e "${blue}INFO: Undercloud VM has been setup to NAT Overcloud external network${reset}" 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)) diff --git a/lib/undercloud-functions.sh b/lib/undercloud-functions.sh index bd93aa78..a5d3b78d 100755 --- a/lib/undercloud-functions.sh +++ b/lib/undercloud-functions.sh @@ -253,6 +253,7 @@ sudo systemctl restart openstack-heat-api EOI # configure external network +if [[ "$enabled_network_list" =~ "external" ]]; then ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" << EOI if [[ "$external_installer_vm_vlan" != "native" ]]; then cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-vlan${external_installer_vm_vlan} @@ -274,6 +275,7 @@ else fi fi EOI +fi # WORKAROUND: must restart the above services to fix sync problem with nova compute manager # TODO: revisit and file a bug if necessary. This should eventually be removed |