fix some more issues at SDN assist and deleting openstack ports
[osm/RO.git] / osm_ro / nfvo.py
index bd9d368..ce96910 100644 (file)
@@ -884,6 +884,11 @@ def new_vnfd_v3(mydb, tenant_id, vnf_descriptor):
                 net_id2uuid[vld.get("id")] = net_uuid
                 db_nets.append(db_net)
 
+            # connection points vaiable declaration
+            cp_name2iface_uuid = {}
+            cp_name2vm_uuid = {}
+            cp_name2db_interface = {}
+
             # table vms (vdus)
             vdu_id2uuid = {}
             vdu_id2db_table_index = {}
@@ -968,9 +973,6 @@ def new_vnfd_v3(mydb, tenant_id, vnf_descriptor):
 
                 # table interfaces (internal/external interfaces)
                 flavor_epa_interfaces = []
-                cp_name2iface_uuid = {}
-                cp_name2vm_uuid = {}
-                cp_name2db_interface = {}
                 vdu_id2cp_name = {}  # stored only when one external connection point is presented at this VDU
                 # for iface in chain(vdu.get("internal-interface").itervalues(), vdu.get("external-interface").itervalues()):
                 for iface in vdu.get("interface").itervalues():
@@ -1071,7 +1073,7 @@ def new_vnfd_v3(mydb, tenant_id, vnf_descriptor):
                     "ram": int(vdu["vm-flavor"].get("memory-mb", 1)),
                     "disk": int(vdu["vm-flavor"].get("storage-gb", 1)),
                 }
-                # EPA  TODO revise
+                # TODO revise the case of several numa-node-policy node
                 extended = {}
                 numa = {}
                 if devices:
@@ -1083,7 +1085,7 @@ def new_vnfd_v3(mydb, tenant_id, vnf_descriptor):
                     if vdu["guest-epa"].get("numa-node-policy"):  # TODO or dedicated_int:
                         numa_node_policy = vdu["guest-epa"].get("numa-node-policy")
                         if numa_node_policy.get("node"):
-                            numa_node = numa_node_policy["node"]['0']
+                            numa_node = numa_node_policy["node"].values()[0]
                             if numa_node.get("num-cores"):
                                 numa["cores"] = numa_node["num-cores"]
                                 epa_vcpu_set = True
@@ -4339,29 +4341,35 @@ def vim_action_create(mydb, tenant_id, datacenter, item, descriptor):
 
             #If the datacenter has a SDN controller defined and the network is of dataplane type, then create the sdn network
             if get_sdn_controller_id(mydb, datacenter) != None and (net_type == 'data' or net_type == 'ptp'):
+                #obtain datacenter_tenant_id
+                datacenter_tenant_id = mydb.get_rows(SELECT=('uuid',),
+                                                     FROM='datacenter_tenants',
+                                                     WHERE={'datacenter_id': datacenter})[0]['uuid']
                 try:
                     sdn_network = {}
                     sdn_network['vlan'] = net_vlan
                     sdn_network['type'] = net_type
                     sdn_network['name'] = net_name
+                    sdn_network['region'] = datacenter_tenant_id
                     ovim_content = ovim.new_network(sdn_network)
                 except ovimException as e:
-                    self.logger.error("ovimException creating SDN network={} ".format(
+                    logger.error("ovimException creating SDN network={} ".format(
                         sdn_network) + str(e), exc_info=True)
                     raise NfvoException("ovimException creating SDN network={} ".format(sdn_network) + str(e),
                                         HTTP_Internal_Server_Error)
 
                 # Save entry in in dabase mano_db in table instance_nets to stablish a dictionary  vim_net_id <->sdn_net_id
                 # use instance_scenario_id=None to distinguish from real instaces of nets
-                correspondence = {'instance_scenario_id': None, 'sdn_net_id': ovim_content, 'vim_net_id': content}
-                #obtain datacenter_tenant_id
-                correspondence['datacenter_tenant_id'] = mydb.get_rows(SELECT=('uuid',), FROM='datacenter_tenants', WHERE={'datacenter_id': datacenter})[0]['uuid']
-
+                correspondence = {'instance_scenario_id': None,
+                                  'sdn_net_id': ovim_content,
+                                  'vim_net_id': content,
+                                  'datacenter_tenant_id': datacenter_tenant_id
+                                  }
                 try:
                     mydb.new_row('instance_nets', correspondence, add_uuid=True)
                 except db_base_Exception as e:
-                    raise NfvoException("Error saving correspondence for VIM/SDN dataplane networks{}: ".format(correspondence) +
-                                        str(e), HTTP_Internal_Server_Error)
+                    raise NfvoException("Error saving correspondence for VIM/SDN dataplane networks{}: {}".format(
+                        correspondence, e), HTTP_Internal_Server_Error)
         elif item=="tenants":
             tenant = descriptor["tenant"]
             content = myvim.new_tenant(tenant["name"], tenant.get("description"))