(bug 80) allow several dns_address for ip_profile 93/1893/4
authortierno <alfonso.tiernosepulveda@telefonica.com>
Tue, 30 May 2017 14:40:10 +0000 (16:40 +0200)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Mon, 5 Jun 2017 14:31:03 +0000 (16:31 +0200)
Change-Id: Icded218d71a1fe193321b53ebb4fe522682b8225
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
osm_ro/nfvo.py
osm_ro/openmano_schemas.py
osm_ro/vimconn_openstack.py
osm_ro/vimconn_vmware.py

index 9330047..d45a3c7 100644 (file)
@@ -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']:
index 765c05f..7d218ec 100644 (file)
@@ -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
     },
 }
index de94fff..e88d18d 100644 (file)
@@ -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:
index 910387d..43ffba8 100644 (file)
@@ -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                                                <Dns2>{}</Dns2>\n".format(dns_list[1])
             data = """ <OrgVdcNetwork name="{0:s}" xmlns="http://www.vmware.com/vcloud/v1.5">
                             <Description>Openmano created</Description>
                                     <Configuration>
@@ -2759,22 +2764,22 @@ class vimconnector(vimconn.vimconnector):
                                                 <IsInherited>{1:s}</IsInherited>
                                                 <Gateway>{2:s}</Gateway>
                                                 <Netmask>{3:s}</Netmask>
-                                                <Dns1>{4:s}</Dns1>
-                                                <IsEnabled>{5:s}</IsEnabled>
+                                                <Dns1>{4:s}</Dns1>{5:s}
+                                                <IsEnabled>{6:s}</IsEnabled>
                                                 <IpRanges>
                                                     <IpRange>
-                                                        <StartAddress>{6:s}</StartAddress>
-                                                        <EndAddress>{7:s}</EndAddress>
+                                                        <StartAddress>{7:s}</StartAddress>
+                                                        <EndAddress>{8:s}</EndAddress>
                                                     </IpRange>
                                                 </IpRanges>
                                             </IpScope>
                                         </IpScopes>
-                                        <ParentNetwork href="{8:s}"/>
-                                        <FenceMode>{9:s}</FenceMode>
+                                        <ParentNetwork href="{9:s}"/>
+                                        <FenceMode>{10:s}</FenceMode>
                                     </Configuration>
-                                    <IsShared>{10:s}</IsShared>
+                                    <IsShared>{11:s}</IsShared>
                         </OrgVdcNetwork> """.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)