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']:
"$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
},
}
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:
#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>
<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)