- 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("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"),
- 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
- 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"),
- ip_profile_2_RO(vld_params["ip-profile"]))
-
- 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}
- if RO_vld_ns_net:
- 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
-
- def scale_vnfr(self, db_vnfr, vdu_create=None, vdu_delete=None):
- # make a copy to do not change
- vdu_create = copy(vdu_create)
- vdu_delete = copy(vdu_delete)
-
- vdurs = db_vnfr.get("vdur")
- if vdurs is None:
- vdurs = []
- vdu_index = len(vdurs)
- while vdu_index:
- vdu_index -= 1
- vdur = vdurs[vdu_index]
- if vdur.get("pdu-type"):
- continue
- vdu_id_ref = vdur["vdu-id-ref"]
- if vdu_create and vdu_create.get(vdu_id_ref):
- for index in range(0, vdu_create[vdu_id_ref]):
- vdur = deepcopy(vdur)
- vdur["_id"] = str(uuid4())
- vdur["count-index"] += 1
- vdurs.insert(vdu_index+1+index, vdur)
- del vdu_create[vdu_id_ref]
- if vdu_delete and vdu_delete.get(vdu_id_ref):
- del vdurs[vdu_index]
- vdu_delete[vdu_id_ref] -= 1
- if not vdu_delete[vdu_id_ref]:
- del vdu_delete[vdu_id_ref]
- # check all operations are done
- if vdu_create or vdu_delete:
- raise LcmException("Error scaling OUT VNFR for {}. There is not any existing vnfr. Scaled to 0?".format(
- vdu_create))
- if vdu_delete:
- raise LcmException("Error scaling IN VNFR for {}. There is not any existing vnfr. Scaled to 0?".format(
- vdu_delete))