- def _ns_params_2_RO(self, ns_params, nsd, vnfd_dict, db_vnfrs, n2vc_key_list):
- """
- Creates a RO ns descriptor from OSM ns_instantiate params
- :param ns_params: OSM instantiate params
- :param vnfd_dict: database content of vnfds, indexed by id (not _id). {id: {vnfd_object}, ...}
- :param db_vnfrs: database content of vnfrs, indexed by member-vnf-index. {member-vnf-index: {vnfr_object}, ...}
- :return: The RO ns descriptor
- """
- vim_2_RO = {}
- wim_2_RO = {}
- # TODO feature 1417: Check that no instantiation is set over PDU
- # check if PDU forces a concrete vim-network-id and add it
- # check if PDU contains a SDN-assist info (dpid, switch, port) and pass it to RO
-
- def vim_account_2_RO(vim_account):
- if vim_account in vim_2_RO:
- return vim_2_RO[vim_account]
-
- db_vim = self.db.get_one("vim_accounts", {"_id": vim_account})
- if db_vim["_admin"]["operationalState"] != "ENABLED":
- raise LcmException("VIM={} is not available. operationalState={}".format(
- vim_account, db_vim["_admin"]["operationalState"]))
- RO_vim_id = db_vim["_admin"]["deployed"]["RO"]
- vim_2_RO[vim_account] = RO_vim_id
- return RO_vim_id
-
- def wim_account_2_RO(wim_account):
- if isinstance(wim_account, str):
- if wim_account in wim_2_RO:
- return wim_2_RO[wim_account]
-
- db_wim = self.db.get_one("wim_accounts", {"_id": wim_account})
- if db_wim["_admin"]["operationalState"] != "ENABLED":
- raise LcmException("WIM={} is not available. operationalState={}".format(
- wim_account, db_wim["_admin"]["operationalState"]))
- RO_wim_id = db_wim["_admin"]["deployed"]["RO-account"]
- wim_2_RO[wim_account] = RO_wim_id
- return RO_wim_id
- else:
- return wim_account
-
- if not ns_params:
- return None
- RO_ns_params = {
- # "name": ns_params["nsName"],
- # "description": ns_params.get("nsDescription"),
- "datacenter": vim_account_2_RO(ns_params["vimAccountId"]),
- "wim_account": wim_account_2_RO(ns_params.get("wimAccountId")),
- # "scenario": ns_params["nsdId"],
- }
- # set vim_account of each vnf if different from general vim_account.
- # Get this information from <vnfr> database content, key vim-account-id
- # Vim account can be set by placement_engine and it may be different from
- # the instantiate parameters (vnfs.member-vnf-index.datacenter).
- for vnf_index, vnfr in db_vnfrs.items():
- if vnfr.get("vim-account-id") and vnfr["vim-account-id"] != ns_params["vimAccountId"]:
- populate_dict(RO_ns_params, ("vnfs", vnf_index, "datacenter"), vim_account_2_RO(vnfr["vim-account-id"]))
-
- n2vc_key_list = n2vc_key_list or []
- for vnfd_ref, vnfd in vnfd_dict.items():
- vdu_needed_access = []
- mgmt_cp = None
- if vnfd.get("vnf-configuration"):
- ssh_required = deep_get(vnfd, ("vnf-configuration", "config-access", "ssh-access", "required"))
- if ssh_required and vnfd.get("mgmt-interface"):
- if vnfd["mgmt-interface"].get("vdu-id"):
- vdu_needed_access.append(vnfd["mgmt-interface"]["vdu-id"])
- elif vnfd["mgmt-interface"].get("cp"):
- mgmt_cp = vnfd["mgmt-interface"]["cp"]
-
- for vdu in vnfd.get("vdu", ()):
- if vdu.get("vdu-configuration"):
- ssh_required = deep_get(vdu, ("vdu-configuration", "config-access", "ssh-access", "required"))
- if ssh_required:
- vdu_needed_access.append(vdu["id"])
- elif mgmt_cp:
- for vdu_interface in vdu.get("interface"):
- if vdu_interface.get("external-connection-point-ref") and \
- vdu_interface["external-connection-point-ref"] == mgmt_cp:
- vdu_needed_access.append(vdu["id"])
- mgmt_cp = None
- break
-
- if vdu_needed_access:
- for vnf_member in nsd.get("constituent-vnfd"):
- if vnf_member["vnfd-id-ref"] != vnfd_ref:
- continue
- for vdu in vdu_needed_access:
- populate_dict(RO_ns_params,
- ("vnfs", vnf_member["member-vnf-index"], "vdus", vdu, "mgmt_keys"),
- n2vc_key_list)
- # cloud init
- for vdu in get_iterable(vnfd, "vdu"):
- cloud_init_text = self._get_cloud_init(vdu, vnfd)
- if not cloud_init_text:
- continue
- for vnf_member in nsd.get("constituent-vnfd"):
- if vnf_member["vnfd-id-ref"] != vnfd_ref:
- continue
- db_vnfr = db_vnfrs[vnf_member["member-vnf-index"]]
- additional_params = self._get_vdu_additional_params(db_vnfr, vdu["id"]) or {}
-
- cloud_init_list = []
- for vdu_index in range(0, int(vdu.get("count", 1))):
- additional_params["OSM"] = self._get_osm_params(db_vnfr, vdu["id"], vdu_index)
- cloud_init_list.append(self._parse_cloud_init(cloud_init_text, additional_params, vnfd["id"],
- vdu["id"]))
- populate_dict(RO_ns_params,
- ("vnfs", vnf_member["member-vnf-index"], "vdus", vdu["id"], "cloud_init"),
- cloud_init_list)
-
- if ns_params.get("vduImage"):
- RO_ns_params["vduImage"] = ns_params["vduImage"]
-
- if ns_params.get("ssh_keys"):
- RO_ns_params["cloud-config"] = {"key-pairs": ns_params["ssh_keys"]}
- for vnf_params in get_iterable(ns_params, "vnf"):
- for constituent_vnfd in nsd["constituent-vnfd"]:
- if constituent_vnfd["member-vnf-index"] == vnf_params["member-vnf-index"]:
- vnf_descriptor = vnfd_dict[constituent_vnfd["vnfd-id-ref"]]
- break
- else:
- raise LcmException("Invalid instantiate parameter vnf:member-vnf-index={} is not present at nsd:"
- "constituent-vnfd".format(vnf_params["member-vnf-index"]))
-
- for vdu_params in get_iterable(vnf_params, "vdu"):
- # TODO feature 1417: check that this VDU exist and it is not a PDU
- if vdu_params.get("volume"):
- for volume_params in vdu_params["volume"]:
- if volume_params.get("vim-volume-id"):
- populate_dict(RO_ns_params, ("vnfs", vnf_params["member-vnf-index"], "vdus",
- vdu_params["id"], "devices", volume_params["name"], "vim_id"),
- volume_params["vim-volume-id"])
- if vdu_params.get("interface"):
- for interface_params in vdu_params["interface"]:
- if interface_params.get("ip-address"):
- populate_dict(RO_ns_params, ("vnfs", vnf_params["member-vnf-index"], "vdus",
- vdu_params["id"], "interfaces", interface_params["name"],
- "ip_address"),
- interface_params["ip-address"])
- if interface_params.get("mac-address"):
- populate_dict(RO_ns_params, ("vnfs", vnf_params["member-vnf-index"], "vdus",
- vdu_params["id"], "interfaces", interface_params["name"],
- "mac_address"),
- interface_params["mac-address"])
- if interface_params.get("floating-ip-required"):
- populate_dict(RO_ns_params, ("vnfs", vnf_params["member-vnf-index"], "vdus",
- vdu_params["id"], "interfaces", interface_params["name"],
- "floating-ip"),
- interface_params["floating-ip-required"])
-
- for internal_vld_params in get_iterable(vnf_params, "internal-vld"):
- if internal_vld_params.get("vim-network-name"):
- populate_dict(RO_ns_params, ("vnfs", vnf_params["member-vnf-index"], "networks",
- internal_vld_params["name"], "vim-network-name"),
- internal_vld_params["vim-network-name"])
- if internal_vld_params.get("vim-network-id"):
- populate_dict(RO_ns_params, ("vnfs", vnf_params["member-vnf-index"], "networks",
- internal_vld_params["name"], "vim-network-id"),
- internal_vld_params["vim-network-id"])
- if internal_vld_params.get("ip-profile"):
- populate_dict(RO_ns_params, ("vnfs", vnf_params["member-vnf-index"], "networks",
- internal_vld_params["name"], "ip-profile"),
- self.ip_profile_2_RO(internal_vld_params["ip-profile"]))
- if internal_vld_params.get("provider-network"):
-
- populate_dict(RO_ns_params, ("vnfs", vnf_params["member-vnf-index"], "networks",
- internal_vld_params["name"], "provider-network"),
- internal_vld_params["provider-network"].copy())
-
- for icp_params in get_iterable(internal_vld_params, "internal-connection-point"):
- # look for interface
- iface_found = False
- for vdu_descriptor in vnf_descriptor["vdu"]:
- for vdu_interface in vdu_descriptor["interface"]:
- if vdu_interface.get("internal-connection-point-ref") == icp_params["id-ref"]:
- if icp_params.get("ip-address"):
- populate_dict(RO_ns_params, ("vnfs", vnf_params["member-vnf-index"], "vdus",
- vdu_descriptor["id"], "interfaces",
- vdu_interface["name"], "ip_address"),
- icp_params["ip-address"])
-
- if icp_params.get("mac-address"):
- populate_dict(RO_ns_params, ("vnfs", vnf_params["member-vnf-index"], "vdus",
- vdu_descriptor["id"], "interfaces",
- vdu_interface["name"], "mac_address"),
- icp_params["mac-address"])
- iface_found = True
- break
- if iface_found:
- break
- else:
- raise LcmException("Invalid instantiate parameter vnf:member-vnf-index[{}]:"
- "internal-vld:id-ref={} is not present at vnfd:internal-"
- "connection-point".format(vnf_params["member-vnf-index"],
- icp_params["id-ref"]))
-
- for vld_params in get_iterable(ns_params, "vld"):
- if "ip-profile" in vld_params:
- populate_dict(RO_ns_params, ("networks", vld_params["name"], "ip-profile"),
- self.ip_profile_2_RO(vld_params["ip-profile"]))
-
- if vld_params.get("provider-network"):
-
- populate_dict(RO_ns_params, ("networks", vld_params["name"], "provider-network"),
- vld_params["provider-network"].copy())
-
- if "wimAccountId" in vld_params and vld_params["wimAccountId"] is not None:
- populate_dict(RO_ns_params, ("networks", vld_params["name"], "wim_account"),
- wim_account_2_RO(vld_params["wimAccountId"])),
- if vld_params.get("vim-network-name"):
- RO_vld_sites = []
- if isinstance(vld_params["vim-network-name"], dict):
- for vim_account, vim_net in vld_params["vim-network-name"].items():
- RO_vld_sites.append({
- "netmap-use": vim_net,
- "datacenter": vim_account_2_RO(vim_account)
- })
- else: # isinstance str
- RO_vld_sites.append({"netmap-use": vld_params["vim-network-name"]})
- if RO_vld_sites:
- populate_dict(RO_ns_params, ("networks", vld_params["name"], "sites"), RO_vld_sites)
-
- if vld_params.get("vim-network-id"):
- RO_vld_sites = []
- if isinstance(vld_params["vim-network-id"], dict):
- for vim_account, vim_net in vld_params["vim-network-id"].items():
- RO_vld_sites.append({
- "netmap-use": vim_net,
- "datacenter": vim_account_2_RO(vim_account)
- })
- else: # isinstance str
- RO_vld_sites.append({"netmap-use": vld_params["vim-network-id"]})
- if RO_vld_sites:
- populate_dict(RO_ns_params, ("networks", vld_params["name"], "sites"), RO_vld_sites)
- if vld_params.get("ns-net"):
- if isinstance(vld_params["ns-net"], dict):
- for vld_id, instance_scenario_id in vld_params["ns-net"].items():
- RO_vld_ns_net = {"instance_scenario_id": instance_scenario_id, "osm_id": vld_id}
- populate_dict(RO_ns_params, ("networks", vld_params["name"], "use-network"), RO_vld_ns_net)
- if "vnfd-connection-point-ref" in vld_params:
- for cp_params in vld_params["vnfd-connection-point-ref"]:
- # look for interface
- for constituent_vnfd in nsd["constituent-vnfd"]:
- if constituent_vnfd["member-vnf-index"] == cp_params["member-vnf-index-ref"]:
- vnf_descriptor = vnfd_dict[constituent_vnfd["vnfd-id-ref"]]
- break
- else:
- raise LcmException(
- "Invalid instantiate parameter vld:vnfd-connection-point-ref:member-vnf-index-ref={} "
- "is not present at nsd:constituent-vnfd".format(cp_params["member-vnf-index-ref"]))
- match_cp = False
- for vdu_descriptor in vnf_descriptor["vdu"]:
- for interface_descriptor in vdu_descriptor["interface"]:
- if interface_descriptor.get("external-connection-point-ref") == \
- cp_params["vnfd-connection-point-ref"]:
- match_cp = True
- break
- if match_cp:
- break
- else:
- raise LcmException(
- "Invalid instantiate parameter vld:vnfd-connection-point-ref:member-vnf-index-ref={}:"
- "vnfd-connection-point-ref={} is not present at vnfd={}".format(
- cp_params["member-vnf-index-ref"],
- cp_params["vnfd-connection-point-ref"],
- vnf_descriptor["id"]))
- if cp_params.get("ip-address"):
- populate_dict(RO_ns_params, ("vnfs", cp_params["member-vnf-index-ref"], "vdus",
- vdu_descriptor["id"], "interfaces",
- interface_descriptor["name"], "ip_address"),
- cp_params["ip-address"])
- if cp_params.get("mac-address"):
- populate_dict(RO_ns_params, ("vnfs", cp_params["member-vnf-index-ref"], "vdus",
- vdu_descriptor["id"], "interfaces",
- interface_descriptor["name"], "mac_address"),
- cp_params["mac-address"])
- return RO_ns_params