# -*- 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.
#
if scenario_dict["cloud_config"]:
scenario_dict["cloud-config"] = yaml.load(scenario_dict["cloud_config"])
del scenario_dict["cloud_config"]
- #sce_vnfs
+ # sce_vnfs
cmd = "SELECT uuid,name,member_vnf_index,vnf_id,description FROM sce_vnfs WHERE scenario_id='{}' "\
"ORDER BY created_at".format(scenario_dict['uuid'])
self.logger.debug(cmd)
vnf['mgmt_access'] = yaml.load(mgmt_access_dict[0]['mgmt_access'])
else:
vnf['mgmt_access'] = None
- #sce_interfaces
+ # 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"\
" WHERE scei.sce_vnf_id='{}' ORDER BY scei.created_at".format(vnf['uuid'])
self.logger.debug(cmd)
self.cur.execute(cmd)
vnf['interfaces'] = self.cur.fetchall()
- #vms
- cmd = "SELECT vms.uuid as uuid, flavor_id, image_id, vms.name as name," \
+ # 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.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"
vm["boot_data"] = yaml.safe_load(vm["boot_data"])
else:
del vm["boot_data"]
+ if vm["image_list"]:
+ vm["image_list"] = yaml.safe_load(vm["image_list"])
+ 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.logger.debug(cmd)
self.cur.execute(cmd)
vm['interfaces'] = self.cur.fetchall()
- for index in range(0,len(vm['interfaces'])):
- vm['interfaces'][index]['port-security'] = vm['interfaces'][index].pop("port_security")
- vm['interfaces'][index]['floating-ip'] = vm['interfaces'][index].pop("floating_ip")
+ for iface in vm['interfaces']:
+ iface['port-security'] = iface.pop("port_security")
+ iface['floating-ip'] = iface.pop("floating_ip")
+ for sce_interface in vnf["interfaces"]:
+ if sce_interface["interface_id"] == iface["uuid"]:
+ if sce_interface["ip_address"]:
+ iface["ip_address"] = sce_interface["ip_address"]
+ break
#nets every net of a vms
- cmd = "SELECT uuid,name,type,description FROM nets WHERE vnf_id='{}'".format(vnf['vnf_id'])
+ cmd = "SELECT uuid,name,type,description, osm_id FROM nets WHERE vnf_id='{}'".format(vnf['vnf_id'])
self.logger.debug(cmd)
self.cur.execute(cmd)
vnf['nets'] = self.cur.fetchall()
raise db_base.db_base_Exception("More than one ip-profile found with this criteria: net_id='{}'".format(vnf_net['uuid']), db_base.HTTP_Bad_Request)
#sce_nets
- cmd = "SELECT uuid,name,type,external,description" \
+ cmd = "SELECT uuid,name,type,external,description,vim_network_name, osm_id" \
" FROM sce_nets WHERE scenario_id='{}'" \
" ORDER BY created_at ".format(scenario_dict['uuid'])
self.logger.debug(cmd)
self.cur.execute(cmd)
rows = self.cur.fetchall()
if self.cur.rowcount==0:
- raise db_base.db_base_Exception("No scenario found where " + where_text, db_base.HTTP_Bad_Request)
+ raise db_base.db_base_Exception("No scenario found where " + where_text, db_base.HTTP_Not_Found)
elif self.cur.rowcount>1:
- raise db_base.db_base_Exception("More than one scenario found where " + where_text, db_base.HTTP_Bad_Request)
+ raise db_base.db_base_Exception("More than one scenario found where " + where_text, db_base.HTTP_Conflict)
scenario_uuid = rows[0]["uuid"]
scenario_name = rows[0]["name"]
def new_rows(self, tables, uuid_list=None):
"""
- Make a transactional insertion of rows at several tables
+ Make a transactional insertion of rows at several tables. Can be also a deletion
:param tables: list with dictionary where the keys are the table names and the values are a row or row list
with the values to be inserted at the table. Each row is a dictionary with the key values. E.g.:
tables = [
If tables does not contain the 'created_at', it is generated incrementally with the order of tables. You can
provide a integer value, that it is an index multiply by 0.00001 to add to the created time to manually set
up and order
+ If dict contains {"TO-DELETE": uuid} the entry is deleted if exist instead of inserted
:param uuid_list: list of created uuids, first one is the root (#TODO to store at uuid table)
:return: None if success, raise exception otherwise
"""
if isinstance(row_list, dict):
row_list = (row_list, ) #create a list with the single value
for row in row_list:
+ if "TO-DELETE" in row:
+ self._delete_row_by_id_internal(table_name, row["TO-DELETE"])
+ continue
+
if table_name in self.tables_with_created_field:
if "created_at" in row:
- created_time_param = created_time + row.pop("created_at")*0.00001
+ created_time_param = created_time + (index + row.pop("created_at"))*0.00001
else:
created_time_param = created_time + index*0.00001
- index += 1
+ index += 1
else:
created_time_param = 0
self._new_row_internal(table_name, row, add_uuid=False, root_uuid=None,
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" \
+ " ,inst.cloud_config as cloud_config, s.osm_id as nsd_osm_id" \
" FROM instance_scenarios as inst left join scenarios as s on inst.scenario_id=s.uuid" \
" WHERE " + where_text
self.logger.debug(cmd)
# instance_vnfs
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, sv.member_vnf_index "\
- " 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'])
+ ", datacenter_tenant_id, v.mgmt_access, sv.member_vnf_index, v.osm_id as vnfd_osm_id "\
+ "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)
self.cur.execute(cmd)
instance_dict['vnfs'] = self.cur.fetchall()
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"\
+ vnf["ip_address"] = None
+ vnf_mgmt_access_iface = None
+ vnf_mgmt_access_vm = None
+ if vnf["mgmt_access"]:
+ vnf_mgmt_access = yaml.load(vnf["mgmt_access"])
+ vnf_mgmt_access_iface = vnf_mgmt_access.get("interface_id")
+ vnf_mgmt_access_vm = vnf_mgmt_access.get("vm_id")
+ vnf["ip_address"] = vnf_mgmt_access.get("ip-address")
+
+ # instance vms
+ cmd = "SELECT iv.uuid as uuid, vim_vm_id, status, error_msg, vim_info, iv.created_at as "\
+ "created_at, name, vms.osm_id as vdu_osm_id, vim_name, vms.uuid as vm_uuid"\
" 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)
vm_manage_iface_list=[]
# 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"\
+ " ii.ip_address as ip_address, vim_info, i.type as type, sdn_port_id, i.uuid"\
" FROM instance_interfaces as ii join interfaces as i on ii.interface_id=i.uuid"\
" WHERE instance_vm_id='{}' ORDER BY created_at".format(vm['uuid'])
self.logger.debug(cmd)
self.cur.execute(cmd )
vm['interfaces'] = self.cur.fetchall()
for iface in vm['interfaces']:
+ if vnf_mgmt_access_iface and vnf_mgmt_access_iface == iface["uuid"]:
+ if not vnf["ip_address"]:
+ vnf["ip_address"] = iface["ip_address"]
if iface["type"] == "mgmt" and iface["ip_address"]:
- vnf_manage_iface_list.append(iface["ip_address"])
vm_manage_iface_list.append(iface["ip_address"])
if not verbose:
del iface["type"]
- if vm_manage_iface_list: vm["ip_address"] = ",".join(vm_manage_iface_list)
- if vnf_manage_iface_list: vnf["ip_address"] = ",".join(vnf_manage_iface_list)
-
+ del iface["uuid"]
+ if vm_manage_iface_list:
+ vm["ip_address"] = ",".join(vm_manage_iface_list)
+ if not vnf["ip_address"] and vnf_mgmt_access_vm == vm["vm_uuid"]:
+ vnf["ip_address"] = vm["ip_address"]
+ del vm["vm_uuid"]
+
#instance_nets
#select_text = "instance_nets.uuid as uuid,sce_nets.name as net_name,instance_nets.vim_net_id as net_id,instance_nets.status as status,instance_nets.external as external"
#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()