- async def _ns_execute_primitive(self, db_deployed, nsr_name, member_vnf_index, vdu_id, primitive, primitive_params):
-
- vdu_id_text = "vnfd"
- if vdu_id:
- vdu_id_text = vdu_id
- application_name = self.n2vc.FormatApplicationName(
- nsr_name,
- member_vnf_index,
- vdu_id_text
- )
- vca_deployed = db_deployed["VCA"].get(application_name)
- if not vca_deployed:
- raise LcmException("charm for member_vnf_index={} vdu_id={} is not deployed".format(member_vnf_index,
- vdu_id))
- model_name = vca_deployed.get("model")
- application_name = vca_deployed.get("application")
- if not model_name or not application_name:
- raise LcmException("charm for member_vnf_index={} is not properly deployed".format(member_vnf_index))
- if vca_deployed["operational-status"] != "active":
- raise LcmException("charm for member_vnf_index={} operational_status={} not 'active'".format(
- member_vnf_index, vca_deployed["operational-status"]))
- callback = None # self.n2vc_callback
- callback_args = () # [db_nsr, db_nslcmop, member_vnf_index, None]
- await self.n2vc.login()
- task = asyncio.ensure_future(
- self.n2vc.ExecutePrimitive(
+ @staticmethod
+ def _map_primitive_params(primitive_desc, params, instantiation_params):
+ """
+ Generates the params to be provided to charm before executing primitive. If user does not provide a parameter,
+ The default-value is used. If it is between < > it look for a value at instantiation_params
+ :param primitive_desc: portion of VNFD/NSD that describes primitive
+ :param params: Params provided by user
+ :param instantiation_params: Instantiation params provided by user
+ :return: a dictionary with the calculated params
+ """
+ calculated_params = {}
+ for parameter in primitive_desc.get("parameter", ()):
+ param_name = parameter["name"]
+ if param_name in params:
+ calculated_params[param_name] = params[param_name]
+ elif "default-value" in parameter:
+ calculated_params[param_name] = parameter["default-value"]
+ if isinstance(parameter["default-value"], str) and parameter["default-value"].startswith("<") and \
+ parameter["default-value"].endswith(">"):
+ if parameter["default-value"][1:-1] in instantiation_params:
+ calculated_params[param_name] = instantiation_params[parameter["default-value"][1:-1]]
+ else:
+ raise LcmException("Parameter {} needed to execute primitive {} not provided".
+ format(parameter["default-value"], primitive_desc["name"]))
+ else:
+ raise LcmException("Parameter {} needed to execute primitive {} not provided".
+ format(param_name, primitive_desc["name"]))
+
+ if isinstance(calculated_params[param_name], (dict, list, tuple)):
+ calculated_params[param_name] = yaml.safe_dump(calculated_params[param_name], default_flow_style=True,
+ width=256)
+ elif isinstance(calculated_params[param_name], str) and calculated_params[param_name].startswith("!!yaml "):
+ calculated_params[param_name] = calculated_params[param_name][7:]
+ return calculated_params
+
+ async def _ns_execute_primitive(self, db_deployed, member_vnf_index, vdu_id, vdu_name, vdu_count_index,
+ primitive, primitive_params):
+ start_primitive_time = time()
+ try:
+ for vca_deployed in db_deployed["VCA"]:
+ if not vca_deployed:
+ continue
+ if member_vnf_index != vca_deployed["member-vnf-index"] or vdu_id != vca_deployed["vdu_id"]:
+ continue
+ if vdu_name and vdu_name != vca_deployed["vdu_name"]:
+ continue
+ if vdu_count_index and vdu_count_index != vca_deployed["vdu_count_index"]:
+ continue
+ break
+ else:
+ raise LcmException("charm for member_vnf_index={} vdu_id={} vdu_name={} vdu_count_index={} is not "
+ "deployed".format(member_vnf_index, vdu_id, vdu_name, vdu_count_index))
+ model_name = vca_deployed.get("model")
+ application_name = vca_deployed.get("application")
+ if not model_name or not application_name:
+ raise LcmException("charm for member_vnf_index={} vdu_id={} vdu_name={} vdu_count_index={} has not "
+ "model or application name" .format(member_vnf_index, vdu_id, vdu_name,
+ vdu_count_index))
+ if vca_deployed["operational-status"] != "active":
+ raise LcmException("charm for member_vnf_index={} vdu_id={} operational_status={} not 'active'".format(
+ member_vnf_index, vdu_id, vca_deployed["operational-status"]))
+ callback = None # self.n2vc_callback
+ callback_args = () # [db_nsr, db_nslcmop, member_vnf_index, None]
+ await self.n2vc.login()
+ primitive_id = await self.n2vc.ExecutePrimitive(