X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_ro%2Fnfvo_db.py;h=bad7cec2248fa86753571bc2a440f1f10c51ccf1;hb=0ea9b0f0cbd4c5567289c4c80c73de94901d7047;hp=b1224436441acbd3ea0ec340464649f62555a1ef;hpb=0446cd5df24c38f95cea13b995c553e9b2403f21;p=osm%2FRO.git diff --git a/osm_ro/nfvo_db.py b/osm_ro/nfvo_db.py index b1224436..bad7cec2 100644 --- a/osm_ro/nfvo_db.py +++ b/osm_ro/nfvo_db.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ## -# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U. +# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U. # This file is part of openmano # All Rights Reserved. # @@ -21,9 +21,9 @@ # contact with: nfvlabs@tid.es ## -''' +""" NFVO DB engine. It implements all the methods to interact with the Openmano Database -''' +""" __author__="Alfonso Tierno, Gerardo Garcia, Pablo Montes" __date__ ="$28-aug-2014 10:05:01$" @@ -612,7 +612,7 @@ class nfvo_db(db_base.db_base): # vms cmd = "SELECT vms.uuid as uuid, flavor_id, image_id, image_list, vms.name as name," \ " vms.description as description, vms.boot_data as boot_data, count," \ - " vms.availability_zone as availability_zone, vms.osm_id as osm_id" \ + " vms.availability_zone as availability_zone, vms.osm_id as osm_id, vms.pdu_type" \ " FROM vnfs join vms on vnfs.uuid=vms.vnf_id" \ " WHERE vnfs.uuid='" + vnf['vnf_id'] + "'" \ " ORDER BY vms.created_at" @@ -629,18 +629,22 @@ class nfvo_db(db_base.db_base): else: del vm["image_list"] if datacenter_vim_id!=None: - cmd = "SELECT vim_id FROM datacenters_images WHERE image_id='{}' AND datacenter_vim_id='{}'".format(vm['image_id'],datacenter_vim_id) - self.logger.debug(cmd) - self.cur.execute(cmd) - if self.cur.rowcount==1: - vim_image_dict = self.cur.fetchone() - vm['vim_image_id']=vim_image_dict['vim_id'] - cmd = "SELECT vim_id FROM datacenters_flavors WHERE flavor_id='{}' AND datacenter_vim_id='{}'".format(vm['flavor_id'],datacenter_vim_id) - self.logger.debug(cmd) - self.cur.execute(cmd) - if self.cur.rowcount==1: - vim_flavor_dict = self.cur.fetchone() - vm['vim_flavor_id']=vim_flavor_dict['vim_id'] + if vm['image_id']: + cmd = "SELECT vim_id FROM datacenters_images WHERE image_id='{}' AND " \ + "datacenter_vim_id='{}'".format(vm['image_id'], datacenter_vim_id) + self.logger.debug(cmd) + self.cur.execute(cmd) + if self.cur.rowcount==1: + vim_image_dict = self.cur.fetchone() + vm['vim_image_id']=vim_image_dict['vim_id'] + if vm['flavor_id']: + cmd = "SELECT vim_id FROM datacenters_flavors WHERE flavor_id='{}' AND " \ + "datacenter_vim_id='{}'".format(vm['flavor_id'], datacenter_vim_id) + self.logger.debug(cmd) + self.cur.execute(cmd) + if self.cur.rowcount==1: + vim_flavor_dict = self.cur.fetchone() + vm['vim_flavor_id']=vim_flavor_dict['vim_id'] #interfaces cmd = "SELECT uuid,internal_name,external_name,net_id,type,vpci,mac,bw,model,ip_address," \ @@ -724,7 +728,8 @@ class nfvo_db(db_base.db_base): self.cur.execute(cmd) vnffg['rsps'] = self.cur.fetchall() for rsp in vnffg['rsps']: - cmd = "SELECT uuid,if_order,interface_id,sce_vnf_id FROM sce_rsp_hops WHERE sce_rsp_id='{}' "\ + cmd = "SELECT uuid,if_order,ingress_interface_id,egress_interface_id,sce_vnf_id " \ + "FROM sce_rsp_hops WHERE sce_rsp_id='{}' "\ "ORDER BY created_at".format(rsp['uuid']) self.logger.debug(cmd) self.cur.execute(cmd) @@ -997,7 +1002,7 @@ class nfvo_db(db_base.db_base): self.cur.execute(cmd) instance_dict['vnfs'] = self.cur.fetchall() for vnf in instance_dict['vnfs']: - + vnf["ip_address"] = None vnf_mgmt_access_iface = None vnf_mgmt_access_vm = None if vnf["mgmt_access"]: @@ -1026,7 +1031,8 @@ class nfvo_db(db_base.db_base): vm['interfaces'] = self.cur.fetchall() for iface in vm['interfaces']: if vnf_mgmt_access_iface and vnf_mgmt_access_iface == iface["uuid"]: - vnf["ip_address"] = iface["ip_address"] + if not vnf["ip_address"]: + vnf["ip_address"] = iface["ip_address"] if iface["type"] == "mgmt" and iface["ip_address"]: vm_manage_iface_list.append(iface["ip_address"]) if not verbose: @@ -1034,9 +1040,7 @@ class nfvo_db(db_base.db_base): del iface["uuid"] if vm_manage_iface_list: vm["ip_address"] = ",".join(vm_manage_iface_list) - if vnf_mgmt_access_vm == vm["vm_uuid"]: - vnf["ip_address"] = vm["ip_address"] - elif not vnf.get("ip_address"): + if not vnf["ip_address"] and vnf_mgmt_access_vm == vm["vm_uuid"]: vnf["ip_address"] = vm["ip_address"] del vm["vm_uuid"] @@ -1045,9 +1049,12 @@ class nfvo_db(db_base.db_base): #from_text = "instance_nets join instance_scenarios on instance_nets.instance_scenario_id=instance_scenarios.uuid " + \ # "join sce_nets on instance_scenarios.scenario_id=sce_nets.scenario_id" #where_text = "instance_nets.instance_scenario_id='"+ instance_dict['uuid'] + "'" - cmd = "SELECT uuid,vim_net_id,status,error_msg,vim_info,created, sce_net_id, net_id as vnf_net_id, datacenter_id, datacenter_tenant_id, sdn_net_id"\ - " FROM instance_nets" \ - " WHERE instance_scenario_id='{}' ORDER BY created_at".format(instance_dict['uuid']) + cmd = "SELECT inets.uuid as uuid,vim_net_id,status,error_msg,vim_info,created, sce_net_id, " \ + "net_id as vnf_net_id, datacenter_id, datacenter_tenant_id, sdn_net_id, " \ + "snets.osm_id as ns_net_osm_id, nets.osm_id as vnf_net_osm_id, inets.vim_name " \ + "FROM instance_nets as inets left join sce_nets as snets on inets.sce_net_id=snets.uuid " \ + "left join nets on inets.net_id=nets.uuid " \ + "WHERE instance_scenario_id='{}' ORDER BY inets.created_at".format(instance_dict['uuid']) self.logger.debug(cmd) self.cur.execute(cmd) instance_dict['nets'] = self.cur.fetchall()