- if ns_params.get("ssh-authorized-key"):
- RO_ns_params["cloud-config"] = {"key-pairs": ns_params["ssh-authorized-key"]}
- if ns_params.get("vnf"):
- for vnf_params in 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"]))
- RO_vnf = {"vdus": {}, "networks": {}}
- if vnf_params.get("vimAccountId"):
- RO_vnf["datacenter"] = vim_account_2_RO(vnf_params["vimAccountId"])
- if vnf_params.get("vdu"):
- for vdu_params in vnf_params["vdu"]:
- RO_vnf["vdus"][vdu_params["id"]] = {}
- if vdu_params.get("volume"):
- RO_vnf["vdus"][vdu_params["id"]]["devices"] = {}
- for volume_params in vdu_params["volume"]:
- RO_vnf["vdus"][vdu_params["id"]]["devices"][volume_params["name"]] = {}
- if volume_params.get("vim-volume-id"):
- RO_vnf["vdus"][vdu_params["id"]]["devices"][volume_params["name"]]["vim_id"] = \
- volume_params["vim-volume-id"]
- if vdu_params.get("interface"):
- RO_vnf["vdus"][vdu_params["id"]]["interfaces"] = {}
- for interface_params in vdu_params["interface"]:
- RO_interface = {}
- RO_vnf["vdus"][vdu_params["id"]]["interfaces"][interface_params["name"]] = RO_interface
- if interface_params.get("ip-address"):
- RO_interface["ip_address"] = interface_params["ip-address"]
- if interface_params.get("mac-address"):
- RO_interface["mac_address"] = interface_params["mac-address"]
- if interface_params.get("floating-ip-required"):
- RO_interface["floating-ip"] = interface_params["floating-ip-required"]
- if vnf_params.get("internal-vld"):
- for internal_vld_params in vnf_params["internal-vld"]:
- RO_vnf["networks"][internal_vld_params["name"]] = {}
- if internal_vld_params.get("vim-network-name"):
- RO_vnf["networks"][internal_vld_params["name"]]["vim-network-name"] = \
- internal_vld_params["vim-network-name"]
- if internal_vld_params.get("ip-profile"):
- RO_vnf["networks"][internal_vld_params["name"]]["ip-profile"] = \
- ip_profile_2_RO(internal_vld_params["ip-profile"])
- if internal_vld_params.get("internal-connection-point"):
- for icp_params in 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"]:
- RO_interface_update = {}
- if icp_params.get("ip-address"):
- RO_interface_update["ip_address"] = icp_params["ip-address"]
- if icp_params.get("mac-address"):
- RO_interface_update["mac_address"] = icp_params["mac-address"]
- if RO_interface_update:
- RO_vnf_update = {"vdus": {vdu_descriptor["id"]: {
- "interfaces": {vdu_interface["name"]: RO_interface_update}}}}
- deep_update(RO_vnf, RO_vnf_update)
- 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"]))
-
- if not RO_vnf["vdus"]:
- del RO_vnf["vdus"]
- if not RO_vnf["networks"]:
- del RO_vnf["networks"]
- if RO_vnf:
- RO_ns_params["vnfs"][vnf_params["member-vnf-index"]] = RO_vnf
- if ns_params.get("vld"):
- for vld_params in ns_params["vld"]:
- RO_vld = {}
- if "ip-profile" in vld_params:
- RO_vld["ip-profile"] = ip_profile_2_RO(vld_params["ip-profile"])
- if "vim-network-name" in vld_params:
- 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 "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"]]
+ 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"]))
+ if vnf_params.get("vimAccountId"):
+ populate_dict(RO_ns_params, ("vnfs", vnf_params["member-vnf-index"], "datacenter"),
+ vim_account_2_RO(vnf_params["vimAccountId"]))
+
+ 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("ip-profile"):
+ populate_dict(RO_ns_params, ("vnfs", vnf_params["member-vnf-index"], "networks",
+ internal_vld_params["name"], "ip-profile"),
+ ip_profile_2_RO(internal_vld_params["ip-profile"]))
+
+ 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