X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=blobdiff_plain;f=osm_nbi%2Finstance_topics.py;h=8c084e4ea2b1caa0e4b961b819c105fc1106e307;hp=4b3f04bc74317f2cd95517b57b8a3a376b1c60fc;hb=15a1f68badbe4865b7abb3cb9ac816ed963d4b63;hpb=23acf4001306e92a587de566be4bab00931104ba diff --git a/osm_nbi/instance_topics.py b/osm_nbi/instance_topics.py index 4b3f04b..8c084e4 100644 --- a/osm_nbi/instance_topics.py +++ b/osm_nbi/instance_topics.py @@ -33,8 +33,8 @@ class NsrTopic(BaseTopic): topic_msg = "ns" schema_new = ns_instantiate - def __init__(self, db, fs, msg): - BaseTopic.__init__(self, db, fs, msg) + def __init__(self, db, fs, msg, auth): + BaseTopic.__init__(self, db, fs, msg, auth) def _check_descriptor_dependencies(self, session, descriptor): """ @@ -182,6 +182,9 @@ class NsrTopic(BaseTopic): """ try: + step = "checking quotas" + self.check_quota(session) + step = "validating input parameters" ns_request = self._remove_envelop(indata) # Override descriptor with query string kwargs @@ -391,8 +394,8 @@ class VnfrTopic(BaseTopic): topic = "vnfrs" topic_msg = None - def __init__(self, db, fs, msg): - BaseTopic.__init__(self, db, fs, msg) + def __init__(self, db, fs, msg, auth): + BaseTopic.__init__(self, db, fs, msg, auth) def delete(self, session, _id, dry_run=False): raise EngineException("Method delete called directly", HTTPStatus.INTERNAL_SERVER_ERROR) @@ -415,8 +418,8 @@ class NsLcmOpTopic(BaseTopic): "terminate": None, } - def __init__(self, db, fs, msg): - BaseTopic.__init__(self, db, fs, msg) + def __init__(self, db, fs, msg, auth): + BaseTopic.__init__(self, db, fs, msg, auth) def _check_ns_operation(self, session, nsr, operation, indata): """ @@ -426,22 +429,34 @@ class NsLcmOpTopic(BaseTopic): :param indata: descriptor with the parameters of the operation :return: None """ - vnfds = {} + vnf_member_index_to_vnfd = {} # map between vnf_member_index to vnf descriptor. vim_accounts = [] wim_accounts = [] nsd = nsr["nsd"] def check_valid_vnf_member_index(member_vnf_index): - # TODO change to vnfR - for vnf in nsd["constituent-vnfd"]: - if member_vnf_index == vnf["member-vnf-index"]: - vnfd_id = vnf["vnfd-id-ref"] - if vnfd_id not in vnfds: - vnfds[vnfd_id] = self.db.get_one("vnfds", {"id": vnfd_id}) - return vnfds[vnfd_id] - else: + # Obtain vnf descriptor. The vnfr is used to get the vnfd._id used for this member_vnf_index + if vnf_member_index_to_vnfd.get(member_vnf_index): + return vnf_member_index_to_vnfd[member_vnf_index] + vnfr = self.db.get_one("vnfrs", + {"nsr-id-ref": nsr["_id"], "member-vnf-index-ref": member_vnf_index}, + fail_on_empty=False) + if not vnfr: raise EngineException("Invalid parameter member_vnf_index='{}' is not one of the " "nsd:constituent-vnfd".format(member_vnf_index)) + vnfd = self.db.get_one("vnfds", {"_id": vnfr["vnfd-id"]}, fail_on_empty=False) + if not vnfd: + raise EngineException("vnfd id={} has been deleted!. Operation cannot be performed". + format(vnfr["vnfd-id"])) + vnf_member_index_to_vnfd[member_vnf_index] = vnfd # add to cache, avoiding a later look for + return vnfd + + def check_valid_vdu(vnfd, vdu_id): + for vdud in get_iterable(vnfd.get("vdu")): + if vdud["id"] == vdu_id: + return vdud + else: + raise EngineException("Invalid parameter vdu_id='{}' not present at vnfd:vdu:id".format(vdu_id)) def _check_vnf_instantiation_params(in_vnfd, vnfd): @@ -520,7 +535,11 @@ class NsLcmOpTopic(BaseTopic): indata["member_vnf_index"] = indata.pop("vnf_member_index") # for backward compatibility if indata.get("member_vnf_index"): vnfd = check_valid_vnf_member_index(indata["member_vnf_index"]) - descriptor_configuration = vnfd.get("vnf-configuration", {}).get("config-primitive") + if indata.get("vdu_id"): + vdud = check_valid_vdu(vnfd, indata["vdu_id"]) + descriptor_configuration = vdud.get("vdu-configuration", {}).get("config-primitive") + else: + descriptor_configuration = vnfd.get("vnf-configuration", {}).get("config-primitive") else: # use a NSD descriptor_configuration = nsd.get("ns-configuration", {}).get("config-primitive") # check primitive @@ -829,9 +848,9 @@ class NsiTopic(BaseTopic): topic = "nsis" topic_msg = "nsi" - def __init__(self, db, fs, msg): - BaseTopic.__init__(self, db, fs, msg) - self.nsrTopic = NsrTopic(db, fs, msg) + def __init__(self, db, fs, msg, auth): + BaseTopic.__init__(self, db, fs, msg, auth) + self.nsrTopic = NsrTopic(db, fs, msg, auth) @staticmethod def _format_ns_request(ns_request): @@ -990,6 +1009,9 @@ class NsiTopic(BaseTopic): """ try: + step = "checking quotas" + self.check_quota(session) + step = "" slice_request = self._remove_envelop(indata) # Override descriptor with query string kwargs @@ -1153,9 +1175,9 @@ class NsiLcmOpTopic(BaseTopic): "terminate": None } - def __init__(self, db, fs, msg): - BaseTopic.__init__(self, db, fs, msg) - self.nsi_NsLcmOpTopic = NsLcmOpTopic(self.db, self.fs, self.msg) + def __init__(self, db, fs, msg, auth): + BaseTopic.__init__(self, db, fs, msg, auth) + self.nsi_NsLcmOpTopic = NsLcmOpTopic(self.db, self.fs, self.msg, self.auth) def _check_nsi_operation(self, session, nsir, operation, indata): """