: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
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
+
def ip_profile_2_RO(ip_profile):
RO_ip_profile = deepcopy((ip_profile))
if "dns-server" in RO_ip_profile:
# "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"],
}
if n2vc_key_list:
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):
continue
vnfr_update = {}
if vnf_RO.get("ip_address"):
- db_vnfr["ip-address"] = vnfr_update["ip-address"] = vnf_RO["ip_address"]
+ db_vnfr["ip-address"] = vnfr_update["ip-address"] = vnf_RO["ip_address"].split(";")[0]
elif not db_vnfr.get("ip-address"):
raise LcmExceptionNoMgmtIP("ns member_vnf_index '{}' has no IP address".format(vnf_index))
vdur_RO_count_index += 1
continue
vdur["vim-id"] = vdur_RO.get("vim_vm_id")
- vdur["ip-address"] = vdur_RO.get("ip_address")
+ if vdur_RO.get("ip_address"):
+ vdur["ip-address"] = vdur_RO["ip_address"].split(";")[0]
vdur["vdu-id-ref"] = vdur_RO.get("vdu_osm_id")
vdur["name"] = vdur_RO.get("vim_name")
vdur["status"] = vdur_RO.get("status")
db_nsr_update["detailed-status"] = "creating"
db_nsr_update["operational-status"] = "init"
+ if not db_nsr["_admin"].get("deployed") or not db_nsr["_admin"]["deployed"].get("RO") or \
+ not db_nsr["_admin"]["deployed"]["RO"].get("vnfd"):
+ populate_dict(db_nsr, ("_admin", "deployed", "RO", "vnfd"), [])
+ db_nsr_update["_admin.deployed.RO.vnfd"] = []
RO = ROclient.ROClient(self.loop, **self.ro_config)
# 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']]
vnfd_ref = vnfd["id"]
- step = db_nsr_update["detailed-status"] = "Creating vnfd={} at RO".format(vnfd_ref)
+ step = db_nsr_update["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 RO.get_list("vnfd", filter_by={"osm_id": vnfd_id_RO})
if vnfd_list:
- db_nsr_update["_admin.deployed.RO.vnfd_id.{}".format(vnfd_id)] = vnfd_list[0]["uuid"]
- self.logger.debug(logging_text + "vnfd={} exists at RO. Using RO_id={}".format(
- vnfd_ref, vnfd_list[0]["uuid"]))
+ 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 RO.create("vnfd", descriptor=vnfd_RO)
- db_nsr_update["_admin.deployed.RO.vnfd_id.{}".format(vnfd_id)] = desc["uuid"]
- self.logger.debug(logging_text + "vnfd={} created at RO. RO_id={}".format(
- vnfd_ref, desc["uuid"]))
+ 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)
# create nsd at RO
while time() <= start_deploy + self.total_deploy_timeout:
desc = await RO.show("ns", RO_nsr_id)
ns_status, ns_status_info = RO.check_ns_status(desc)
- db_nsr_update["admin.deployed.RO.nsr_status"] = ns_status
+ db_nsr_update["_admin.deployed.RO.nsr_status"] = ns_status
if ns_status == "ERROR":
raise ROclient.ROClientException(ns_status_info)
elif ns_status == "BUILD":
db_nsr_update = {"_admin.nslcmop": nslcmop_id}
db_nslcmop_update = {}
nslcmop_operation_state = None
+ autoremove = False # autoremove after terminated
try:
step = "Getting nslcmop={} from db".format(nslcmop_id)
db_nslcmop = self.db.get_one("nslcmops", {"_id": nslcmop_id})
self.logger.error(logging_text + failed_detail[-1])
RO_fail = True
- if not RO_fail and nsr_deployed and nsr_deployed.get("RO") and nsr_deployed["RO"].get("vnfd_id"):
- for vnf_id, RO_vnfd_id in nsr_deployed["RO"]["vnfd_id"].items():
- if not RO_vnfd_id:
+ if not RO_fail and nsr_deployed and nsr_deployed.get("RO") and nsr_deployed["RO"].get("vnfd"):
+ for index, vnf_deployed in enumerate(nsr_deployed["RO"]["vnfd"]):
+ if not vnf_deployed or not vnf_deployed["id"]:
continue
try:
+ RO_vnfd_id = vnf_deployed["id"]
step = db_nsr_update["detailed-status"] = db_nslcmop_update["detailed-status"] =\
- "Deleting vnfd={} at RO".format(vnf_id)
+ "Deleting member-vnf-index={} RO_vnfd_id={} from RO".format(
+ vnf_deployed["member-vnf-index"], RO_vnfd_id)
await RO.delete("vnfd", RO_vnfd_id)
self.logger.debug(logging_text + "RO_vnfd_id={} deleted".format(RO_vnfd_id))
- db_nsr_update["_admin.deployed.RO.vnfd_id.{}".format(vnf_id)] = None
+ db_nsr_update["_admin.deployed.RO.vnfd.{}.id".format(index)] = None
except ROclient.ROClientException as e:
if e.http_code == 404: # not found
- db_nsr_update["_admin.deployed.RO.vnfd_id.{}".format(vnf_id)] = None
+ db_nsr_update["_admin.deployed.RO.vnfd.{}.id".format(index)] = None
self.logger.debug(logging_text + "RO_vnfd_id={} already deleted ".format(RO_vnfd_id))
elif e.http_code == 409: # conflict
failed_detail.append("RO_vnfd_id={} delete conflict: {}".format(RO_vnfd_id, e))
db_nslcmop_update["detailed-status"] = "; ".join(failed_detail)
db_nslcmop_update["operationState"] = nslcmop_operation_state = "FAILED"
db_nslcmop_update["statusEnteredTime"] = time()
- elif db_nslcmop["operationParams"].get("autoremove"):
- self.db.del_one("nsrs", {"_id": nsr_id})
- db_nsr = None
- db_nsr_update.clear()
- self.db.del_list("nslcmops", {"nsInstanceId": nsr_id})
- db_nslcmop = None
- nslcmop_operation_state = "COMPLETED"
- db_nslcmop_update.clear()
- self.db.del_list("vnfrs", {"nsr-id-ref": nsr_id})
- self.db.set_list("pdus", {"_admin.usage.nsr_id": nsr_id},
- {"_admin.usageState": "NOT_IN_USE", "_admin.usage": None})
- self.logger.debug(logging_text + "Delete from database")
else:
db_nsr_update["operational-status"] = "terminated"
db_nsr_update["detailed-status"] = "Done"
db_nslcmop_update["detailed-status"] = "Done"
db_nslcmop_update["operationState"] = nslcmop_operation_state = "COMPLETED"
db_nslcmop_update["statusEnteredTime"] = time()
+ if db_nslcmop["operationParams"].get("autoremove"):
+ autoremove = True
except (ROclient.ROClientException, DbException) as e:
self.logger.error(logging_text + "Exit Exception {}".format(e))
if nslcmop_operation_state:
try:
await self.msg.aiowrite("ns", "terminated", {"nsr_id": nsr_id, "nslcmop_id": nslcmop_id,
- "operationState": nslcmop_operation_state},
+ "operationState": nslcmop_operation_state,
+ "autoremove": autoremove},
loop=self.loop)
except Exception as e:
self.logger.error(logging_text + "kafka_write notification Exception {}".format(e))