X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_ro%2Fnfvo_db.py;h=25196dde2881d482163c52e08f075cccf3a1aee4;hb=c4629bd3b12d44dd568240735f8cc546475170a3;hp=cb345e5f03d99a747570c5086c07280dc889b47e;hpb=868220c566cfd302a38f9a45a75f4dbd4ebbf395;p=osm%2FRO.git diff --git a/osm_ro/nfvo_db.py b/osm_ro/nfvo_db.py index cb345e5f..25196dde 100644 --- a/osm_ro/nfvo_db.py +++ b/osm_ro/nfvo_db.py @@ -27,7 +27,7 @@ NFVO DB engine. It implements all the methods to interact with the Openmano Data __author__="Alfonso Tierno, Gerardo Garcia, Pablo Montes" __date__ ="$28-aug-2014 10:05:01$" -import db_base +from . import db_base import MySQLdb as mdb import json import yaml @@ -66,7 +66,7 @@ class nfvo_db(db_base.db_base): #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(): + for _,vm in VNFCDict.items(): #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']) @@ -213,12 +213,12 @@ class nfvo_db(db_base.db_base): 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(): + for _,vm in VNFCDict.items(): #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']) @@ -389,7 +389,7 @@ class nfvo_db(db_base.db_base): scenario_uuid = self._new_row_internal('scenarios', INSERT_, add_uuid=True, root_uuid=None, created_time=created_time) #sce_nets - for net in scenario_dict['nets'].values(): + for net in list(scenario_dict['nets'].values()): net_dict={'scenario_id': scenario_uuid} net_dict["name"] = net["name"] net_dict["type"] = net["type"] @@ -418,7 +418,7 @@ class nfvo_db(db_base.db_base): self._new_row_internal('ip_profiles', myIPProfileDict) # sce_vnfs - for k, vnf in scenario_dict['vnfs'].items(): + for k, vnf in list(scenario_dict['vnfs'].items()): INSERT_ = {'scenario_id': scenario_uuid, 'name': k, 'vnf_id': vnf['uuid'], @@ -433,7 +433,7 @@ class nfvo_db(db_base.db_base): root_uuid=scenario_uuid, created_time=created_time) vnf['scn_vnf_uuid']=scn_vnf_uuid # sce_interfaces - for iface in vnf['ifaces'].values(): + for iface in list(vnf['ifaces'].values()): # print 'iface', iface if 'net_key' not in iface: continue @@ -488,7 +488,7 @@ class nfvo_db(db_base.db_base): WHERE_={'tenant_id': tenant_id, 'uuid': scenario_uuid} item_changed += self._update_rows('scenarios', UPDATE_, WHERE_, modified_time=modified_time) #sce_nets - for node_id, node in nodes.items(): + for node_id, node in list(nodes.items()): if "graph" in node: #node["graph"] = yaml.safe_dump(node["graph"],default_flow_style=True,width=256) #TODO, must be json because of the GUI, change to yaml @@ -586,7 +586,16 @@ class nfvo_db(db_base.db_base): self.logger.debug(cmd) self.cur.execute(cmd) scenario_dict['vnfs'] = self.cur.fetchall() + for vnf in scenario_dict['vnfs']: + cmd = "SELECT mgmt_access FROM vnfs WHERE uuid='{}'".format(scenario_dict['vnfs'][0]['vnf_id']) + self.logger.debug(cmd) + self.cur.execute(cmd) + mgmt_access_dict = self.cur.fetchall() + if mgmt_access_dict[0].get('mgmt_access'): + vnf['mgmt_access'] = yaml.load(mgmt_access_dict[0]['mgmt_access']) + else: + vnf['mgmt_access'] = None #sce_interfaces cmd = "SELECT scei.uuid,scei.sce_net_id,scei.interface_id,i.external_name,scei.ip_address"\ " FROM sce_interfaces as scei join interfaces as i on scei.interface_id=i.uuid"\ @@ -721,7 +730,7 @@ class nfvo_db(db_base.db_base): cmd = "DELETE FROM scenarios WHERE uuid='{}'".format(scenario_uuid) self.logger.debug(cmd) self.cur.execute(cmd) - + return scenario_uuid + " " + scenario_name except (mdb.Error, AttributeError) as e: self._format_error(e, tries, "delete", "instances running") @@ -750,7 +759,7 @@ class nfvo_db(db_base.db_base): with self.con: self.cur = self.con.cursor() for table in tables: - for table_name, row_list in table.items(): + for table_name, row_list in list(table.items()): index = 0 if isinstance(row_list, dict): row_list = (row_list, ) #create a list with the single value @@ -801,7 +810,7 @@ class nfvo_db(db_base.db_base): net["vim_id_sites"]["datacenter_site_id"] = {datacenter_site_id: net['vim_id']} sce_net_id = net.get("uuid") - for datacenter_site_id,vim_id in net["vim_id_sites"].iteritems(): + for datacenter_site_id,vim_id in net["vim_id_sites"].items(): INSERT_={'vim_net_id': vim_id, 'created': net.get('created', False), 'instance_scenario_id':instance_uuid } #, 'type': net['type'] INSERT_['datacenter_id'] = datacenter_site_id INSERT_['datacenter_tenant_id'] = scenarioDict["datacenter2tenant"][datacenter_site_id] @@ -897,35 +906,39 @@ class nfvo_db(db_base.db_base): with self.con: self.cur = self.con.cursor(mdb.cursors.DictCursor) # instance table - where_list=[] - if tenant_id is not None: where_list.append( "inst.tenant_id='" + tenant_id +"'" ) + where_list = [] + if tenant_id: + where_list.append("inst.tenant_id='{}'".format(tenant_id)) if db_base._check_valid_uuid(instance_id): - where_list.append( "inst.uuid='" + instance_id +"'" ) + where_list.append("inst.uuid='{}'".format(instance_id)) else: - where_list.append( "inst.name='" + instance_id +"'" ) + where_list.append("inst.name='{}'".format(instance_id)) where_text = " AND ".join(where_list) - cmd = "SELECT inst.uuid as uuid,inst.name as name,inst.scenario_id as scenario_id, datacenter_id" +\ - " ,datacenter_tenant_id, s.name as scenario_name,inst.tenant_id as tenant_id" + \ - " ,inst.description as description,inst.created_at as created_at" +\ - " ,inst.cloud_config as 'cloud_config'" +\ - " FROM instance_scenarios as inst join scenarios as s on inst.scenario_id=s.uuid"+\ + cmd = "SELECT inst.uuid as uuid, inst.name as name, inst.scenario_id as scenario_id, datacenter_id"\ + " ,datacenter_tenant_id, s.name as scenario_name,inst.tenant_id as tenant_id" \ + " ,inst.description as description, inst.created_at as created_at" \ + " ,inst.cloud_config as cloud_config" \ + " FROM instance_scenarios as inst left join scenarios as s on inst.scenario_id=s.uuid" \ " WHERE " + where_text self.logger.debug(cmd) self.cur.execute(cmd) rows = self.cur.fetchall() - if self.cur.rowcount==0: + if self.cur.rowcount == 0: raise db_base.db_base_Exception("No instance found where " + where_text, db_base.HTTP_Not_Found) - elif self.cur.rowcount>1: - raise db_base.db_base_Exception("More than one instance found where " + where_text, db_base.HTTP_Bad_Request) + elif self.cur.rowcount > 1: + raise db_base.db_base_Exception("More than one instance found where " + where_text, + db_base.HTTP_Bad_Request) instance_dict = rows[0] if instance_dict["cloud_config"]: instance_dict["cloud-config"] = yaml.load(instance_dict["cloud_config"]) del instance_dict["cloud_config"] # instance_vnfs - cmd = "SELECT iv.uuid as uuid,sv.vnf_id as vnf_id,sv.name as vnf_name, sce_vnf_id, datacenter_id, datacenter_tenant_id"\ - " FROM instance_vnfs as iv join sce_vnfs as sv on iv.sce_vnf_id=sv.uuid" \ + cmd = "SELECT iv.uuid as uuid, iv.vnf_id as vnf_id, sv.name as vnf_name, sce_vnf_id, datacenter_id"\ + " ,datacenter_tenant_id, v.mgmt_access "\ + " FROM instance_vnfs as iv left join sce_vnfs as sv "\ + "on iv.sce_vnf_id=sv.uuid join vnfs as v on iv.vnf_id=v.uuid" \ " WHERE iv.instance_scenario_id='{}'" \ " ORDER BY iv.created_at ".format(instance_dict['uuid']) self.logger.debug(cmd) @@ -934,7 +947,7 @@ class nfvo_db(db_base.db_base): for vnf in instance_dict['vnfs']: vnf_manage_iface_list=[] #instance vms - cmd = "SELECT iv.uuid as uuid, vim_vm_id, status, error_msg, vim_info, iv.created_at as created_at, name "\ + cmd = "SELECT iv.uuid as uuid, vim_vm_id, status, error_msg, vim_info, iv.created_at as created_at, name"\ " FROM instance_vms as iv join vms on iv.vm_id=vms.uuid "\ " WHERE instance_vnf_id='{}' ORDER BY iv.created_at".format(vnf['uuid']) self.logger.debug(cmd) @@ -942,7 +955,7 @@ class nfvo_db(db_base.db_base): vnf['vms'] = self.cur.fetchall() for vm in vnf['vms']: vm_manage_iface_list=[] - #instance_interfaces + # instance_interfaces cmd = "SELECT vim_interface_id, instance_net_id, internal_name,external_name, mac_address,"\ " ii.ip_address as ip_address, vim_info, i.type as type, sdn_port_id"\ " FROM instance_interfaces as ii join interfaces as i on ii.interface_id=i.uuid"\