+ raise LcmException("ns_update_vnfr: Not found member_vnf_index={} from VIM info".format(vnf_index))
+
+ def _get_ns_config_info(self, nsr_id):
+ """
+ Generates a mapping between vnf,vdu elements and the N2VC id
+ :param nsr_id: id of nsr to get last database _admin.deployed.VCA that contains this list
+ :return: a dictionary with {osm-config-mapping: {}} where its element contains:
+ "<member-vnf-index>": <N2VC-id> for a vnf configuration, or
+ "<member-vnf-index>.<vdu.id>.<vdu replica(0, 1,..)>": <N2VC-id> for a vdu configuration
+ """
+ db_nsr = self.db.get_one("nsrs", {"_id": nsr_id})
+ vca_deployed_list = db_nsr["_admin"]["deployed"]["VCA"]
+ mapping = {}
+ ns_config_info = {"osm-config-mapping": mapping}
+ for vca in vca_deployed_list:
+ if not vca["member-vnf-index"]:
+ continue
+ if not vca["vdu_id"]:
+ mapping[vca["member-vnf-index"]] = vca["application"]
+ else:
+ mapping["{}.{}.{}".format(vca["member-vnf-index"], vca["vdu_id"], vca["vdu_count_index"])] =\
+ vca["application"]
+ return ns_config_info
+
+ @staticmethod
+ def _get_initial_config_primitive_list(desc_primitive_list, vca_deployed):
+ """
+ Generates a list of initial-config-primitive based on the list provided by the descriptor. It includes internal
+ primitives as verify-ssh-credentials, or config when needed
+ :param desc_primitive_list: information of the descriptor
+ :param vca_deployed: information of the deployed, needed for known if it is related to an NS, VNF, VDU and if
+ this element contains a ssh public key
+ :return: The modified list. Can ba an empty list, but always a list
+ """
+ if desc_primitive_list:
+ primitive_list = desc_primitive_list.copy()
+ else:
+ primitive_list = []
+ # look for primitive config, and get the position. None if not present
+ config_position = None
+ for index, primitive in enumerate(primitive_list):
+ if primitive["name"] == "config":
+ config_position = index
+ break
+
+ # for NS, add always a config primitive if not present (bug 874)
+ if not vca_deployed["member-vnf-index"] and config_position is None:
+ primitive_list.insert(0, {"name": "config", "parameter": []})
+ config_position = 0
+ # for VNF/VDU add verify-ssh-credentials after config
+ if vca_deployed["member-vnf-index"] and config_position is not None and vca_deployed.get("ssh-public-key"):
+ primitive_list.insert(config_position + 1, {"name": "verify-ssh-credentials", "parameter": []})
+ return primitive_list
+
+ async def instantiate_RO(self, logging_text, nsr_id, nsd, db_nsr,
+ db_nslcmop, db_vnfrs, db_vnfds_ref, n2vc_key_list):
+
+ db_nsr_update = {}
+ RO_descriptor_number = 0 # number of descriptors created at RO
+ vnf_index_2_RO_id = {} # map between vnfd/nsd id to the id used at RO
+ start_deploy = time()
+ vdu_flag = False # If any of the VNFDs has VDUs
+ ns_params = db_nslcmop.get("operationParams")
+
+ # deploy RO
+
+ # get vnfds, instantiate at RO
+
+ for c_vnf in nsd.get("constituent-vnfd", ()):
+ member_vnf_index = c_vnf["member-vnf-index"]
+ vnfd = db_vnfds_ref[c_vnf['vnfd-id-ref']]
+ if vnfd.get("vdu"):
+ vdu_flag = True
+ vnfd_ref = vnfd["id"]
+ step = db_nsr_update["_admin.deployed.RO.detailed-status"] = "Creating vnfd='{}' member_vnf_index='{}' at" \
+ " RO".format(vnfd_ref, member_vnf_index)
+ # self.logger.debug(logging_text + step)
+ vnfd_id_RO = "{}.{}.{}".format(nsr_id, RO_descriptor_number, member_vnf_index[:23])
+ vnf_index_2_RO_id[member_vnf_index] = vnfd_id_RO
+ RO_descriptor_number += 1
+
+ # look position at deployed.RO.vnfd if not present it will be appended at the end
+ for index, vnf_deployed in enumerate(db_nsr["_admin"]["deployed"]["RO"]["vnfd"]):
+ if vnf_deployed["member-vnf-index"] == member_vnf_index:
+ break
+ else:
+ index = len(db_nsr["_admin"]["deployed"]["RO"]["vnfd"])
+ db_nsr["_admin"]["deployed"]["RO"]["vnfd"].append(None)
+
+ # look if present
+ RO_update = {"member-vnf-index": member_vnf_index}
+ vnfd_list = await self.RO.get_list("vnfd", filter_by={"osm_id": vnfd_id_RO})
+ if vnfd_list:
+ RO_update["id"] = vnfd_list[0]["uuid"]
+ self.logger.debug(logging_text + "vnfd='{}' member_vnf_index='{}' exists at RO. Using RO_id={}".
+ format(vnfd_ref, member_vnf_index, vnfd_list[0]["uuid"]))
+ else:
+ vnfd_RO = self.vnfd2RO(vnfd, vnfd_id_RO, db_vnfrs[c_vnf["member-vnf-index"]].
+ get("additionalParamsForVnf"), nsr_id)
+ desc = await self.RO.create("vnfd", descriptor=vnfd_RO)
+ RO_update["id"] = desc["uuid"]
+ self.logger.debug(logging_text + "vnfd='{}' member_vnf_index='{}' created at RO. RO_id={}".format(
+ vnfd_ref, member_vnf_index, desc["uuid"]))
+ db_nsr_update["_admin.deployed.RO.vnfd.{}".format(index)] = RO_update
+ db_nsr["_admin"]["deployed"]["RO"]["vnfd"][index] = RO_update
+ self.update_db_2("nsrs", nsr_id, db_nsr_update)
+ self._on_update_n2vc_db("nsrs", {"_id": nsr_id}, "_admin.deployed", db_nsr_update)
+
+ # create nsd at RO
+ nsd_ref = nsd["id"]
+ step = db_nsr_update["_admin.deployed.RO.detailed-status"] = "Creating nsd={} at RO".format(nsd_ref)
+ # self.logger.debug(logging_text + step)
+
+ RO_osm_nsd_id = "{}.{}.{}".format(nsr_id, RO_descriptor_number, nsd_ref[:23])
+ RO_descriptor_number += 1
+ nsd_list = await self.RO.get_list("nsd", filter_by={"osm_id": RO_osm_nsd_id})
+ if nsd_list:
+ db_nsr_update["_admin.deployed.RO.nsd_id"] = RO_nsd_uuid = nsd_list[0]["uuid"]
+ self.logger.debug(logging_text + "nsd={} exists at RO. Using RO_id={}".format(
+ nsd_ref, RO_nsd_uuid))
+ else:
+ nsd_RO = deepcopy(nsd)
+ nsd_RO["id"] = RO_osm_nsd_id
+ nsd_RO.pop("_id", None)
+ nsd_RO.pop("_admin", None)
+ for c_vnf in nsd_RO.get("constituent-vnfd", ()):
+ member_vnf_index = c_vnf["member-vnf-index"]
+ c_vnf["vnfd-id-ref"] = vnf_index_2_RO_id[member_vnf_index]
+ for c_vld in nsd_RO.get("vld", ()):
+ for cp in c_vld.get("vnfd-connection-point-ref", ()):
+ member_vnf_index = cp["member-vnf-index-ref"]
+ cp["vnfd-id-ref"] = vnf_index_2_RO_id[member_vnf_index]
+
+ desc = await self.RO.create("nsd", descriptor=nsd_RO)
+ db_nsr_update["_admin.nsState"] = "INSTANTIATED"
+ db_nsr_update["_admin.deployed.RO.nsd_id"] = RO_nsd_uuid = desc["uuid"]
+ self.logger.debug(logging_text + "nsd={} created at RO. RO_id={}".format(nsd_ref, RO_nsd_uuid))
+ self.update_db_2("nsrs", nsr_id, db_nsr_update)
+ self._on_update_n2vc_db("nsrs", {"_id": nsr_id}, "_admin.deployed", db_nsr_update)
+
+ # Crate ns at RO
+ # if present use it unless in error status
+ RO_nsr_id = deep_get(db_nsr, ("_admin", "deployed", "RO", "nsr_id"))
+ if RO_nsr_id:
+ try:
+ step = db_nsr_update["_admin.deployed.RO.detailed-status"] = "Looking for existing ns at RO"
+ # self.logger.debug(logging_text + step + " RO_ns_id={}".format(RO_nsr_id))
+ desc = await self.RO.show("ns", RO_nsr_id)
+ except ROclient.ROClientException as e:
+ if e.http_code != HTTPStatus.NOT_FOUND:
+ raise
+ RO_nsr_id = db_nsr_update["_admin.deployed.RO.nsr_id"] = None
+ if RO_nsr_id:
+ ns_status, ns_status_info = self.RO.check_ns_status(desc)
+ db_nsr_update["_admin.deployed.RO.nsr_status"] = ns_status
+ if ns_status == "ERROR":
+ step = db_nsr_update["_admin.deployed.RO.detailed-status"] = "Deleting ns at RO. RO_ns_id={}"\
+ .format(RO_nsr_id)
+ self.logger.debug(logging_text + step)
+ await self.RO.delete("ns", RO_nsr_id)
+ RO_nsr_id = db_nsr_update["_admin.deployed.RO.nsr_id"] = None
+ if not RO_nsr_id:
+ step = db_nsr_update["_admin.deployed.RO.detailed-status"] = "Checking dependencies"
+ # self.logger.debug(logging_text + step)
+
+ # check if VIM is creating and wait look if previous tasks in process
+ task_name, task_dependency = self.lcm_tasks.lookfor_related("vim_account", ns_params["vimAccountId"])
+ if task_dependency:
+ step = "Waiting for related tasks to be completed: {}".format(task_name)
+ self.logger.debug(logging_text + step)
+ await asyncio.wait(task_dependency, timeout=3600)
+ if ns_params.get("vnf"):
+ for vnf in ns_params["vnf"]:
+ if "vimAccountId" in vnf:
+ task_name, task_dependency = self.lcm_tasks.lookfor_related("vim_account",
+ vnf["vimAccountId"])
+ if task_dependency:
+ step = "Waiting for related tasks to be completed: {}".format(task_name)
+ self.logger.debug(logging_text + step)
+ await asyncio.wait(task_dependency, timeout=3600)
+
+ step = db_nsr_update["_admin.deployed.RO.detailed-status"] = "Checking instantiation parameters"
+
+ RO_ns_params = self.ns_params_2_RO(ns_params, nsd, db_vnfds_ref, n2vc_key_list)
+
+ step = db_nsr_update["detailed-status"] = "Deploying ns at VIM"
+ # step = db_nsr_update["_admin.deployed.RO.detailed-status"] = "Deploying ns at VIM"
+ desc = await self.RO.create("ns", descriptor=RO_ns_params, name=db_nsr["name"], scenario=RO_nsd_uuid)
+ RO_nsr_id = db_nsr_update["_admin.deployed.RO.nsr_id"] = desc["uuid"]
+ db_nsr_update["_admin.nsState"] = "INSTANTIATED"
+ db_nsr_update["_admin.deployed.RO.nsr_status"] = "BUILD"
+ self.logger.debug(logging_text + "ns created at RO. RO_id={}".format(desc["uuid"]))
+ self.update_db_2("nsrs", nsr_id, db_nsr_update)
+ self._on_update_n2vc_db("nsrs", {"_id": nsr_id}, "_admin.deployed", db_nsr_update)
+
+ # wait until NS is ready
+ step = ns_status_detailed = detailed_status = "Waiting VIM to deploy ns. RO_ns_id={}".format(RO_nsr_id)
+ detailed_status_old = None
+ self.logger.debug(logging_text + step)
+
+ while time() <= start_deploy + self.total_deploy_timeout:
+ desc = await self.RO.show("ns", RO_nsr_id)
+ ns_status, ns_status_info = self.RO.check_ns_status(desc)
+ db_nsr_update["_admin.deployed.RO.nsr_status"] = ns_status
+ if ns_status == "ERROR":
+ raise ROclient.ROClientException(ns_status_info)
+ elif ns_status == "BUILD":
+ detailed_status = ns_status_detailed + "; {}".format(ns_status_info)
+ elif ns_status == "ACTIVE":
+ step = detailed_status = "Waiting for management IP address reported by the VIM. Updating VNFRs"
+ try:
+ if vdu_flag:
+ self.ns_update_vnfr(db_vnfrs, desc)
+ break
+ except LcmExceptionNoMgmtIP:
+ pass
+ else:
+ assert False, "ROclient.check_ns_status returns unknown {}".format(ns_status)
+ if detailed_status != detailed_status_old:
+ detailed_status_old = db_nsr_update["_admin.deployed.RO.detailed-status"] = detailed_status
+ self.update_db_2("nsrs", nsr_id, db_nsr_update)
+ self._on_update_n2vc_db("nsrs", {"_id": nsr_id}, "_admin.deployed", db_nsr_update)
+ await asyncio.sleep(5, loop=self.loop)
+ else: # total_deploy_timeout
+ raise ROclient.ROClientException("Timeout waiting ns to be ready")
+
+ step = "Updating NSR"
+ self.ns_update_nsr(db_nsr_update, db_nsr, desc)
+
+ db_nsr_update["_admin.deployed.RO.operational-status"] = "running"
+ db_nsr["_admin.deployed.RO.detailed-status"] = "Deployed at VIM"
+ db_nsr_update["_admin.deployed.RO.detailed-status"] = "Deployed at VIM"
+ self.update_db_2("nsrs", nsr_id, db_nsr_update)
+ self._on_update_n2vc_db("nsrs", {"_id": nsr_id}, "_admin.deployed", db_nsr_update)
+
+ step = "Deployed at VIM"
+ self.logger.debug(logging_text + step)
+
+ async def wait_vm_up_insert_key_ro(self, logging_text, nsr_id, vnfr_id, vdu_id, vdu_index, pub_key=None, user=None):
+ """
+ Wait for ip addres at RO, and optionally, insert public key in virtual machine
+ :param logging_text: prefix use for logging
+ :param nsr_id:
+ :param vnfr_id:
+ :param vdu_id:
+ :param vdu_index:
+ :param pub_key: public ssh key to inject, None to skip
+ :param user: user to apply the public ssh key
+ :return: IP address
+ """
+
+ # self.logger.debug(logging_text + "Starting wait_vm_up_insert_key_ro")
+ ro_nsr_id = None
+ ip_address = None
+ nb_tries = 0
+ target_vdu_id = None
+ ro_retries = 0
+
+ while True:
+
+ ro_retries += 1
+ if ro_retries >= 360: # 1 hour
+ raise LcmException("Not found _admin.deployed.RO.nsr_id for nsr_id: {}".format(nsr_id))
+
+ await asyncio.sleep(10, loop=self.loop)
+ # wait until NS is deployed at RO
+ if not ro_nsr_id:
+ db_nsrs = self.db.get_one("nsrs", {"_id": nsr_id})
+ ro_nsr_id = deep_get(db_nsrs, ("_admin", "deployed", "RO", "nsr_id"))
+ if not ro_nsr_id:
+ continue
+
+ # get ip address
+ if not target_vdu_id:
+ db_vnfr = self.db.get_one("vnfrs", {"_id": vnfr_id})
+
+ if not vdu_id: # for the VNF case
+ ip_address = db_vnfr.get("ip-address")
+ if not ip_address:
+ continue
+ vdur = next((x for x in get_iterable(db_vnfr, "vdur") if x.get("ip-address") == ip_address), None)
+ else: # VDU case
+ vdur = next((x for x in get_iterable(db_vnfr, "vdur")
+ if x.get("vdu-id-ref") == vdu_id and x.get("count-index") == vdu_index), None)
+
+ if not vdur:
+ raise LcmException("Not found vnfr_id={}, vdu_index={}, vdu_index={}".format(
+ vnfr_id, vdu_id, vdu_index
+ ))
+
+ if vdur.get("status") == "ACTIVE":
+ ip_address = vdur.get("ip-address")
+ if not ip_address:
+ continue
+ target_vdu_id = vdur["vdu-id-ref"]
+ elif vdur.get("status") == "ERROR":
+ raise LcmException("Cannot inject ssh-key because target VM is in error state")
+
+ if not target_vdu_id:
+ continue
+
+ # self.logger.debug(logging_text + "IP address={}".format(ip_address))
+
+ # inject public key into machine
+ if pub_key and user:
+ # self.logger.debug(logging_text + "Inserting RO key")
+ try:
+ ro_vm_id = "{}-{}".format(db_vnfr["member-vnf-index-ref"], target_vdu_id) # TODO add vdu_index
+ result_dict = await self.RO.create_action(
+ item="ns",
+ item_id_name=ro_nsr_id,
+ descriptor={"add_public_key": pub_key, "vms": [ro_vm_id], "user": user}
+ )
+ # result_dict contains the format {VM-id: {vim_result: 200, description: text}}
+ if not result_dict or not isinstance(result_dict, dict):
+ raise LcmException("Unknown response from RO when injecting key")
+ for result in result_dict.values():
+ if result.get("vim_result") == 200:
+ break
+ else:
+ raise ROclient.ROClientException("error injecting key: {}".format(
+ result.get("description")))
+ break
+ except ROclient.ROClientException as e:
+ if not nb_tries:
+ self.logger.debug(logging_text + "error injecting key: {}. Retrying until {} seconds".
+ format(e, 20*10))
+ nb_tries += 1
+ if nb_tries >= 20:
+ raise LcmException("Reaching max tries injecting key. Error: {}".format(e))
+ else:
+ break
+
+ return ip_address
+
+ async def _wait_dependent_n2vc(self, nsr_id, vca_deployed_list, vca_index):
+ """
+ Wait until dependent VCA deployments have been finished. NS wait for VNFs and VDUs. VNFs for VDUs
+ """
+ my_vca = vca_deployed_list[vca_index]
+ if my_vca.get("vdu_id") or my_vca.get("kdu_name"):
+ return
+ timeout = 300
+ while timeout >= 0:
+ for index, vca_deployed in enumerate(vca_deployed_list):
+ if index == vca_index:
+ continue
+ if not my_vca.get("member-vnf-index") or \
+ (vca_deployed.get("member-vnf-index") == my_vca.get("member-vnf-index")):
+ if not vca_deployed.get("instantiation"):
+ break # wait
+ if vca_deployed["instantiation"] == "FAILED":
+ raise LcmException("Configuration aborted because dependent charm/s has failed")
+ else:
+ return
+ await asyncio.sleep(10)
+ timeout -= 1
+ db_nsr = self.db.get_one("nsrs", {"_id": nsr_id})
+ vca_deployed_list = db_nsr["_admin"]["deployed"]["VCA"]
+
+ raise LcmException("Configuration aborted because dependent charm/s timeout")
+
+ async def instantiate_N2VC(self, logging_text, vca_index, nsi_id, db_nsr, db_vnfr, vdu_id,
+ kdu_name, vdu_index, config_descriptor, deploy_params, base_folder):
+ nsr_id = db_nsr["_id"]
+ db_update_entry = "_admin.deployed.VCA.{}.".format(vca_index)
+ vca_deployed_list = db_nsr["_admin"]["deployed"]["VCA"]
+ vca_deployed = db_nsr["_admin"]["deployed"]["VCA"][vca_index]
+ db_dict = {
+ 'collection': 'nsrs',
+ 'filter': {'_id': nsr_id},
+ 'path': db_update_entry
+ }
+ step = ""
+ try:
+ vnfr_id = None
+ if db_vnfr:
+ vnfr_id = db_vnfr["_id"]
+
+ namespace = "{nsi}.{ns}".format(
+ nsi=nsi_id if nsi_id else "",
+ ns=nsr_id)
+ if vnfr_id:
+ namespace += "." + vnfr_id
+ if vdu_id:
+ namespace += ".{}-{}".format(vdu_id, vdu_index or 0)
+
+ # Get artifact path
+ artifact_path = "{}/{}/charms/{}".format(
+ base_folder["folder"],
+ base_folder["pkg-dir"],
+ config_descriptor["juju"]["charm"]
+ )
+
+ is_proxy_charm = deep_get(config_descriptor, ('juju', 'charm')) is not None
+ if deep_get(config_descriptor, ('juju', 'proxy')) is False:
+ is_proxy_charm = False
+
+ # n2vc_redesign STEP 3.1
+
+ # find old ee_id if exists
+ ee_id = vca_deployed.get("ee_id")
+
+ # create or register execution environment in VCA
+ if is_proxy_charm:
+ step = "create execution environment"
+ self.logger.debug(logging_text + step)
+ ee_id, credentials = await self.n2vc.create_execution_environment(namespace=namespace,
+ reuse_ee_id=ee_id,
+ db_dict=db_dict)
+ else:
+ step = "Waiting to VM being up and getting IP address"
+ self.logger.debug(logging_text + step)
+ rw_mgmt_ip = await self.wait_vm_up_insert_key_ro(logging_text, nsr_id, vnfr_id, vdu_id, vdu_index,
+ user=None, pub_key=None)
+ credentials = {"hostname": rw_mgmt_ip}
+ # get username
+ username = deep_get(config_descriptor, ("config-access", "ssh-access", "default-user"))
+ # TODO remove this when changes on IM regarding config-access:ssh-access:default-user were
+ # merged. Meanwhile let's get username from initial-config-primitive
+ if not username and config_descriptor.get("initial-config-primitive"):
+ for config_primitive in config_descriptor["initial-config-primitive"]:
+ for param in config_primitive.get("parameter", ()):
+ if param["name"] == "ssh-username":
+ username = param["value"]
+ break
+ if not username:
+ raise LcmException("Cannot determine the username neither with 'initial-config-promitive' nor with "
+ "'config-access.ssh-access.default-user'")
+ credentials["username"] = username
+ # n2vc_redesign STEP 3.2
+
+ step = "register execution environment {}".format(credentials)
+ self.logger.debug(logging_text + step)
+ ee_id = await self.n2vc.register_execution_environment(credentials=credentials, namespace=namespace,
+ db_dict=db_dict)
+
+ # for compatibility with MON/POL modules, the need model and application name at database
+ # TODO ask to N2VC instead of assuming the format "model_name.application_name"
+ ee_id_parts = ee_id.split('.')
+ model_name = ee_id_parts[0]
+ application_name = ee_id_parts[1]
+ self.update_db_2("nsrs", nsr_id, {db_update_entry + "model": model_name,
+ db_update_entry + "application": application_name,
+ db_update_entry + "ee_id": ee_id})
+
+ # n2vc_redesign STEP 3.3
+
+ step = "Install configuration Software"
+ # TODO check if already done
+ self.logger.debug(logging_text + step)
+ await self.n2vc.install_configuration_sw(ee_id=ee_id, artifact_path=artifact_path, db_dict=db_dict)
+
+ # if SSH access is required, then get execution environment SSH public
+ if is_proxy_charm: # if native charm we have waited already to VM be UP
+ pub_key = None
+ user = None
+ if deep_get(config_descriptor, ("config-access", "ssh-access", "required")):
+ # Needed to inject a ssh key
+ user = deep_get(config_descriptor, ("config-access", "ssh-access", "default-user"))
+ step = "Install configuration Software, getting public ssh key"
+ pub_key = await self.n2vc.get_ee_ssh_public__key(ee_id=ee_id, db_dict=db_dict)
+
+ step = "Insert public key into VM user={} ssh_key={}".format(user, pub_key)
+ else:
+ step = "Waiting to VM being up and getting IP address"
+ self.logger.debug(logging_text + step)
+
+ # n2vc_redesign STEP 5.1
+ # wait for RO (ip-address) Insert pub_key into VM
+ if vnfr_id:
+ rw_mgmt_ip = await self.wait_vm_up_insert_key_ro(logging_text, nsr_id, vnfr_id, vdu_id, vdu_index,
+ user=user, pub_key=pub_key)
+ else:
+ rw_mgmt_ip = None # This is for a NS configuration
+
+ self.logger.debug(logging_text + ' VM_ip_address={}'.format(rw_mgmt_ip))
+
+ # store rw_mgmt_ip in deploy params for later replacement
+ deploy_params["rw_mgmt_ip"] = rw_mgmt_ip
+
+ # n2vc_redesign STEP 6 Execute initial config primitive
+ step = 'execute initial config primitive'
+ initial_config_primitive_list = config_descriptor.get('initial-config-primitive')
+
+ # sort initial config primitives by 'seq'
+ try:
+ initial_config_primitive_list.sort(key=lambda val: int(val['seq']))
+ except Exception as e:
+ self.logger.error(logging_text + step + ": " + str(e))
+
+ # add config if not present for NS charm
+ initial_config_primitive_list = self._get_initial_config_primitive_list(initial_config_primitive_list,
+ vca_deployed)
+ if initial_config_primitive_list:
+ await self._wait_dependent_n2vc(nsr_id, vca_deployed_list, vca_index)
+ for initial_config_primitive in initial_config_primitive_list:
+ # adding information on the vca_deployed if it is a NS execution environment
+ if not vca_deployed["member-vnf-index"]:
+ deploy_params["ns_config_info"] = json.dumps(self._get_ns_config_info(nsr_id))
+ # TODO check if already done
+ primitive_params_ = self._map_primitive_params(initial_config_primitive, {}, deploy_params)
+
+ step = "execute primitive '{}' params '{}'".format(initial_config_primitive["name"], primitive_params_)
+ self.logger.debug(logging_text + step)
+ await self.n2vc.exec_primitive(
+ ee_id=ee_id,
+ primitive_name=initial_config_primitive["name"],
+ params_dict=primitive_params_,
+ db_dict=db_dict
+ )
+ # TODO register in database that primitive is done
+
+ step = "instantiated at VCA"
+ self.update_db_2("nsrs", nsr_id, {db_update_entry + "instantiation": "COMPLETED"})
+ self.logger.debug(logging_text + step)
+
+ except Exception as e: # TODO not use Exception but N2VC exception
+ self.update_db_2("nsrs", nsr_id, {db_update_entry + "instantiation": "FAILED"})
+ raise Exception("{} {}".format(step, e)) from e
+ # TODO raise N2VC exception with 'step' extra information
+
+ def _write_ns_status(self, nsr_id: str, ns_state: str, current_operation: str, current_operation_id: str,
+ error_description: str = None, error_detail: str = None):
+ try:
+ db_dict = dict()
+ if ns_state:
+ db_dict["nsState"] = ns_state
+ db_dict["currentOperation"] = current_operation
+ db_dict["currentOperationID"] = current_operation_id
+ db_dict["errorDescription"] = error_description
+ db_dict["errorDetail"] = error_detail
+ self.update_db_2("nsrs", nsr_id, db_dict)
+ except Exception as e:
+ self.logger.warn('Error writing NS status: {}'.format(e))