+ # Set NSD usageState
+ nsr = db_content
+ used_nsd_id = nsr.get("nsd-id")
+ if used_nsd_id:
+ # check if used by another NSR
+ nsrs_list = self.db.get_one("nsrs", {"nsd-id": used_nsd_id},
+ fail_on_empty=False, fail_on_more=False)
+ if not nsrs_list:
+ self.db.set_one("nsds", {"_id": used_nsd_id}, {"_admin.usageState": "NOT_IN_USE"})
+
+ # Set VNFD usageState
+ used_vnfd_id_list = nsr.get("vnfd-id")
+ if used_vnfd_id_list:
+ for used_vnfd_id in used_vnfd_id_list:
+ # check if used by another NSR
+ nsrs_list = self.db.get_one("nsrs", {"vnfd-id": used_vnfd_id},
+ fail_on_empty=False, fail_on_more=False)
+ if not nsrs_list:
+ self.db.set_one("vnfds", {"_id": used_vnfd_id}, {"_admin.usageState": "NOT_IN_USE"})
+
+ @staticmethod
+ def _format_ns_request(ns_request):
+ formated_request = copy(ns_request)
+ formated_request.pop("additionalParamsForNs", None)
+ formated_request.pop("additionalParamsForVnf", None)
+ return formated_request
+
+ @staticmethod
+ def _format_addional_params(ns_request, member_vnf_index=None, descriptor=None):
+ """
+ Get and format user additional params for NS or VNF
+ :param ns_request: User instantiation additional parameters
+ :param member_vnf_index: None for extract NS params, or member_vnf_index to extract VNF params
+ :param descriptor: If not None it check that needed parameters of descriptor are supplied
+ :return: a formated copy of additional params or None if not supplied
+ """
+ additional_params = None
+ if not member_vnf_index:
+ additional_params = copy(ns_request.get("additionalParamsForNs"))
+ where_ = "additionalParamsForNs"
+ elif ns_request.get("additionalParamsForVnf"):
+ for additionalParamsForVnf in get_iterable(ns_request.get("additionalParamsForVnf")):
+ if additionalParamsForVnf["member-vnf-index"] == member_vnf_index:
+ additional_params = copy(additionalParamsForVnf.get("additionalParams"))
+ where_ = "additionalParamsForVnf[member-vnf-index={}]".format(
+ additionalParamsForVnf["member-vnf-index"])
+ break
+ if additional_params:
+ for k, v in additional_params.items():
+ # BEGIN Check that additional parameter names are valid Jinja2 identifiers
+ if not match('^[a-zA-Z_][a-zA-Z0-9_]*$', k):
+ raise EngineException("Invalid param name at {}:{}. Must contain only alphanumeric characters "
+ "and underscores, and cannot start with a digit"
+ .format(where_, k))
+ # END Check that additional parameter names are valid Jinja2 identifiers
+ if not isinstance(k, str):
+ raise EngineException("Invalid param at {}:{}. Only string keys are allowed".format(where_, k))
+ if "." in k or "$" in k:
+ raise EngineException("Invalid param at {}:{}. Keys must not contain dots or $".format(where_, k))
+ if isinstance(v, (dict, tuple, list)):
+ additional_params[k] = "!!yaml " + safe_dump(v)
+
+ if descriptor:
+ # check that enough parameters are supplied for the initial-config-primitive
+ # TODO: check for cloud-init
+ if member_vnf_index:
+ if descriptor.get("vnf-configuration"):
+ for initial_primitive in get_iterable(
+ descriptor["vnf-configuration"].get("initial-config-primitive")):
+ for param in get_iterable(initial_primitive.get("parameter")):
+ if param["value"].startswith("<") and param["value"].endswith(">"):
+ if param["value"] in ("<rw_mgmt_ip>", "<VDU_SCALE_INFO>"):
+ continue
+ if not additional_params or param["value"][1:-1] not in additional_params:
+ raise EngineException("Parameter '{}' needed for vnfd[id={}]:vnf-configuration:"
+ "initial-config-primitive[name={}] not supplied".
+ format(param["value"], descriptor["id"],
+ initial_primitive["name"]))
+
+ return additional_params
+
+ def new(self, rollback, session, indata=None, kwargs=None, headers=None):