From: tierno Date: Tue, 30 May 2017 14:40:10 +0000 (+0200) Subject: (bug 80) allow several dns_address for ip_profile X-Git-Tag: v2.0.2~27 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=455612d1570ba8924c7170fa8f5d19729b080625;p=osm%2FRO.git (bug 80) allow several dns_address for ip_profile Change-Id: Icded218d71a1fe193321b53ebb4fe522682b8225 Signed-off-by: tierno --- diff --git a/osm_ro/nfvo.py b/osm_ro/nfvo.py index 93300472..d45a3c79 100644 --- a/osm_ro/nfvo.py +++ b/osm_ro/nfvo.py @@ -2041,20 +2041,23 @@ def create_instance(mydb, tenant_id, instance_dict): for scenario_net in scenarioDict['nets']: if net_name == scenario_net["name"]: if 'ip-profile' in net_instance_desc: - ipprofile = net_instance_desc['ip-profile'] - ipprofile['subnet_address'] = ipprofile.pop('subnet-address',None) - ipprofile['ip_version'] = ipprofile.pop('ip-version','IPv4') - ipprofile['gateway_address'] = ipprofile.pop('gateway-address',None) - ipprofile['dns_address'] = ipprofile.pop('dns-address',None) - if 'dhcp' in ipprofile: - ipprofile['dhcp_start_address'] = ipprofile['dhcp'].get('start-address',None) - ipprofile['dhcp_enabled'] = ipprofile['dhcp'].get('enabled',True) - ipprofile['dhcp_count'] = ipprofile['dhcp'].get('count',None) - del ipprofile['dhcp'] + # translate from input format to database format + ipprofile_in = net_instance_desc['ip-profile'] + ipprofile_db = {} + ipprofile_db['subnet_address'] = ipprofile_in.get('subnet-address') + ipprofile_db['ip_version'] = ipprofile_in.get('ip-version', 'IPv4') + ipprofile_db['gateway_address'] = ipprofile_in.get('gateway-address') + ipprofile_db['dns_address'] = ipprofile_in.get('dns-address') + if isinstance(ipprofile_db['dns_address'], (list, tuple)): + ipprofile_db['dns_address'] = ";".join(ipprofile_db['dns_address']) + if 'dhcp' in ipprofile_in: + ipprofile_db['dhcp_start_address'] = ipprofile_in['dhcp'].get('start-address') + ipprofile_db['dhcp_enabled'] = ipprofile_in['dhcp'].get('enabled', True) + ipprofile_db['dhcp_count'] = ipprofile_in['dhcp'].get('count' ) if 'ip_profile' not in scenario_net: - scenario_net['ip_profile'] = ipprofile + scenario_net['ip_profile'] = ipprofile_db else: - update(scenario_net['ip_profile'],ipprofile) + update(scenario_net['ip_profile'], ipprofile_db) for interface in net_instance_desc.get('interfaces', () ): if 'ip_address' in interface: for vnf in scenarioDict['vnfs']: diff --git a/osm_ro/openmano_schemas.py b/osm_ro/openmano_schemas.py index 765c05f0..7d218ec1 100644 --- a/osm_ro/openmano_schemas.py +++ b/osm_ro/openmano_schemas.py @@ -316,10 +316,11 @@ ip_profile_schema = { "$schema": "http://json-schema.org/draft-04/schema#", "type":"object", "properties":{ - "ip-version": {"type":"string", "enum":["IPv4","IPv6"]}, + "ip-version": {"type": "string", "enum": ["IPv4","IPv6"]}, "subnet-address": ip_prefix_schema, "gateway-address": ip_schema, - "dns-address": ip_schema, + "dns-address": {"oneOf": [ip_schema, # for backward compatibility + {"type": "array", "items": ip_schema}]}, "dhcp": dhcp_schema }, } diff --git a/osm_ro/vimconn_openstack.py b/osm_ro/vimconn_openstack.py index de94fff0..e88d18d7 100644 --- a/osm_ro/vimconn_openstack.py +++ b/osm_ro/vimconn_openstack.py @@ -322,9 +322,7 @@ class vimconnector(vimconn.vimconnector): if 'gateway_address' in ip_profile: subnet['gateway_ip'] = ip_profile['gateway_address'] if ip_profile.get('dns_address'): - #TODO: manage dns_address as a list of addresses separated by commas - subnet['dns_nameservers'] = [] - subnet['dns_nameservers'].append(ip_profile['dns_address']) + subnet['dns_nameservers'] = ip_profile['dns_address'].split(";") if 'dhcp_enabled' in ip_profile: subnet['enable_dhcp'] = False if ip_profile['dhcp_enabled']=="false" else True if 'dhcp_start_address' in ip_profile: diff --git a/osm_ro/vimconn_vmware.py b/osm_ro/vimconn_vmware.py index 910387d2..43ffba88 100644 --- a/osm_ro/vimconn_vmware.py +++ b/osm_ro/vimconn_vmware.py @@ -2751,6 +2751,11 @@ class vimconnector(vimconn.vimconnector): #Unused in case of Underlay (data/ptp) network interface. fence_mode="bridged" is_inherited='false' + dns_list = dns_address.split(";") + dns1 = dns_list[0] + dns2_text = "" + if len(dns_list) >= 2: + dns2_text = "\n {}\n".format(dns_list[1]) data = """ Openmano created @@ -2759,22 +2764,22 @@ class vimconnector(vimconn.vimconnector): {1:s} {2:s} {3:s} - {4:s} - {5:s} + {4:s}{5:s} + {6:s} - {6:s} - {7:s} + {7:s} + {8:s} - - {9:s} + + {10:s} - {10:s} + {11:s} """.format(escape(network_name), is_inherited, gateway_address, - subnet_address, dns_address, dhcp_enabled, + subnet_address, dns1, dns2_text, dhcp_enabled, dhcp_start_address, dhcp_end_address, available_networks, fence_mode, isshared)