From b699079de277df00143b293e9d0e1b04ea54a1b8 Mon Sep 17 00:00:00 2001 From: tierno Date: Tue, 13 Nov 2018 10:37:42 +0100 Subject: [PATCH] feature 1417 support of PDUs Change-Id: I4f74215f2604daab1bd6a148e37d21a2547f4207 Signed-off-by: tierno --- database_utils/migrate_mano_db.sh | 18 +++++++++++++++++- openmanod | 4 ++-- osm_ro/nfvo.py | 21 ++++++++++++++++----- osm_ro/nfvo_db.py | 11 +++++++---- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/database_utils/migrate_mano_db.sh b/database_utils/migrate_mano_db.sh index 1cdadd25..ecd6b117 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=32 +LAST_DB_VERSION=33 # Detect paths MYSQL=$(which mysql) @@ -200,6 +200,7 @@ fi #[ $OPENMANO_VER_NUM -ge 5060 ] && DB_VERSION=30 #0.5.60 => 30 #[ $OPENMANO_VER_NUM -ge 5061 ] && DB_VERSION=31 #0.5.61 => 31 #[ $OPENMANO_VER_NUM -ge 5070 ] && DB_VERSION=32 #0.5.70 => 32 +#[ $OPENMANO_VER_NUM -ge 5082 ] && DB_VERSION=33 #0.5.82 => 33 #TODO ... put next versions here function upgrade_to_1(){ @@ -1292,6 +1293,21 @@ function downgrade_from_32(){ sql "DELETE FROM schema_version WHERE version_int='32';" } +function upgrade_to_33(){ + echo " Add PDU information to 'vms" + sql "ALTER TABLE vms ADD COLUMN pdu_type VARCHAR(255) NULL DEFAULT NULL AFTER osm_id;" + sql "ALTER TABLE instance_nets ADD COLUMN vim_name VARCHAR(255) NULL DEFAULT NULL AFTER vim_net_id;" + sql "INSERT INTO schema_version (version_int, version, openmano_ver, comments, date) "\ + "VALUES (33, '0.33', '0.5.82', 'Add pdu information to vms', '2018-11-13');" +} +function downgrade_from_33(){ + echo " Remove back PDU information from' vms'" + sql "ALTER TABLE vms DROP COLUMN pdu_type;" + sql "ALTER TABLE instance_nets DROP COLUMN vim_name;" + sql "DELETE FROM schema_version WHERE version_int='33';" +} + + function upgrade_to_X(){ echo " change 'datacenter_nets'" sql "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);" diff --git a/openmanod b/openmanod index 7010f801..32c60ee3 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.81-r591" +__version__ = "0.5.82-r592" version_date = "Nov 2018" -database_version = 32 # expected database schema version +database_version = 33 # expected database schema version global global_config diff --git a/osm_ro/nfvo.py b/osm_ro/nfvo.py index d25df13c..cfd2b43d 100644 --- a/osm_ro/nfvo.py +++ b/osm_ro/nfvo.py @@ -943,6 +943,7 @@ def new_vnfd_v3(mydb, tenant_id, vnf_descriptor): cp_name2iface_uuid = {} cp_name2vm_uuid = {} cp_name2db_interface = {} + vdu_id2cp_name = {} # stored only when one external connection point is presented at this VDU # table vms (vdus) vdu_id2uuid = {} @@ -960,6 +961,7 @@ def new_vnfd_v3(mydb, tenant_id, vnf_descriptor): "osm_id": vdu_id, "name": get_str(vdu, "name", 255), "description": get_str(vdu, "description", 255), + "pdu_type": get_str(vdu, "pdu-type", 255), "vnf_id": vnf_uuid, } vdu_id2uuid[db_vm["osm_id"]] = vm_uuid @@ -1049,7 +1051,6 @@ def new_vnfd_v3(mydb, tenant_id, vnf_descriptor): # table interfaces (internal/external interfaces) flavor_epa_interfaces = [] - vdu_id2cp_name = {} # stored only when one external connection point is presented at this VDU # for iface in chain(vdu.get("internal-interface").itervalues(), vdu.get("external-interface").itervalues()): for iface in vdu.get("interface").itervalues(): flavor_epa_interface = {} @@ -1240,7 +1241,8 @@ def new_vnfd_v3(mydb, tenant_id, vnf_descriptor): "'member-vdus':'{vdu}'. Reference to a non-existing vdu".format( vnf=vnfd_id, pg=pg_name, vdu=vdu_id), HTTP_Bad_Request) - db_vms[vdu_id2db_table_index[vdu_id]]["availability_zone"] = pg_name + if vdu_id2db_table_index[vdu_id]: + db_vms[vdu_id2db_table_index[vdu_id]]["availability_zone"] = pg_name # TODO consider the case of isolation and not colocation # if pg.get("strategy") == "ISOLATION": @@ -1256,20 +1258,22 @@ def new_vnfd_v3(mydb, tenant_id, vnf_descriptor): mgmt_access["vm_id"] = vdu_id2uuid[vnfd["mgmt-interface"]["vdu-id"]] # if only one cp is defined by this VDU, mark this interface as of type "mgmt" if vdu_id2cp_name.get(mgmt_vdu_id): - cp_name2db_interface[vdu_id2cp_name[mgmt_vdu_id]]["type"] = "mgmt" + if cp_name2db_interface[vdu_id2cp_name[mgmt_vdu_id]]: + cp_name2db_interface[vdu_id2cp_name[mgmt_vdu_id]]["type"] = "mgmt" if vnfd["mgmt-interface"].get("ip-address"): mgmt_access["ip-address"] = str(vnfd["mgmt-interface"].get("ip-address")) if vnfd["mgmt-interface"].get("cp"): if vnfd["mgmt-interface"]["cp"] not in cp_name2iface_uuid: - raise NfvoException("Error. Invalid VNF descriptor at 'vnfd[{vnf}]':'mgmt-interface':'cp':'{cp}'. " + raise NfvoException("Error. Invalid VNF descriptor at 'vnfd[{vnf}]':'mgmt-interface':'cp'['{cp}']. " "Reference to a non-existing connection-point".format( vnf=vnfd_id, cp=vnfd["mgmt-interface"]["cp"]), HTTP_Bad_Request) mgmt_access["vm_id"] = cp_name2vm_uuid[vnfd["mgmt-interface"]["cp"]] mgmt_access["interface_id"] = cp_name2iface_uuid[vnfd["mgmt-interface"]["cp"]] # mark this interface as of type mgmt - cp_name2db_interface[vnfd["mgmt-interface"]["cp"]]["type"] = "mgmt" + if cp_name2db_interface[vnfd["mgmt-interface"]["cp"]]: + cp_name2db_interface[vnfd["mgmt-interface"]["cp"]]["type"] = "mgmt" default_user = get_str(vnfd.get("vnf-configuration", {}).get("config-access", {}).get("ssh-access", {}), "default-user", 64) @@ -3146,6 +3150,7 @@ def create_instance(mydb, tenant_id, instance_dict): myvim_thread_id = myvim_threads_id[datacenter_id] net_type = sce_net['type'] + net_vim_name = None lookfor_filter = {'admin_state_up': True, 'status': 'ACTIVE'} # 'shared': True if not net_name: @@ -3218,6 +3223,7 @@ def create_instance(mydb, tenant_id, instance_dict): db_net = { "uuid": net_uuid, 'vim_net_id': None, + "vim_name": net_vim_name, "instance_scenario_id": instance_uuid, "sce_net_id": sce_net["uuid"], "created": create_network, @@ -3531,6 +3537,7 @@ def instantiate_vnf(mydb, sce_vnf, params, params_out, rollbackList): db_net = { "uuid": net_uuid, 'vim_net_id': None, + "vim_name": net_name, "instance_scenario_id": instance_uuid, "net_id": net["uuid"], "created": True, @@ -3616,6 +3623,10 @@ def instantiate_vnf(mydb, sce_vnf, params, params_out, rollbackList): db_instance_vnfs.append(db_instance_vnf) for vm in sce_vnf['vms']: + # skip PDUs + if vm.get("pdu_type"): + continue + myVMDict = {} sce_vnf_name = sce_vnf['member_vnf_index'] if sce_vnf['member_vnf_index'] else sce_vnf['name'] myVMDict['name'] = "{}-{}-{}".format(instance_name[:64], sce_vnf_name[:64], vm["name"][:64]) diff --git a/osm_ro/nfvo_db.py b/osm_ro/nfvo_db.py index de143ec8..a40a804d 100644 --- a/osm_ro/nfvo_db.py +++ b/osm_ro/nfvo_db.py @@ -608,7 +608,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" @@ -1038,9 +1038,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() -- 2.25.1