X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_nbi%2Finstance_topics.py;h=22580d152adf6b9528aca0713070197a85005161;hb=refs%2Fchanges%2F71%2F11771%2F2;hp=94adb7bf02420bbb9fca07b9e6fe75b4b745a9cd;hpb=bb00602bac72bd5744e1e3ddc8e15068cb27c024;p=osm%2FNBI.git diff --git a/osm_nbi/instance_topics.py b/osm_nbi/instance_topics.py index 94adb7b..22580d1 100644 --- a/osm_nbi/instance_topics.py +++ b/osm_nbi/instance_topics.py @@ -14,6 +14,7 @@ # limitations under the License. # import logging +import json from uuid import uuid4 from http import HTTPStatus from time import time @@ -239,14 +240,16 @@ class NsrTopic(BaseTopic): where_, k ) ) - if "." in k or "$" in k: + if "$" in k: raise EngineException( - "Invalid param at {}:{}. Keys must not contain dots or $".format( + "Invalid param at {}:{}. Keys must not contain $ symbol".format( where_, k ) ) if isinstance(v, (dict, tuple, list)): additional_params[k] = "!!yaml " + safe_dump(v) + if kdu_name: + additional_params = json.dumps(additional_params) if descriptor: for df in descriptor.get("df", []): @@ -478,7 +481,6 @@ class NsrTopic(BaseTopic): ns_request["nsr_id"] = nsr_id if ns_request and ns_request.get("config-units"): nsr_descriptor["config-units"] = ns_request["config-units"] - # Create vld if nsd.get("virtual-link-desc"): nsr_vld = deepcopy(nsd.get("virtual-link-desc", [])) @@ -767,6 +769,14 @@ class NsrTopic(BaseTopic): additional_params, vdu_params = self._format_additional_params( ns_request, vnf_index, vdu_id=vdu["id"], descriptor=vnfd ) + + try: + vdu_virtual_storage_descriptors = utils.filter_in_list( + vnfd.get("virtual-storage-desc", []), + lambda stg_desc: stg_desc["id"] in vdu["virtual-storage-desc"] + ) + except Exception: + vdu_virtual_storage_descriptors = [] vdur = { "vdu-id-ref": vdu["id"], # TODO "name": "" Name of the VDU in the VIM @@ -776,6 +786,7 @@ class NsrTopic(BaseTopic): "interfaces": [], "additionalParams": additional_params, "vdu-name": vdu["name"], + "virtual-storages": vdu_virtual_storage_descriptors } if vdu_params and vdu_params.get("config-units"): vdur["config-units"] = vdu_params["config-units"] @@ -1326,6 +1337,18 @@ class NsLcmOpTopic(BaseTopic): ) vim_accounts.append(vim_account) + def _get_vim_account(self, vim_id: str, session): + try: + db_filter = self._get_project_filter(session) + db_filter["_id"] = vim_id + return self.db.get_one("vim_accounts", db_filter) + except Exception: + raise EngineException( + "Invalid vimAccountId='{}' not present for the project".format( + vim_id + ) + ) + def _check_valid_wim_account(self, wim_account, wim_accounts, session): if not isinstance(wim_account, str): return @@ -1588,6 +1611,68 @@ class NsLcmOpTopic(BaseTopic): # TODO check that this forcing is not incompatible with other forcing return ifaces_forcing_vim_network + def _update_vnfrs_from_nsd(self, nsr): + try: + nsr_id = nsr["_id"] + nsd = nsr["nsd"] + + step = "Getting vnf_profiles from nsd" + vnf_profiles = nsd.get("df", [{}])[0].get("vnf-profile", ()) + vld_fixed_ip_connection_point_data = {} + + step = "Getting ip-address info from vnf_profile if it exists" + for vnfp in vnf_profiles: + # Checking ip-address info from nsd.vnf_profile and storing + for vlc in vnfp.get("virtual-link-connectivity", ()): + for cpd in vlc.get("constituent-cpd-id", ()): + if cpd.get("ip-address"): + step = "Storing ip-address info" + vld_fixed_ip_connection_point_data.update({vlc.get("virtual-link-profile-id") + '.' + cpd.get("constituent-base-element-id"): { + "vnfd-connection-point-ref": cpd.get( + "constituent-cpd-id"), + "ip-address": cpd.get( + "ip-address")}}) + + # Inserting ip address to vnfr + if len(vld_fixed_ip_connection_point_data) > 0: + step = "Getting vnfrs" + vnfrs = self.db.get_list("vnfrs", {"nsr-id-ref": nsr_id}) + for item in vld_fixed_ip_connection_point_data.keys(): + step = "Filtering vnfrs" + vnfr = next(filter(lambda vnfr: vnfr["member-vnf-index-ref"] == item.split('.')[1], vnfrs), None) + if vnfr: + vnfr_update = {} + for vdur_index, vdur in enumerate(vnfr["vdur"]): + for iface_index, iface in enumerate(vdur["interfaces"]): + step = "Looking for matched interface" + if ( + iface.get("external-connection-point-ref") + == vld_fixed_ip_connection_point_data[item].get("vnfd-connection-point-ref") and + iface.get("ns-vld-id") == item.split('.')[0] + + ): + vnfr_update_text = "vdur.{}.interfaces.{}".format( + vdur_index, iface_index + ) + step = "Storing info in order to update vnfr" + vnfr_update[ + vnfr_update_text + ".ip-address" + ] = increment_ip_mac( + vld_fixed_ip_connection_point_data[item].get("ip-address"), + vdur.get("count-index", 0), ) + vnfr_update[vnfr_update_text + ".fixed-ip"] = True + + step = "updating vnfr at database" + self.db.set_one("vnfrs", {"_id": vnfr["_id"]}, vnfr_update) + except ( + ValidationError, + EngineException, + DbException, + MsgException, + FsException, + ) as e: + raise type(e)("{} while '{}'".format(e, step), http_code=e.http_code) + def _update_vnfrs(self, session, rollback, nsr, indata): # get vnfr nsr_id = nsr["_id"] @@ -1600,15 +1685,14 @@ class NsLcmOpTopic(BaseTopic): # update vim-account-id vim_account = indata["vimAccountId"] - vca_id = indata.get("vcaId") + vca_id = self._get_vim_account(vim_account, session).get("vca") # check instantiate parameters for vnf_inst_params in get_iterable(indata.get("vnf")): if vnf_inst_params["member-vnf-index"] != member_vnf_index: continue if vnf_inst_params.get("vimAccountId"): vim_account = vnf_inst_params.get("vimAccountId") - if vnf_inst_params.get("vcaId"): - vca_id = vnf_inst_params.get("vcaId") + vca_id = self._get_vim_account(vim_account, session).get("vca") # get vnf.vdu.interface instantiation params to update vnfr.vdur.interfaces ip, mac for vdu_inst_param in get_iterable(vnf_inst_params.get("vdu")): @@ -1906,8 +1990,13 @@ class NsLcmOpTopic(BaseTopic): HTTPStatus.CONFLICT, ) self._check_ns_operation(session, nsr, operation, indata) + if (indata.get("primitive_params")): + indata["primitive_params"] = json.dumps(indata["primitive_params"]) + elif (indata.get("additionalParamsForVnf")): + indata["additionalParamsForVnf"] = json.dumps(indata["additionalParamsForVnf"]) if operation == "instantiate": + self._update_vnfrs_from_nsd(nsr) self._update_vnfrs(session, rollback, nsr, indata) nslcmop_desc = self._create_nslcmop(nsInstanceId, operation, indata)