- tries = 2
- while tries:
- created_time = time.time()
- try:
- with self.con:
-
- myVNFDict = {}
- myVNFDict["name"] = vnf_name
- myVNFDict["descriptor"] = vnf_descriptor['vnf'].get('descriptor')
- myVNFDict["public"] = vnf_descriptor['vnf'].get('public', "false")
- myVNFDict["description"] = vnf_descriptor['vnf']['description']
- myVNFDict["class"] = vnf_descriptor['vnf'].get('class',"MISC")
- myVNFDict["tenant_id"] = vnf_descriptor['vnf'].get("tenant_id")
-
- vnf_id = self._new_row_internal('vnfs', myVNFDict, add_uuid=True, root_uuid=None, created_time=created_time)
- #print "Adding new vms to the NFVO database"
- #For each vm, we must create the appropriate vm in the NFVO database.
- vmDict = {}
- for _,vm in VNFCDict.iteritems():
- #This code could make the name of the vms grow and grow.
- #If we agree to follow this convention, we should check with a regex that the vnfc name is not including yet the vnf name
- #vm['name'] = "%s-%s" % (vnf_name,vm['name'])
- #print "VM name: %s. Description: %s" % (vm['name'], vm['description'])
- vm["vnf_id"] = vnf_id
- created_time += 0.00001
- vm_id = self._new_row_internal('vms', vm, add_uuid=True, root_uuid=vnf_id, created_time=created_time)
- #print "Internal vm id in NFVO DB: %s" % vm_id
- vmDict[vm['name']] = vm_id
-
- #Collect the bridge interfaces of each VM/VNFC under the 'bridge-ifaces' field
- bridgeInterfacesDict = {}
- for vm in vnf_descriptor['vnf']['VNFC']:
- if 'bridge-ifaces' in vm:
- bridgeInterfacesDict[vm['name']] = {}
- for bridgeiface in vm['bridge-ifaces']:
- created_time += 0.00001
- db_base._convert_bandwidth(bridgeiface, logger=self.logger)
- if 'port-security' in bridgeiface:
- bridgeiface['port_security'] = bridgeiface.pop('port-security')
- if 'floating-ip' in bridgeiface:
- bridgeiface['floating_ip'] = bridgeiface.pop('floating-ip')
- ifaceDict = {}
- ifaceDict['vpci'] = bridgeiface.get('vpci',None)
- ifaceDict['mac'] = bridgeiface.get('mac_address',None)
- ifaceDict['bw'] = bridgeiface.get('bandwidth', None)
- ifaceDict['model'] = bridgeiface.get('model', None)
- ifaceDict['port_security'] = int(bridgeiface.get('port_security', True))
- ifaceDict['floating_ip'] = int(bridgeiface.get('floating_ip', False))
- ifaceDict['created_time'] = created_time
- bridgeInterfacesDict[vm['name']][bridgeiface['name']] = ifaceDict
-
- # Collect the data interfaces of each VM/VNFC under the 'numas' field
- dataifacesDict = {}
- for vm in vnf_descriptor['vnf']['VNFC']:
- dataifacesDict[vm['name']] = {}
- for numa in vm.get('numas', []):
- for dataiface in numa.get('interfaces', []):
- created_time += 0.00001
- db_base._convert_bandwidth(dataiface, logger=self.logger)
- ifaceDict = {}
- ifaceDict['vpci'] = dataiface.get('vpci')
- ifaceDict['bw'] = dataiface['bandwidth']
- ifaceDict['model'] = "PF" if dataiface['dedicated'] == "yes" else \
- ("VF" if dataiface['dedicated'] == "no" else "VFnotShared")
- ifaceDict['created_time'] = created_time
- dataifacesDict[vm['name']][dataiface['name']] = ifaceDict
-
- #For each internal connection, we add it to the interfaceDict and we create the appropriate net in the NFVO database.
- #print "Adding new nets (VNF internal nets) to the NFVO database (if any)"
- if 'internal-connections' in vnf_descriptor['vnf']:
- for net in vnf_descriptor['vnf']['internal-connections']:
- #print "Net name: %s. Description: %s" % (net['name'], net['description'])
-
- myNetDict = {}
- myNetDict["name"] = net['name']
- myNetDict["description"] = net['description']
- if (net["implementation"] == "overlay"):
- net["type"] = "bridge"
- #It should give an error if the type is e-line. For the moment, we consider it as a bridge
- elif (net["implementation"] == "underlay"):
- if (net["type"] == "e-line"):
- net["type"] = "ptp"
- elif (net["type"] == "e-lan"):
- net["type"] = "data"
- net.pop("implementation")
- myNetDict["type"] = net['type']
- myNetDict["vnf_id"] = vnf_id
-
- created_time += 0.00001
- net_id = self._new_row_internal('nets', myNetDict, add_uuid=True, root_uuid=vnf_id, created_time=created_time)
-
- if "ip-profile" in net:
- ip_profile = net["ip-profile"]
- myIPProfileDict = {}
- myIPProfileDict["net_id"] = net_id
- myIPProfileDict["ip_version"] = ip_profile.get('ip-version',"IPv4")
- myIPProfileDict["subnet_address"] = ip_profile.get('subnet-address',None)
- myIPProfileDict["gateway_address"] = ip_profile.get('gateway-address',None)
- myIPProfileDict["dns_address"] = ip_profile.get('dns-address',None)
- if ("dhcp" in ip_profile):
- myIPProfileDict["dhcp_enabled"] = ip_profile["dhcp"].get('enabled',"true")
- myIPProfileDict["dhcp_start_address"] = ip_profile["dhcp"].get('start-address',None)
- myIPProfileDict["dhcp_count"] = ip_profile["dhcp"].get('count',None)
-
- created_time += 0.00001
- ip_profile_id = self._new_row_internal('ip_profiles', myIPProfileDict)
-
- for element in net['elements']:
- ifaceItem = {}
- #ifaceItem["internal_name"] = "%s-%s-%s" % (net['name'],element['VNFC'], element['local_iface_name'])
- ifaceItem["internal_name"] = element['local_iface_name']
- #ifaceItem["vm_id"] = vmDict["%s-%s" % (vnf_name,element['VNFC'])]
- ifaceItem["vm_id"] = vmDict[element['VNFC']]
- ifaceItem["net_id"] = net_id
- ifaceItem["type"] = net['type']
- ifaceItem["ip_address"] = element.get('ip_address',None)
- if ifaceItem ["type"] == "data":
- ifaceDict = dataifacesDict[ element['VNFC'] ][ element['local_iface_name'] ]
- ifaceItem["vpci"] = ifaceDict['vpci']
- ifaceItem["bw"] = ifaceDict['bw']
- ifaceItem["model"] = ifaceDict['model']
- else:
- ifaceDict = bridgeInterfacesDict[ element['VNFC'] ][ element['local_iface_name'] ]
- ifaceItem["vpci"] = ifaceDict['vpci']
- ifaceItem["mac"] = ifaceDict['mac']
- ifaceItem["bw"] = ifaceDict['bw']
- ifaceItem["model"] = ifaceDict['model']
- ifaceItem["port_security"] = ifaceDict['port_security']
- ifaceItem["floating_ip"] = ifaceDict['floating_ip']
- created_time_iface = ifaceDict["created_time"]
- #print "Iface name: %s" % iface['internal_name']
- iface_id = self._new_row_internal('interfaces', ifaceItem, add_uuid=True, root_uuid=vnf_id, created_time=created_time_iface)
- #print "Iface id in NFVO DB: %s" % iface_id
-
- #print "Adding external interfaces to the NFVO database"
- for iface in vnf_descriptor['vnf']['external-connections']:
- myIfaceDict = {}
- #myIfaceDict["internal_name"] = "%s-%s-%s" % (vnf_name,iface['VNFC'], iface['local_iface_name'])
- myIfaceDict["internal_name"] = iface['local_iface_name']
- #myIfaceDict["vm_id"] = vmDict["%s-%s" % (vnf_name,iface['VNFC'])]
- myIfaceDict["vm_id"] = vmDict[iface['VNFC']]
- myIfaceDict["external_name"] = iface['name']
- myIfaceDict["type"] = iface['type']
- if iface["type"] == "data":
- myIfaceDict["vpci"] = dataifacesDict[ iface['VNFC'] ][ iface['local_iface_name'] ]['vpci']
- myIfaceDict["bw"] = dataifacesDict[ iface['VNFC'] ][ iface['local_iface_name'] ]['bw']
- myIfaceDict["model"] = dataifacesDict[ iface['VNFC'] ][ iface['local_iface_name'] ]['model']
- created_time_iface = dataifacesDict[ iface['VNFC'] ][ iface['local_iface_name'] ]['created_time']
- else:
- myIfaceDict["vpci"] = bridgeInterfacesDict[ iface['VNFC'] ][ iface['local_iface_name'] ]['vpci']
- myIfaceDict["bw"] = bridgeInterfacesDict[ iface['VNFC'] ][ iface['local_iface_name'] ]['bw']
- myIfaceDict["model"] = bridgeInterfacesDict[ iface['VNFC'] ][ iface['local_iface_name'] ]['model']
- myIfaceDict["mac"] = bridgeInterfacesDict[ iface['VNFC'] ][ iface['local_iface_name'] ]['mac']
- myIfaceDict["port_security"] = \
- bridgeInterfacesDict[iface['VNFC']][iface['local_iface_name']]['port_security']
- myIfaceDict["floating_ip"] = \
- bridgeInterfacesDict[iface['VNFC']][iface['local_iface_name']]['floating_ip']
- created_time_iface = bridgeInterfacesDict[iface['VNFC']][iface['local_iface_name']]['created_time']
- #print "Iface name: %s" % iface['name']
- iface_id = self._new_row_internal('interfaces', myIfaceDict, add_uuid=True, root_uuid=vnf_id, created_time=created_time_iface)
- #print "Iface id in NFVO DB: %s" % iface_id
-
- return vnf_id
-
- except (mdb.Error, AttributeError) as e:
- self._format_error(e, tries)
+ created_time = time.time()
+ myVNFDict = {}
+ myVNFDict["name"] = vnf_name
+ myVNFDict["descriptor"] = vnf_descriptor['vnf'].get('descriptor')
+ myVNFDict["public"] = vnf_descriptor['vnf'].get('public', "false")
+ myVNFDict["description"] = vnf_descriptor['vnf']['description']
+ myVNFDict["class"] = vnf_descriptor['vnf'].get('class',"MISC")
+ myVNFDict["tenant_id"] = vnf_descriptor['vnf'].get("tenant_id")
+
+ vnf_id = self._new_row_internal('vnfs', myVNFDict, add_uuid=True, root_uuid=None, created_time=created_time)
+ #print "Adding new vms to the NFVO database"
+ #For each vm, we must create the appropriate vm in the NFVO database.
+ vmDict = {}
+ for _,vm in VNFCDict.iteritems():
+ #This code could make the name of the vms grow and grow.
+ #If we agree to follow this convention, we should check with a regex that the vnfc name is not including yet the vnf name
+ #vm['name'] = "%s-%s" % (vnf_name,vm['name'])
+ #print "VM name: %s. Description: %s" % (vm['name'], vm['description'])
+ vm["vnf_id"] = vnf_id
+ created_time += 0.00001
+ vm_id = self._new_row_internal('vms', vm, add_uuid=True, root_uuid=vnf_id, created_time=created_time)
+ #print "Internal vm id in NFVO DB: %s" % vm_id
+ vmDict[vm['name']] = vm_id
+
+ #Collect the bridge interfaces of each VM/VNFC under the 'bridge-ifaces' field
+ bridgeInterfacesDict = {}
+ for vm in vnf_descriptor['vnf']['VNFC']:
+ if 'bridge-ifaces' in vm:
+ bridgeInterfacesDict[vm['name']] = {}
+ for bridgeiface in vm['bridge-ifaces']:
+ created_time += 0.00001
+ db_base._convert_bandwidth(bridgeiface, logger=self.logger)
+ if 'port-security' in bridgeiface:
+ bridgeiface['port_security'] = bridgeiface.pop('port-security')
+ if 'floating-ip' in bridgeiface:
+ bridgeiface['floating_ip'] = bridgeiface.pop('floating-ip')
+ ifaceDict = {}
+ ifaceDict['vpci'] = bridgeiface.get('vpci',None)
+ ifaceDict['mac'] = bridgeiface.get('mac_address',None)
+ ifaceDict['bw'] = bridgeiface.get('bandwidth', None)
+ ifaceDict['model'] = bridgeiface.get('model', None)
+ ifaceDict['port_security'] = int(bridgeiface.get('port_security', True))
+ ifaceDict['floating_ip'] = int(bridgeiface.get('floating_ip', False))
+ ifaceDict['created_time'] = created_time
+ bridgeInterfacesDict[vm['name']][bridgeiface['name']] = ifaceDict
+
+ # Collect the data interfaces of each VM/VNFC under the 'numas' field
+ dataifacesDict = {}
+ for vm in vnf_descriptor['vnf']['VNFC']:
+ dataifacesDict[vm['name']] = {}
+ for numa in vm.get('numas', []):
+ for dataiface in numa.get('interfaces', []):
+ created_time += 0.00001
+ db_base._convert_bandwidth(dataiface, logger=self.logger)
+ ifaceDict = {}
+ ifaceDict['vpci'] = dataiface.get('vpci')
+ ifaceDict['bw'] = dataiface['bandwidth']
+ ifaceDict['model'] = "PF" if dataiface['dedicated'] == "yes" else \
+ ("VF" if dataiface['dedicated'] == "no" else "VFnotShared")
+ ifaceDict['created_time'] = created_time
+ dataifacesDict[vm['name']][dataiface['name']] = ifaceDict
+
+ #For each internal connection, we add it to the interfaceDict and we create the appropriate net in the NFVO database.
+ #print "Adding new nets (VNF internal nets) to the NFVO database (if any)"
+ if 'internal-connections' in vnf_descriptor['vnf']:
+ for net in vnf_descriptor['vnf']['internal-connections']:
+ #print "Net name: %s. Description: %s" % (net['name'], net['description'])
+
+ myNetDict = {}
+ myNetDict["name"] = net['name']
+ myNetDict["description"] = net['description']
+ if (net["implementation"] == "overlay"):
+ net["type"] = "bridge"
+ #It should give an error if the type is e-line. For the moment, we consider it as a bridge
+ elif (net["implementation"] == "underlay"):
+ if (net["type"] == "e-line"):
+ net["type"] = "ptp"
+ elif (net["type"] == "e-lan"):
+ net["type"] = "data"
+ net.pop("implementation")
+ myNetDict["type"] = net['type']
+ myNetDict["vnf_id"] = vnf_id
+
+ created_time += 0.00001
+ net_id = self._new_row_internal('nets', myNetDict, add_uuid=True, root_uuid=vnf_id, created_time=created_time)
+
+ if "ip-profile" in net:
+ ip_profile = net["ip-profile"]
+ myIPProfileDict = {}
+ myIPProfileDict["net_id"] = net_id
+ myIPProfileDict["ip_version"] = ip_profile.get('ip-version',"IPv4")
+ myIPProfileDict["subnet_address"] = ip_profile.get('subnet-address',None)
+ myIPProfileDict["gateway_address"] = ip_profile.get('gateway-address',None)
+ myIPProfileDict["dns_address"] = ip_profile.get('dns-address',None)
+ if ("dhcp" in ip_profile):
+ myIPProfileDict["dhcp_enabled"] = ip_profile["dhcp"].get('enabled',"true")
+ myIPProfileDict["dhcp_start_address"] = ip_profile["dhcp"].get('start-address',None)
+ myIPProfileDict["dhcp_count"] = ip_profile["dhcp"].get('count',None)
+
+ created_time += 0.00001
+ ip_profile_id = self._new_row_internal('ip_profiles', myIPProfileDict)
+
+ for element in net['elements']:
+ ifaceItem = {}
+ #ifaceItem["internal_name"] = "%s-%s-%s" % (net['name'],element['VNFC'], element['local_iface_name'])
+ ifaceItem["internal_name"] = element['local_iface_name']
+ #ifaceItem["vm_id"] = vmDict["%s-%s" % (vnf_name,element['VNFC'])]
+ ifaceItem["vm_id"] = vmDict[element['VNFC']]
+ ifaceItem["net_id"] = net_id
+ ifaceItem["type"] = net['type']
+ ifaceItem["ip_address"] = element.get('ip_address',None)
+ if ifaceItem ["type"] == "data":
+ ifaceDict = dataifacesDict[ element['VNFC'] ][ element['local_iface_name'] ]
+ ifaceItem["vpci"] = ifaceDict['vpci']
+ ifaceItem["bw"] = ifaceDict['bw']
+ ifaceItem["model"] = ifaceDict['model']
+ else:
+ ifaceDict = bridgeInterfacesDict[ element['VNFC'] ][ element['local_iface_name'] ]
+ ifaceItem["vpci"] = ifaceDict['vpci']
+ ifaceItem["mac"] = ifaceDict['mac']
+ ifaceItem["bw"] = ifaceDict['bw']
+ ifaceItem["model"] = ifaceDict['model']
+ ifaceItem["port_security"] = ifaceDict['port_security']
+ ifaceItem["floating_ip"] = ifaceDict['floating_ip']
+ created_time_iface = ifaceDict["created_time"]
+ #print "Iface name: %s" % iface['internal_name']
+ iface_id = self._new_row_internal('interfaces', ifaceItem, add_uuid=True, root_uuid=vnf_id, created_time=created_time_iface)
+ #print "Iface id in NFVO DB: %s" % iface_id
+
+ #print "Adding external interfaces to the NFVO database"
+ for iface in vnf_descriptor['vnf']['external-connections']:
+ myIfaceDict = {}
+ #myIfaceDict["internal_name"] = "%s-%s-%s" % (vnf_name,iface['VNFC'], iface['local_iface_name'])
+ myIfaceDict["internal_name"] = iface['local_iface_name']
+ #myIfaceDict["vm_id"] = vmDict["%s-%s" % (vnf_name,iface['VNFC'])]
+ myIfaceDict["vm_id"] = vmDict[iface['VNFC']]
+ myIfaceDict["external_name"] = iface['name']
+ myIfaceDict["type"] = iface['type']
+ if iface["type"] == "data":
+ myIfaceDict["vpci"] = dataifacesDict[ iface['VNFC'] ][ iface['local_iface_name'] ]['vpci']
+ myIfaceDict["bw"] = dataifacesDict[ iface['VNFC'] ][ iface['local_iface_name'] ]['bw']
+ myIfaceDict["model"] = dataifacesDict[ iface['VNFC'] ][ iface['local_iface_name'] ]['model']
+ created_time_iface = dataifacesDict[ iface['VNFC'] ][ iface['local_iface_name'] ]['created_time']
+ else:
+ myIfaceDict["vpci"] = bridgeInterfacesDict[ iface['VNFC'] ][ iface['local_iface_name'] ]['vpci']
+ myIfaceDict["bw"] = bridgeInterfacesDict[ iface['VNFC'] ][ iface['local_iface_name'] ]['bw']
+ myIfaceDict["model"] = bridgeInterfacesDict[ iface['VNFC'] ][ iface['local_iface_name'] ]['model']
+ myIfaceDict["mac"] = bridgeInterfacesDict[ iface['VNFC'] ][ iface['local_iface_name'] ]['mac']
+ myIfaceDict["port_security"] = \
+ bridgeInterfacesDict[iface['VNFC']][iface['local_iface_name']]['port_security']
+ myIfaceDict["floating_ip"] = \
+ bridgeInterfacesDict[iface['VNFC']][iface['local_iface_name']]['floating_ip']
+ created_time_iface = bridgeInterfacesDict[iface['VNFC']][iface['local_iface_name']]['created_time']
+ #print "Iface name: %s" % iface['name']
+ iface_id = self._new_row_internal('interfaces', myIfaceDict, add_uuid=True, root_uuid=vnf_id, created_time=created_time_iface)
+ #print "Iface id in NFVO DB: %s" % iface_id
+
+ return vnf_id
+