+ ns_params = db_nslcmop.get("operationParams")
+ ssh_keys_instantiation = ns_params.get("ssh_keys") or []
+ ssh_keys_all = ssh_keys_instantiation + (n2vc_key_list or [])
+
+ cp2target = {}
+ for vld_index, vld in enumerate(db_nsr.get("vld")):
+ target_vim = "vim:{}".format(ns_params["vimAccountId"])
+ target_vld = {
+ "id": vld["id"],
+ "name": vld["name"],
+ "mgmt-network": vld.get("mgmt-network", False),
+ "type": vld.get("type"),
+ "vim_info": {
+ target_vim: {
+ "vim_network_name": vld.get("vim-network-name"),
+ "vim_account_id": ns_params["vimAccountId"]
+ }
+ }
+ }
+ # check if this network needs SDN assist
+ if vld.get("pci-interfaces"):
+ db_vim = VimAccountDB.get_vim_account_with_id(target_vld["vim_info"][0]["vim_account_id"])
+ sdnc_id = db_vim["config"].get("sdn-controller")
+ if sdnc_id:
+ target_vld["vim_info"].append({"sdnc_id": sdnc_id})
+
+ nsd_vnf_profiles = get_vnf_profiles(nsd)
+ for nsd_vnf_profile in nsd_vnf_profiles:
+ for cp in nsd_vnf_profile["virtual-link-connectivity"]:
+ if cp["virtual-link-profile-id"] == vld["id"]:
+ cp2target["member_vnf:{}.{}".format(
+ cp["constituent-cpd-id"][0]["constituent-base-element-id"],
+ cp["constituent-cpd-id"][0]["constituent-cpd-id"]
+ )] = "nsrs:{}:vld.{}".format(nsr_id, vld_index)
+
+ # check at nsd descriptor, if there is an ip-profile
+ vld_params = {}
+ virtual_link_profiles = get_virtual_link_profiles(nsd)
+
+ for vlp in virtual_link_profiles:
+ ip_profile = find_in_list(nsd["ip-profiles"],
+ lambda profile: profile["name"] == vlp["ip-profile-ref"])
+ vld_params["ip-profile"] = ip_profile["ip-profile-params"]
+ # update vld_params with instantiation params
+ vld_instantiation_params = find_in_list(get_iterable(ns_params, "vld"),
+ lambda a_vld: a_vld["name"] in (vld["name"], vld["id"]))
+ if vld_instantiation_params:
+ vld_params.update(vld_instantiation_params)
+ parse_vld_instantiation_params(target_vim, target_vld, vld_params, None)
+ target["ns"]["vld"].append(target_vld)
+
+ for vnfr in db_vnfrs.values():
+ vnfd = find_in_list(db_vnfds, lambda db_vnf: db_vnf["id"] == vnfr["vnfd-ref"])
+ vnf_params = find_in_list(get_iterable(ns_params, "vnf"),
+ lambda a_vnf: a_vnf["member-vnf-index"] == vnfr["member-vnf-index-ref"])
+ target_vnf = deepcopy(vnfr)
+ target_vim = "vim:{}".format(vnfr["vim-account-id"])
+ for vld in target_vnf.get("vld", ()):
+ # check if connected to a ns.vld, to fill target'
+ vnf_cp = find_in_list(vnfd.get("int-virtual-link-desc", ()),
+ lambda cpd: cpd.get("id") == vld["id"])
+ if vnf_cp:
+ ns_cp = "member_vnf:{}.{}".format(vnfr["member-vnf-index-ref"], vnf_cp["id"])
+ if cp2target.get(ns_cp):
+ vld["target"] = cp2target[ns_cp]
+
+ vld["vim_info"] = {target_vim: {"vim_network_name": vld.get("vim-network-name")}}
+ # check if this network needs SDN assist
+ target_sdn = None
+ if vld.get("pci-interfaces"):
+ db_vim = get_vim_account(vnfr["vim-account-id"])
+ sdnc_id = db_vim["config"].get("sdn-controller")
+ if sdnc_id:
+ sdn_vld = "vnfrs:{}:vld.{}".format(target_vnf["_id"], vld["id"])
+ target_sdn = "sdn:{}".format(sdnc_id)
+ vld["vim_info"][target_sdn] = {
+ "sdn": True, "target_vim": target_vim, "vlds": [sdn_vld], "type": vld.get("type")}
+
+ # check at vnfd descriptor, if there is an ip-profile
+ vld_params = {}
+ vnfd_vlp = find_in_list(
+ get_virtual_link_profiles(vnfd),
+ lambda a_link_profile: a_link_profile["id"] == vld["id"]
+ )
+ if vnfd_vlp and vnfd_vlp.get("virtual-link-protocol-data") and \
+ vnfd_vlp["virtual-link-protocol-data"].get("l3-protocol-data"):
+ ip_profile_source_data = vnfd_vlp["virtual-link-protocol-data"]["l3-protocol-data"]
+ ip_profile_dest_data = {}
+ if "ip-version" in ip_profile_source_data:
+ ip_profile_dest_data["ip-version"] = ip_profile_source_data["ip-version"]
+ if "cidr" in ip_profile_source_data:
+ ip_profile_dest_data["subnet-address"] = ip_profile_source_data["cidr"]
+ if "gateway-ip" in ip_profile_source_data:
+ ip_profile_dest_data["gateway-address"] = ip_profile_source_data["gateway-ip"]
+ if "dhcp-enabled" in ip_profile_source_data:
+ ip_profile_dest_data["dhcp-params"] = {
+ "enabled": ip_profile_source_data["dhcp-enabled"]
+ }
+
+ vld_params["ip-profile"] = ip_profile_dest_data
+ # update vld_params with instantiation params
+ if vnf_params:
+ vld_instantiation_params = find_in_list(get_iterable(vnf_params, "internal-vld"),
+ lambda i_vld: i_vld["name"] == vld["id"])
+ if vld_instantiation_params:
+ vld_params.update(vld_instantiation_params)
+ parse_vld_instantiation_params(target_vim, vld, vld_params, target_sdn)
+
+ vdur_list = []
+ for vdur in target_vnf.get("vdur", ()):
+ if vdur.get("status") == "DELETING" or vdur.get("pdu-type"):
+ continue # This vdu must not be created
+ vdur["vim_info"] = {"vim_account_id": vnfr["vim-account-id"]}
+
+ self.logger.debug("NS > ssh_keys > {}".format(ssh_keys_all))
+
+ if ssh_keys_all:
+ vdu_configuration = get_vdu_configuration(vnfd, vdur["vdu-id-ref"])
+ vnf_configuration = get_vnf_configuration(vnfd)
+ if vdu_configuration and vdu_configuration.get("config-access") and \
+ vdu_configuration.get("config-access").get("ssh-access"):
+ vdur["ssh-keys"] = ssh_keys_all
+ vdur["ssh-access-required"] = vdu_configuration["config-access"]["ssh-access"]["required"]
+ elif vnf_configuration and vnf_configuration.get("config-access") and \
+ vnf_configuration.get("config-access").get("ssh-access") and \
+ any(iface.get("mgmt-vnf") for iface in vdur["interfaces"]):
+ vdur["ssh-keys"] = ssh_keys_all
+ vdur["ssh-access-required"] = vnf_configuration["config-access"]["ssh-access"]["required"]
+ elif ssh_keys_instantiation and \
+ find_in_list(vdur["interfaces"], lambda iface: iface.get("mgmt-vnf")):
+ vdur["ssh-keys"] = ssh_keys_instantiation
+
+ self.logger.debug("NS > vdur > {}".format(vdur))
+
+ vdud = get_vdu(vnfd, vdur["vdu-id-ref"])
+ # cloud-init
+ if vdud.get("cloud-init-file"):
+ vdur["cloud-init"] = "{}:file:{}".format(vnfd["_id"], vdud.get("cloud-init-file"))
+ # read file and put content at target.cloul_init_content. Avoid ng_ro to use shared package system
+ if vdur["cloud-init"] not in target["cloud_init_content"]:
+ base_folder = vnfd["_admin"]["storage"]
+ cloud_init_file = "{}/{}/cloud_init/{}".format(base_folder["folder"], base_folder["pkg-dir"],
+ vdud.get("cloud-init-file"))
+ with self.fs.file_open(cloud_init_file, "r") as ci_file:
+ target["cloud_init_content"][vdur["cloud-init"]] = ci_file.read()
+ elif vdud.get("cloud-init"):
+ vdur["cloud-init"] = "{}:vdu:{}".format(vnfd["_id"], get_vdu_index(vnfd, vdur["vdu-id-ref"]))
+ # put content at target.cloul_init_content. Avoid ng_ro read vnfd descriptor
+ target["cloud_init_content"][vdur["cloud-init"]] = vdud["cloud-init"]
+ vdur["additionalParams"] = vdur.get("additionalParams") or {}
+ deploy_params_vdu = self._format_additional_params(vdur.get("additionalParams") or {})
+ deploy_params_vdu["OSM"] = get_osm_params(vnfr, vdur["vdu-id-ref"], vdur["count-index"])
+ vdur["additionalParams"] = deploy_params_vdu
+
+ # flavor
+ ns_flavor = target["flavor"][int(vdur["ns-flavor-id"])]
+ if target_vim not in ns_flavor["vim_info"]:
+ ns_flavor["vim_info"][target_vim] = {}
+ # image
+ ns_image = target["image"][int(vdur["ns-image-id"])]
+ if target_vim not in ns_image["vim_info"]:
+ ns_image["vim_info"][target_vim] = {}
+
+ vdur["vim_info"] = {target_vim: {}}
+ # instantiation parameters
+ # if vnf_params:
+ # vdu_instantiation_params = next((v for v in get_iterable(vnf_params, "vdu") if v["id"] ==
+ # vdud["id"]), None)
+ vdur_list.append(vdur)
+ target_vnf["vdur"] = vdur_list
+ target["vnf"].append(target_vnf)
+
+ desc = await self.RO.deploy(nsr_id, target)
+ self.logger.debug("RO return > {}".format(desc))
+ action_id = desc["action_id"]
+ await self._wait_ng_ro(nsr_id, action_id, nslcmop_id, start_deploy, timeout_ns_deploy, stage)
+
+ # Updating NSR
+ db_nsr_update = {
+ "_admin.deployed.RO.operational-status": "running",
+ "detailed-status": " ".join(stage)
+ }
+ # db_nsr["_admin.deployed.RO.detailed-status"] = "Deployed at VIM"
+ self.update_db_2("nsrs", nsr_id, db_nsr_update)
+ self._write_op_status(nslcmop_id, stage)
+ self.logger.debug(logging_text + "ns deployed at RO. RO_id={}".format(action_id))
+ return