__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
#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'])
#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'])
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"]
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'],
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
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
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
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]
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, v.mgmt_access"\
- " FROM instance_vnfs as iv join sce_vnfs as sv on iv.sce_vnf_id=sv.uuid join vnfs as v on iv.vnf_id=v.uuid" \
+ # 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 "\
+ " 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)
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"\