from osm_lcm.lcm_utils import LcmException, LcmBase, populate_dict, get_iterable, deep_get
from osm_common.dbbase import DbException
from time import time
from osm_lcm.lcm_utils import LcmException, LcmBase, populate_dict, get_iterable, deep_get
from osm_common.dbbase import DbException
from time import time
- def __init__(self, db, msg, fs, lcm_tasks, config, loop):
+ def __init__(self, db, msg, fs, lcm_tasks, config, loop, ns):
"""
Init, Connect to database, filesystem storage, and messaging
:param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
"""
Init, Connect to database, filesystem storage, and messaging
:param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
if nss_cp_item["nss-ref"] == nss["nss-id"]:
db_nsds = self.db.get_one("nsds", {"_id": nss["nsdId"]})
# Go for nsd, and search the CP that match with nst:CP to get vld-id-ref
if nss_cp_item["nss-ref"] == nss["nss-id"]:
db_nsds = self.db.get_one("nsds", {"_id": nss["nsdId"]})
# Go for nsd, and search the CP that match with nst:CP to get vld-id-ref
if cp_nsd["name"] == nss_cp_item["nsd-connection-point-ref"]:
if nslcmop.get("operationParams"):
if nslcmop["operationParams"].get("nsName") == nss["nsName"]:
if cp_nsd["name"] == nss_cp_item["nsd-connection-point-ref"]:
if nslcmop.get("operationParams"):
if nslcmop["operationParams"].get("nsName") == nss["nsName"]:
self.update_db_2("nsis", nsir_id, db_nsir_update)
db_nsir_update["_admin.deployed.RO"] = db_nsir_admin["deployed"]["RO"]
for vld_item in get_iterable(nsir_admin, "netslice-vld"):
await netslice_scenario_create(self, vld_item, nsir_id, db_nsir, db_nsir_admin, db_nsir_update)
self.update_db_2("nsis", nsir_id, db_nsir_update)
self.update_db_2("nsis", nsir_id, db_nsir_update)
db_nsir_update["_admin.deployed.RO"] = db_nsir_admin["deployed"]["RO"]
for vld_item in get_iterable(nsir_admin, "netslice-vld"):
await netslice_scenario_create(self, vld_item, nsir_id, db_nsir, db_nsir_admin, db_nsir_update)
self.update_db_2("nsis", nsir_id, db_nsir_update)
self.update_db_2("nsis", nsir_id, db_nsir_update)
db_nsir = self.db.get_one("nsis", {"_id": nsir_id})
self.update_db_2("nsis", nsir_id, db_nsir_update)
db_nsir = self.db.get_one("nsis", {"_id": nsir_id})
# self.update_db_2("nsis", nsir_id, db_nsir_update)
# Iterate over the network services operation ids to instantiate NSs
# self.update_db_2("nsis", nsir_id, db_nsir_update)
# Iterate over the network services operation ids to instantiate NSs
- # TODO: (future improvement) look another way check the tasks instead of keep asking
- # -> https://docs.python.org/3/library/asyncio-task.html#waiting-primitives
- # steps: declare ns_tasks, add task when terminate is called, await asyncio.wait(vca_task_list, timeout=300)
step = "Instantiating Netslice Subnets"
db_nsir = self.db.get_one("nsis", {"_id": nsir_id})
nslcmop_ids = db_nsilcmop["operationParams"].get("nslcmops_ids")
step = "Instantiating Netslice Subnets"
db_nsir = self.db.get_one("nsis", {"_id": nsir_id})
nslcmop_ids = db_nsilcmop["operationParams"].get("nslcmops_ids")
self.lcm_tasks.register("ns", nsr_id, nslcmop_id, "ns_instantiate", task)
# Wait until Network Slice is ready
self.lcm_tasks.register("ns", nsr_id, nslcmop_id, "ns_instantiate", task)
# Wait until Network Slice is ready
while time() <= start_deploy + timeout_nsi_deploy:
# Check ns instantiation status
nsi_ready = True
nsir = self.db.get_one("nsis", {"_id": nsir_id})
while time() <= start_deploy + timeout_nsi_deploy:
# Check ns instantiation status
nsi_ready = True
nsir = self.db.get_one("nsis", {"_id": nsir_id})
nsrs_detailed_list = nsir["_admin"]["nsrs-detailed-list"]
nsrs_detailed_list_new = []
for nslcmop_item in nslcmop_ids:
nsrs_detailed_list = nsir["_admin"]["nsrs-detailed-list"]
nsrs_detailed_list_new = []
for nslcmop_item in nslcmop_ids:
for nss in nsrs_detailed_list:
if nss["nsrId"] == nslcmop["nsInstanceId"]:
nss.update({"nsrId": nslcmop["nsInstanceId"], "status": nslcmop["operationState"],
for nss in nsrs_detailed_list:
if nss["nsrId"] == nslcmop["nsInstanceId"]:
nss.update({"nsrId": nslcmop["nsInstanceId"], "status": nslcmop["operationState"],
"instantiated": True})
nsrs_detailed_list_new.append(nss)
if status not in ["COMPLETED", "PARTIALLY_COMPLETED", "FAILED", "FAILED_TEMP"]:
"instantiated": True})
nsrs_detailed_list_new.append(nss)
if status not in ["COMPLETED", "PARTIALLY_COMPLETED", "FAILED", "FAILED_TEMP"]:
- step = "Network Slice Instance is ready. nsi_id={}".format(nsir_id)
- for items in nsrs_detailed_list:
- if "FAILED" in items.values():
- raise LcmException("Error deploying NSI: {}".format(nsir_id))
+ error_list = []
+ step = "Network Slice Instance instantiated"
+ for nss in nsrs_detailed_list:
+ if nss["status"] in ("FAILED", "FAILED_TEMP"):
+ error_list.append("NS {} {}: {}".format(nss["nsrId"], nss["status"],
+ nss["detailed-status"]))
+ if error_list:
+ step = "instantiating"
+ raise LcmException("; ".join(error_list))
break
# TODO: future improvement due to synchronism -> await asyncio.wait(vca_task_list, timeout=300)
await asyncio.sleep(5, loop=self.loop)
else: # timeout_nsi_deploy reached:
break
# TODO: future improvement due to synchronism -> await asyncio.wait(vca_task_list, timeout=300)
await asyncio.sleep(5, loop=self.loop)
else: # timeout_nsi_deploy reached:
if db_nsir:
db_nsir_update["detailed-status"] = "ERROR {}: {}".format(step, exc)
db_nsir_update["operational-status"] = "failed"
if db_nsir:
db_nsir_update["detailed-status"] = "ERROR {}: {}".format(step, exc)
db_nsir_update["operational-status"] = "failed"
if db_nsilcmop:
db_nsilcmop_update["detailed-status"] = "FAILED {}: {}".format(step, exc)
db_nsilcmop_update["operationState"] = nsilcmop_operation_state = "FAILED"
db_nsilcmop_update["statusEnteredTime"] = time()
try:
if db_nsir:
if db_nsilcmop:
db_nsilcmop_update["detailed-status"] = "FAILED {}: {}".format(step, exc)
db_nsilcmop_update["operationState"] = nsilcmop_operation_state = "FAILED"
db_nsilcmop_update["statusEnteredTime"] = time()
try:
if db_nsir:
db_nsir_update["_admin.nsilcmop"] = None
self.update_db_2("nsis", nsir_id, db_nsir_update)
if db_nsilcmop:
db_nsir_update["_admin.nsilcmop"] = None
self.update_db_2("nsis", nsir_id, db_nsir_update)
if db_nsilcmop: