From 8e690329e2c9e8bcbb7d3501037e3de1fbb7b942 Mon Sep 17 00:00:00 2001 From: tierno Date: Thu, 10 Aug 2017 15:58:50 +0200 Subject: [PATCH] (bug 329) fix RO VDU count. Enhance nfvo.py:create_instance Change-Id: I588268281fd6fd85d963db3fdcc5b39e809bc5f0 Signed-off-by: tierno --- database_utils/migrate_mano_db.sh | 19 +- openmanod | 4 +- osm_ro/db_base.py | 26 +- osm_ro/nfvo.py | 231 +++++++++++++++--- osm_ro/nfvo_db.py | 48 +++- osm_ro/openmano_schemas.py | 5 +- .../simple_count3/scenario_linux_count3.yaml | 39 +++ test/RO_tests/simple_count3/vnfd_count3.yaml | 68 ++++++ vnfs/vnf-template.yaml | 1 + 9 files changed, 391 insertions(+), 50 deletions(-) create mode 100644 test/RO_tests/simple_count3/scenario_linux_count3.yaml create mode 100644 test/RO_tests/simple_count3/vnfd_count3.yaml diff --git a/database_utils/migrate_mano_db.sh b/database_utils/migrate_mano_db.sh index 68727c02..d99203e7 100755 --- a/database_utils/migrate_mano_db.sh +++ b/database_utils/migrate_mano_db.sh @@ -33,7 +33,7 @@ DBPORT="3306" DBNAME="mano_db" QUIET_MODE="" #TODO update it with the last database version -LAST_DB_VERSION=23 +LAST_DB_VERSION=24 # Detect paths MYSQL=$(which mysql) @@ -191,6 +191,7 @@ fi #[ $OPENMANO_VER_NUM -ge 5015 ] && DB_VERSION=21 #0.5.15 => 21 #[ $OPENMANO_VER_NUM -ge 5016 ] && DB_VERSION=22 #0.5.16 => 22 #[ $OPENMANO_VER_NUM -ge 5020 ] && DB_VERSION=23 #0.5.20 => 23 +#[ $OPENMANO_VER_NUM -ge 5021 ] && DB_VERSION=24 #0.5.21 => 24 #TODO ... put next versions here function upgrade_to_1(){ @@ -800,6 +801,22 @@ function downgrade_from_23(){ echo "DELETE FROM schema_version WHERE version_int='23';" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 } +function upgrade_to_24(){ + # echo " upgrade database from version 0.23 to version 0.24" + echo " Add 'count' to table 'vms'" + echo "ALTER TABLE vms ADD COLUMN count SMALLINT NOT NULL DEFAULT '1' AFTER vnf_id;" | $DBCMD || + ! echo "ERROR. Aborted!" || exit -1 + echo "INSERT INTO schema_version (version_int, version, openmano_ver, comments, date) "\ + "VALUES (24, '0.24', '0.5.21', 'Added vnfd fields', '2017-08-29');" | $DBCMD || + ! echo "ERROR. Aborted!" || exit -1 +} +function downgrade_from_24(){ + # echo " downgrade database from version 0.24 to version 0.23" + echo " Remove 'count' from table 'vms'" + echo "ALTER TABLE vms DROP COLUMN count;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 + echo "DELETE FROM schema_version WHERE version_int='24';" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 +} + function upgrade_to_X(){ echo " change 'datacenter_nets'" echo "ALTER TABLE datacenter_nets ADD COLUMN vim_tenant_id VARCHAR(36) NOT NULL AFTER datacenter_id, DROP INDEX name_datacenter_id, ADD UNIQUE INDEX name_datacenter_id (name, datacenter_id, vim_tenant_id);" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 diff --git a/openmanod b/openmanod index 8d17f389..94924bd7 100755 --- a/openmanod +++ b/openmanod @@ -48,9 +48,9 @@ import osm_ro __author__ = "Alfonso Tierno, Gerardo Garcia, Pablo Montes" __date__ = "$26-aug-2014 11:09:29$" -__version__ = "0.5.20-r529" +__version__ = "0.5.21-r531" version_date = "Aug 2017" -database_version = 23 # expected database schema version +database_version = 24 # expected database schema version global global_config global logger diff --git a/osm_ro/db_base.py b/osm_ro/db_base.py index 4a877213..26e4c002 100644 --- a/osm_ro/db_base.py +++ b/osm_ro/db_base.py @@ -336,7 +336,31 @@ class db_base(): self.logger.debug(cmd) self.cur.execute(cmd) return self.cur.rowcount - + + def _new_uuid(self, root_uuid=None, used_table=None, created_time=0): + """ + Generate a new uuid. It DOES NOT begin or end the transaction, so self.con.cursor must be created + :param root_uuid: master uuid of the transaction + :param used_table: the table this uuid is intended for + :param created_time: time of creation + :return: the created uuid + """ + + uuid = str(myUuid.uuid1()) + # defining root_uuid if not provided + if root_uuid is None: + root_uuid = uuid + if created_time: + created_at = created_time + else: + created_at = time.time() + # inserting new uuid + cmd = "INSERT INTO uuids (uuid, root_uuid, used_at, created_at) VALUES ('{:s}','{:s}','{:s}', {:f})".format( + uuid, root_uuid, used_table, created_at) + self.logger.debug(cmd) + self.cur.execute(cmd) + return uuid + def _new_row_internal(self, table, INSERT, add_uuid=False, root_uuid=None, created_time=0): ''' Add one row into a table. It DOES NOT begin or end the transaction, so self.con.cursor must be created Attribute diff --git a/osm_ro/nfvo.py b/osm_ro/nfvo.py index 9cd39950..f93e5514 100644 --- a/osm_ro/nfvo.py +++ b/osm_ro/nfvo.py @@ -38,6 +38,7 @@ import console_proxy_thread as cli import vimconn import logging import collections +from uuid import uuid4 from db_base import db_base_Exception import nfvo_db @@ -830,6 +831,7 @@ def new_vnf(mydb, tenant_id, vnf_descriptor): #print "Image id for VNFC %s: %s" % (vnfc['name'],image_id) VNFCDict[vnfc['name']]["image_id"] = image_id VNFCDict[vnfc['name']]["image_path"] = vnfc.get('VNFC image') + VNFCDict[vnfc['name']]["count"] = vnfc.get('count', 1) if vnfc.get("boot-data"): VNFCDict[vnfc['name']]["boot_data"] = yaml.safe_dump(vnfc["boot-data"], default_flow_style=True, width=256) @@ -965,6 +967,7 @@ def new_vnf_v02(mydb, tenant_id, vnf_descriptor): #print "Image id for VNFC %s: %s" % (vnfc['name'],image_id) VNFCDict[vnfc['name']]["image_id"] = image_id VNFCDict[vnfc['name']]["image_path"] = vnfc.get('VNFC image') + VNFCDict[vnfc['name']]["count"] = vnfc.get('count', 1) if vnfc.get("boot-data"): VNFCDict[vnfc['name']]["boot_data"] = yaml.safe_dump(vnfc["boot-data"], default_flow_style=True, width=256) @@ -2002,14 +2005,30 @@ def create_instance(mydb, tenant_id, instance_dict): #logger.debug(">>>>>>> InstanceDict:\n{}".format(yaml.safe_dump(instance_dict,default_flow_style=False, width=256))) #logger.debug(">>>>>>> ScenarioDict:\n{}".format(yaml.safe_dump(scenarioDict,default_flow_style=False, width=256))) - scenarioDict['datacenter_id'] = default_datacenter_id + uuid_list = [] + instance_name = instance_dict["name"] + instance_uuid = str(uuid4()) + uuid_list.append(instance_uuid) + db_instance_scenario = { + "uuid": instance_uuid, + "name": instance_name, + "tenant_id": tenant_id, + "scenario_id": scenarioDict['uuid'], + "datacenter_id": default_datacenter_id, + # filled bellow 'datacenter_tenant_id' + "description": instance_dict.get("description"), + } + db_ip_profiles=[] + if scenarioDict.get("cloud-config"): + db_instance_scenario["cloud_config"] = yaml.safe_dump(scenarioDict["cloud-config"], + default_flow_style=True, width=256) + vnf_net2instance = {} #Auxiliar dictionary. First key:'scenario' or sce_vnf uuid. Second Key: uuid of the net/sce_net. Value: vim_net_id + sce_net2instance = {} auxNetDict = {} #Auxiliar dictionary. First key:'scenario' or sce_vnf uuid. Second Key: uuid of the net/sce_net. Value: vim_net_id auxNetDict['scenario'] = {} logger.debug("Creating instance from scenario-dict:\n%s", yaml.safe_dump(scenarioDict, indent=4, default_flow_style=False)) #TODO remove - instance_name = instance_dict["name"] - instance_description = instance_dict.get("description") try: # 0 check correct parameters for net_name, net_instance_desc in instance_dict.get("networks",{}).iteritems(): @@ -2093,12 +2112,12 @@ def create_instance(mydb, tenant_id, instance_dict): #logger.debug(">>>>>>>> Merged dictionary") logger.debug("Creating instance scenario-dict MERGED:\n%s", yaml.safe_dump(scenarioDict, indent=4, default_flow_style=False)) - # 1. Creating new nets (sce_nets) in the VIM" + db_instance_nets = [] for sce_net in scenarioDict['nets']: - sce_net["vim_id_sites"]={} - descriptor_net = instance_dict.get("networks",{}).get(sce_net["name"],{}) + descriptor_net = instance_dict.get("networks",{}).get(sce_net["name"],{}) net_name = descriptor_net.get("vim-network-name") + sce_net2instance[sce_net['uuid']] = {} auxNetDict['scenario'][sce_net['uuid']] = {} sites = descriptor_net.get("sites", [ {} ]) @@ -2163,7 +2182,7 @@ def create_instance(mydb, tenant_id, instance_dict): if not create_network: raise NfvoException("No candidate VIM network found for " + filter_text, HTTP_Bad_Request ) else: - sce_net["vim_id_sites"][datacenter_id] = vim_nets[0]['id'] + vim_id = vim_nets[0]['id'] auxNetDict['scenario'][sce_net['uuid']][datacenter_id] = vim_nets[0]['id'] create_network = False if create_network: @@ -2173,11 +2192,39 @@ def create_instance(mydb, tenant_id, instance_dict): instance_tasks[task_id] = task tasks_to_launch[myvim_thread_id].append(task) #network_id = vim.new_network(net_vim_name, net_type, sce_net.get('ip_profile',None)) - sce_net["vim_id_sites"][datacenter_id] = task_id + vim_id = task_id auxNetDict['scenario'][sce_net['uuid']][datacenter_id] = task_id rollbackList.append({'what':'network', 'where':'vim', 'vim_id':datacenter_id, 'uuid':task_id}) sce_net["created"] = True + # fill database content + net_uuid = str(uuid4()) + uuid_list.append(net_uuid) + sce_net2instance[sce_net['uuid']][datacenter_id] = net_uuid + db_net = { + "uuid": net_uuid, + 'vim_net_id': vim_id, + "instance_scenario_id": instance_uuid, + "sce_net_id": sce_net["uuid"], + "created": create_network, + 'datacenter_id': datacenter_id, + 'datacenter_tenant_id': myvim_thread_id, + 'status': 'BUILD' if create_network else "ACTIVE" + } + db_instance_nets.append(db_net) + if 'ip_profile' in sce_net: + db_ip_profile={ + 'instance_net_id': net_uuid, + 'ip_version': sce_net['ip_profile']['ip_version'], + 'subnet_address': sce_net['ip_profile']['subnet_address'], + 'gateway_address': sce_net['ip_profile']['gateway_address'], + 'dns_address': sce_net['ip_profile']['dns_address'], + 'dhcp_enabled': sce_net['ip_profile']['dhcp_enabled'], + 'dhcp_start_address': sce_net['ip_profile']['dhcp_start_address'], + 'dhcp_count': sce_net['ip_profile']['dhcp_count'], + } + db_ip_profiles.append(db_ip_profile) + # 2. Creating new nets (vnf internal nets) in the VIM" # For each vnf net, we create it and we add it to instanceNetlist. for sce_vnf in scenarioDict['vnfs']: @@ -2201,19 +2248,51 @@ def create_instance(mydb, tenant_id, instance_dict): instance_tasks[task_id] = task tasks_to_launch[myvim_thread_id].append(task) # network_id = vim.new_network(net_name, net_type, net.get('ip_profile',None)) - net['vim_id'] = task_id + vim_id = task_id + if sce_vnf['uuid'] not in vnf_net2instance: + vnf_net2instance[sce_vnf['uuid']] = {} + vnf_net2instance[sce_vnf['uuid']][net['uuid']] = task_id if sce_vnf['uuid'] not in auxNetDict: auxNetDict[sce_vnf['uuid']] = {} auxNetDict[sce_vnf['uuid']][net['uuid']] = task_id rollbackList.append({'what':'network','where':'vim','vim_id':datacenter_id,'uuid':task_id}) net["created"] = True - #print "auxNetDict:" - #print yaml.safe_dump(auxNetDict, indent=4, default_flow_style=False) + # fill database content + net_uuid = str(uuid4()) + uuid_list.append(net_uuid) + vnf_net2instance[sce_vnf['uuid']][net['uuid']] = net_uuid + db_net = { + "uuid": net_uuid, + 'vim_net_id': vim_id, + "instance_scenario_id": instance_uuid, + "net_id": net["uuid"], + "created": True, + 'datacenter_id': datacenter_id, + 'datacenter_tenant_id': myvim_thread_id, + } + db_instance_nets.append(db_net) + if 'ip_profile' in net: + db_ip_profile = { + 'instance_net_id': net_uuid, + 'ip_version': net['ip_profile']['ip_version'], + 'subnet_address': net['ip_profile']['subnet_address'], + 'gateway_address': net['ip_profile']['gateway_address'], + 'dns_address': net['ip_profile']['dns_address'], + 'dhcp_enabled': net['ip_profile']['dhcp_enabled'], + 'dhcp_start_address': net['ip_profile']['dhcp_start_address'], + 'dhcp_count': net['ip_profile']['dhcp_count'], + } + db_ip_profiles.append(db_ip_profile) + + #print "vnf_net2instance:" + #print yaml.safe_dump(vnf_net2instance, indent=4, default_flow_style=False) # 3. Creating new vm instances in the VIM + db_instance_vnfs = [] + db_instance_vms = [] + db_instance_interfaces = [] #myvim.new_vminstance(self,vimURI,tenant_id,name,description,image_id,flavor_id,net_dict) - sce_vnf_list = sorted(scenarioDict['vnfs'], key=lambda k: k['name']) #for sce_vnf in scenarioDict['vnfs']: for sce_vnf in sce_vnf_list: @@ -2239,10 +2318,21 @@ def create_instance(mydb, tenant_id, instance_dict): sce_vnf["datacenter_id"] = datacenter_id i = 0 + vnf_uuid = str(uuid4()) + uuid_list.append(vnf_uuid) + db_instance_vnf = { + 'uuid': vnf_uuid, + 'instance_scenario_id': instance_uuid, + 'vnf_id': sce_vnf['vnf_id'], + 'sce_vnf_id': sce_vnf['uuid'], + 'datacenter_id': datacenter_id, + 'datacenter_tenant_id': myvim_thread_id, + } + db_instance_vnfs.append(db_instance_vnf) + for vm in sce_vnf['vms']: - i += 1 myVMDict = {} - myVMDict['name'] = "{}.{}.{}".format(instance_name,sce_vnf['name'],chr(96+i)) + myVMDict['name'] = "{}.{}.{}".format(instance_name[:64], sce_vnf['name'][:64], vm["name"][:64]) myVMDict['description'] = myVMDict['name'][0:99] # if not startvms: # myVMDict['start'] = "no" @@ -2279,6 +2369,7 @@ def create_instance(mydb, tenant_id, instance_dict): myVMDict['networks'] = [] task_depends = {} #TODO ALF. connect_mgmt_interfaces. Connect management interfaces if this is true + db_vm_ifaces = [] for iface in vm['interfaces']: netDict = {} if iface['type']=="data": @@ -2325,54 +2416,114 @@ def create_instance(mydb, tenant_id, instance_dict): #print vnf_iface if vnf_iface['interface_id']==iface['uuid']: netDict['net_id'] = auxNetDict['scenario'][ vnf_iface['sce_net_id'] ][datacenter_id] + instance_net_id = sce_net2instance[ vnf_iface['sce_net_id'] ][datacenter_id] break else: netDict['net_id'] = auxNetDict[ sce_vnf['uuid'] ][ iface['net_id'] ] + instance_net_id = vnf_net2instance[ sce_vnf['uuid'] ][ iface['net_id'] ] if netDict.get('net_id') and is_task_id(netDict['net_id']): task_depends[netDict['net_id']] = instance_tasks[netDict['net_id']] #skip bridge ifaces not connected to any net #if 'net_id' not in netDict or netDict['net_id']==None: # continue myVMDict['networks'].append(netDict) - #print ">>>>>>>>>>>>>>>>>>>>>>>>>>>" - #print myVMDict['name'] - #print "networks", yaml.safe_dump(myVMDict['networks'], indent=4, default_flow_style=False) - #print "interfaces", yaml.safe_dump(vm['interfaces'], indent=4, default_flow_style=False) - #print ">>>>>>>>>>>>>>>>>>>>>>>>>>>" + db_vm_iface={ + # "uuid" + # 'instance_vm_id': instance_vm_uuid, + "instance_net_id": instance_net_id, + 'interface_id': iface['uuid'], + # 'vim_interface_id': , + 'type': 'external' if iface['external_name'] is not None else 'internal', + 'ip_address': iface.get('ip_address'), + 'floating_ip': int(iface.get('floating-ip', False)), + 'port_security': int(iface.get('port-security', True)) + } + db_vm_ifaces.append(db_vm_iface) + # print ">>>>>>>>>>>>>>>>>>>>>>>>>>>" + # print myVMDict['name'] + # print "networks", yaml.safe_dump(myVMDict['networks'], indent=4, default_flow_style=False) + # print "interfaces", yaml.safe_dump(vm['interfaces'], indent=4, default_flow_style=False) + # print ">>>>>>>>>>>>>>>>>>>>>>>>>>>" if vm.get("boot_data"): cloud_config_vm = unify_cloud_config(vm["boot_data"], cloud_config) else: cloud_config_vm = cloud_config - if myVMDict.get('availability_zone'): av_index = vnf_availability_zones.index(myVMDict['availability_zone']) else: av_index = None - task = new_task("new-vm", (myVMDict['name'], myVMDict['description'], myVMDict.get('start', None), - myVMDict['imageRef'], myVMDict['flavorRef'], myVMDict['networks'], - cloud_config_vm, myVMDict['disks'], av_index, - vnf_availability_zones), depends=task_depends) - instance_tasks[task["id"]] = task - tasks_to_launch[myvim_thread_id].append(task) - vm_id = task["id"] - vm['vim_id'] = vm_id - rollbackList.append({'what':'vm','where':'vim','vim_id':datacenter_id,'uuid':vm_id}) - #put interface uuid back to scenario[vnfs][vms[[interfaces] - for net in myVMDict['networks']: - if "vim_id" in net: - for iface in vm['interfaces']: - if net["name"]==iface["internal_name"]: - iface["vim_id"]=net["vim_id"] - break + for vm_index in range(0, vm.get('count', 1)): + vm_index_name = "" + if vm.get('count', 1) > 1: + vm_index_name += "." + chr(97 + vm_index) + task = new_task("new-vm", (myVMDict['name']+vm_index_name, myVMDict['description'], + myVMDict.get('start', None), myVMDict['imageRef'], + myVMDict['flavorRef'], myVMDict['networks'], + cloud_config_vm, myVMDict['disks'], av_index, + vnf_availability_zones), depends=task_depends) + instance_tasks[task["id"]] = task + tasks_to_launch[myvim_thread_id].append(task) + vm_id = task["id"] + vm['vim_id'] = vm_id + rollbackList.append({'what':'vm','where':'vim','vim_id':datacenter_id,'uuid':vm_id}) + # put interface uuid back to scenario[vnfs][vms[[interfaces] + for net in myVMDict['networks']: + if "vim_id" in net: + for iface in vm['interfaces']: + if net["name"]==iface["internal_name"]: + iface["vim_id"]=net["vim_id"] + break + vm_uuid = str(uuid4()) + uuid_list.append(vm_uuid) + db_vm = { + "uuid": vm_uuid, + 'instance_vnf_id': vnf_uuid, + "vim_vm_id": vm_id, + "vm_id": vm["uuid"], + # "status": + } + db_instance_vms.append(db_vm) + for db_vm_iface in db_vm_ifaces: + iface_uuid = str(uuid4()) + uuid_list.append(iface_uuid) + db_vm_iface_instance = { + "uuid": iface_uuid, + "instance_vm_id": vm_uuid + } + db_vm_iface_instance.update(db_vm_iface) + if db_vm_iface_instance.get("ip_address"): # increment ip_address + ip = db_vm_iface_instance.get("ip_address") + i = ip.rfind(".") + if i > 0: + try: + i += 1 + ip = ip[i:] + str(int(ip[:i]) +1) + db_vm_iface_instance["ip_address"] = ip + except: + db_vm_iface_instance["ip_address"] = None + db_instance_interfaces.append(db_vm_iface_instance) + scenarioDict["datacenter2tenant"] = myvim_threads_id + + db_instance_scenario['datacenter_tenant_id'] = myvim_threads_id[default_datacenter_id] + db_instance_scenario['datacenter_id'] = default_datacenter_id + db_tables=[ + {"instance_scenarios": db_instance_scenario}, + {"instance_vnfs": db_instance_vnfs}, + {"instance_nets": db_instance_nets}, + {"ip_profiles": db_ip_profiles}, + {"instance_vms": db_instance_vms}, + {"instance_interfaces": db_instance_interfaces}, + ] + logger.debug("create_instance Deployment done scenarioDict: %s", - yaml.safe_dump(scenarioDict, indent=4, default_flow_style=False) ) - instance_id = mydb.new_instance_scenario_as_a_whole(tenant_id,instance_name, instance_description, scenarioDict) + yaml.safe_dump(db_tables, indent=4, default_flow_style=False) ) + mydb.new_rows(db_tables, uuid_list) for myvim_thread_id,task_list in tasks_to_launch.items(): for task in task_list: vim_threads["running"][myvim_thread_id].insert_task(task) - global_instance_tasks[instance_id] = instance_tasks + global_instance_tasks[instance_uuid] = instance_tasks # Update database with those ended instance_tasks # for task in instance_tasks.values(): # if task["status"] == "ok": @@ -2382,7 +2533,7 @@ def create_instance(mydb, tenant_id, instance_dict): # elif task["name"] == "new-net": # mydb.update_rows("instance_nets", UPDATE={"vim_net_id": task["result"]}, # WHERE={"vim_net_id": task["id"]}) - return mydb.get_instance_scenario(instance_id) + return mydb.get_instance_scenario(instance_uuid) except (NfvoException, vimconn.vimconnException,db_base_Exception) as e: message = rollback(mydb, myvims, rollbackList) if isinstance(e, db_base_Exception): diff --git a/osm_ro/nfvo_db.py b/osm_ro/nfvo_db.py index 3dcffd0c..071d03ab 100644 --- a/osm_ro/nfvo_db.py +++ b/osm_ro/nfvo_db.py @@ -38,6 +38,7 @@ tables_with_createdat_field=["datacenters","instance_nets","instance_scenarios", "interfaces","nets","nfvo_tenants","scenarios","sce_interfaces","sce_nets", "sce_vnfs","tenants_datacenters","datacenter_tenants","vms","vnfs", "datacenter_nets"] + class nfvo_db(db_base.db_base): def __init__(self, host=None, user=None, passwd=None, database=None, log_name='openmano.db', log_level=None): db_base.db_base.__init__(self, host, user, passwd, database, log_name, log_level) @@ -585,16 +586,18 @@ class nfvo_db(db_base.db_base): scenario_dict['vnfs'] = self.cur.fetchall() for vnf in scenario_dict['vnfs']: #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']) + 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.description as description, vms.boot_data as boot_data," \ + " vms.description as description, vms.boot_data as boot_data, count," \ " vms.availability_zone as availability_zone" \ - " FROM vnfs join vms on vnfs.uuid=vms.vnf_id " \ - " WHERE vnfs.uuid='" + vnf['vnf_id'] +"'" \ + " FROM vnfs join vms on vnfs.uuid=vms.vnf_id" \ + " WHERE vnfs.uuid='" + vnf['vnf_id'] + "'" \ " ORDER BY vms.created_at" self.logger.debug(cmd) self.cur.execute(cmd) @@ -722,6 +725,43 @@ class nfvo_db(db_base.db_base): self._format_error(e, tries, "delete", "instances running") tries -= 1 + def new_rows(self, tables, uuid_list=None): + """ + Make a transactional insertion of rows at several tables + :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 = [ + {"table1": [ {"column1": value, "column2: value, ... }, {"column1": value, "column2: value, ... }, ...], + {"table2": [ {"column1": value, "column2: value, ... }, {"column1": value, "column2: value, ... }, ...], + {"table3": {"column1": value, "column2: value, ... } + } + :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 + """ + tries = 2 + while tries: + created_time = time.time() + try: + with self.con: + self.cur = self.con.cursor() + for table in tables: + for table_name, row_list in table.items(): + index = 0 + if isinstance(row_list, dict): + row_list = (row_list, ) #create a list with the single value + for row in row_list: + if table_name in self.tables_with_created_field: + created_time_param = created_time + index*0.00001 + else: + created_time_param=0 + self._new_row_internal(table_name, row, add_uuid=False, root_uuid=None, + created_time=created_time_param) + index += 1 + return + except (mdb.Error, AttributeError) as e: + self._format_error(e, tries) + tries -= 1 + def new_instance_scenario_as_a_whole(self,tenant_id,instance_scenario_name,instance_scenario_description,scenarioDict): tries = 2 while tries: diff --git a/osm_ro/openmano_schemas.py b/osm_ro/openmano_schemas.py index ec154781..fb12d9f1 100644 --- a/osm_ro/openmano_schemas.py +++ b/osm_ro/openmano_schemas.py @@ -386,7 +386,7 @@ internal_connection_schema = { "name": name_schema, "description":description_schema, "type":{"type":"string", "enum":["bridge","data","ptp"]}, - "elements": {"type" : "array", "items": internal_connection_element_schema, "minItems":2} + "elements": {"type" : "array", "items": internal_connection_element_schema, "minItems":1} }, "required": ["name", "type", "elements"], "additionalProperties": False @@ -400,7 +400,7 @@ internal_connection_schema_v02 = { "type": {"type": "string", "enum":["e-line", "e-lan"]}, "implementation": {"type": "string", "enum":["overlay", "underlay"]}, "ip-profile": ip_profile_schema, - "elements": {"type" : "array", "items": internal_connection_element_schema_v02, "minItems":2} + "elements": {"type" : "array", "items": internal_connection_element_schema_v02, "minItems":1} }, "required": ["name", "type", "implementation", "elements"], "additionalProperties": False @@ -541,6 +541,7 @@ vnfc_schema = { "properties":{ "name": name_schema, "description": description_schema, + "count": integer1_schema, "image name": name_schema, "availability_zone": name_schema, "VNFC image": {"oneOf": [path_schema, http_schema]}, diff --git a/test/RO_tests/simple_count3/scenario_linux_count3.yaml b/test/RO_tests/simple_count3/scenario_linux_count3.yaml new file mode 100644 index 00000000..2362c027 --- /dev/null +++ b/test/RO_tests/simple_count3/scenario_linux_count3.yaml @@ -0,0 +1,39 @@ +## +# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U. +# This file is part of openmano +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# For those usages not covered by the Apache License, Version 2.0 please +# contact with: nfvlabs@tid.es +## +--- +schema_version: 2 +scenario: + name: simple_count3 + description: Simple network scenario consisting of a multi VNFC VNF connected to an external network + vnfs: + linux1: # vnf/net name in the scenario + vnf_name: simple_linux_count3 # VNF name as introduced in OPENMANO DB + networks: + mgmt: # provide a name for this net or connection + external: true + interfaces: + - linux1: control0 # Node and its interface + internal1: # provide a name for this net or connection + external: false + interfaces: + - linux1: data-eth1 + + diff --git a/test/RO_tests/simple_count3/vnfd_count3.yaml b/test/RO_tests/simple_count3/vnfd_count3.yaml new file mode 100644 index 00000000..a4c70705 --- /dev/null +++ b/test/RO_tests/simple_count3/vnfd_count3.yaml @@ -0,0 +1,68 @@ +## +# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U. +# This file is part of openmano +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# For those usages not covered by the Apache License, Version 2.0 please +# contact with: nfvlabs@tid.es +## +--- +schema_version: "0.2" +vnf: + name: simple_linux_count3 + description: "Example of a linux VNF consisting of two VMs with one internal network" + # class: parent # Optional. Used to organize VNFs + internal-connections: + - name: internal-eth2 + description: internalnet + type: e-lan + implementation: overlay + ip-profile: + ip-version: IPv4 + subnet-address: 192.168.1.0/24 + gateway-address: 192.168.1.1 + dns-address: 8.8.8.8 + dhcp: + enabled: true + start-address: 192.168.1.100 + count: 100 + elements: + - VNFC: linux_3VMs + local_iface_name: eth2 + ip_address: 192.168.1.2 + external-connections: + - name: control0 + type: mgmt + VNFC: linux_3VMs + local_iface_name: eth0 + description: control interface VM1 + - name: data-eth1 + type: bridge + VNFC: linux_3VMs + local_iface_name: eth1 + description: data interface input + VNFC: + - name: linux_3VMs + count: 3 + description: "Linux VM1 2 CPUs, 2 GB RAM and 3 bridge interfaces" + #Copy the image to a compute path and edit this path + image name: TestVM + disk: 10 + vcpus: 2 + ram: 2048 + bridge-ifaces: + - name: eth0 + - name: eth1 + - name: eth2 diff --git a/vnfs/vnf-template.yaml b/vnfs/vnf-template.yaml index 121c5abb..b57ebfd7 100644 --- a/vnfs/vnf-template.yaml +++ b/vnfs/vnf-template.yaml @@ -46,6 +46,7 @@ vnf: description: Bridge interface VNFC: # Virtual machine array - name: TEMPLATE-VM # name of Virtual Machine + # count: 1 #by default 1 description: TEMPLATE description VNFC image: /path/to/imagefolder/TEMPLATE-VM.qcow2 # image metadata: {"bus":"ide", "os_type":"windows", "use_incremental": "no" } #Optional -- 2.25.1