1 # -*- coding: utf-8 -*-
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
18 import logging
.handlers
20 from osm_lcm
import ROclient
21 from osm_lcm
.lcm_utils
import (
28 from osm_common
.dbbase
import DbException
30 from copy
import deepcopy
33 __author__
= "Felipe Vicens, Pol Alemany, Alfonso Tierno"
36 class NetsliceLcm(LcmBase
):
37 def __init__(self
, msg
, lcm_tasks
, config
, ns
):
39 Init, Connect to database, filesystem storage, and messaging
40 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
44 self
.logger
= logging
.getLogger("lcm.netslice")
45 self
.lcm_tasks
= lcm_tasks
47 self
.ro_config
= config
["RO"]
48 self
.timeout
= config
["timeout"]
50 super().__init
__(msg
, self
.logger
)
52 def nsi_update_nsir(self
, nsi_update_nsir
, db_nsir
, nsir_desc_RO
):
54 Updates database nsir with the RO info for the created vld
55 :param nsi_update_nsir: dictionary to be filled with the updated info
56 :param db_nsir: content of db_nsir. This is also modified
57 :param nsir_desc_RO: nsir descriptor from RO
58 :return: Nothing, LcmException is raised on errors
61 for vld_index
, vld
in enumerate(get_iterable(db_nsir
, "vld")):
62 for net_RO
in get_iterable(nsir_desc_RO
, "nets"):
63 if vld
["id"] != net_RO
.get("ns_net_osm_id"):
65 vld
["vim-id"] = net_RO
.get("vim_net_id")
66 vld
["name"] = net_RO
.get("vim_name")
67 vld
["status"] = net_RO
.get("status")
68 vld
["status-detailed"] = net_RO
.get("error_msg")
69 nsi_update_nsir
["vld.{}".format(vld_index
)] = vld
73 "ns_update_nsir: Not found vld={} at RO info".format(vld
["id"])
76 async def instantiate(self
, nsir_id
, nsilcmop_id
):
77 # Try to lock HA task here
78 task_is_locked_by_me
= self
.lcm_tasks
.lock_HA("nsi", "nsilcmops", nsilcmop_id
)
79 if not task_is_locked_by_me
:
82 logging_text
= "Task netslice={} instantiate={} ".format(nsir_id
, nsilcmop_id
)
83 self
.logger
.debug(logging_text
+ "Enter")
84 # get all needed from database
88 db_nsir_update
= {"_admin.nsilcmop": nsilcmop_id
}
89 db_nsilcmop_update
= {}
90 nsilcmop_operation_state
= None
92 RO
= ROclient
.ROClient(**self
.ro_config
)
93 nsi_vld_instantiationi_params
= {}
95 def ip_profile_2_RO(ip_profile
):
96 RO_ip_profile
= deepcopy((ip_profile
))
97 if "dns-server" in RO_ip_profile
:
98 if isinstance(RO_ip_profile
["dns-server"], list):
99 RO_ip_profile
["dns-address"] = []
100 for ds
in RO_ip_profile
.pop("dns-server"):
101 RO_ip_profile
["dns-address"].append(ds
["address"])
103 RO_ip_profile
["dns-address"] = RO_ip_profile
.pop("dns-server")
104 if RO_ip_profile
.get("ip-version") == "ipv4":
105 RO_ip_profile
["ip-version"] = "IPv4"
106 if RO_ip_profile
.get("ip-version") == "ipv6":
107 RO_ip_profile
["ip-version"] = "IPv6"
108 if "dhcp-params" in RO_ip_profile
:
109 RO_ip_profile
["dhcp"] = RO_ip_profile
.pop("dhcp-params")
112 def vim_account_2_RO(vim_account
):
114 Translate a RO vim_account from OSM vim_account params
115 :param ns_params: OSM instantiate params
116 :return: The RO ns descriptor
118 if vim_account
in vim_2_RO
:
119 return vim_2_RO
[vim_account
]
121 db_vim
= self
.db
.get_one("vim_accounts", {"_id": vim_account
})
122 if db_vim
["_admin"]["operationalState"] != "ENABLED":
124 "VIM={} is not available. operationalState={}".format(
125 vim_account
, db_vim
["_admin"]["operationalState"]
128 RO_vim_id
= db_vim
["_admin"]["deployed"]["RO"]
129 vim_2_RO
[vim_account
] = RO_vim_id
132 async def netslice_scenario_create(
133 self
, vld_item
, nsir_id
, db_nsir
, db_nsir_admin
, db_nsir_update
136 Create a network slice VLD through RO Scenario
137 :param vld_id The VLD id inside nsir to be created
138 :param nsir_id The nsir id
140 nonlocal nsi_vld_instantiationi_params
144 vld_id
= vld_item
["id"]
145 netslice_vld
= vld_item
146 # logging_text = "Task netslice={} instantiate_vld={} ".format(nsir_id, vld_id)
147 # self.logger.debug(logging_text + "Enter")
150 for shared_nsrs_item
in get_iterable(vld_item
, "shared-nsrs-list"):
153 "_admin.nsrs-detailed-list.ANYINDEX.nsrId": shared_nsrs_item
,
155 shared_nsi
= self
.db
.get_one(
156 "nsis", _filter
, fail_on_empty
=False, fail_on_more
=False
159 for vlds
in get_iterable(shared_nsi
["_admin"]["deployed"], "RO"):
160 if vld_id
== vlds
["vld_id"]:
162 "instance_scenario_id": vlds
["netslice_scenario_id"],
168 # Creating netslice-vld at RO
169 RO_nsir
= deep_get(db_nsir
, ("_admin", "deployed", "RO"), [])
171 if vld_id
in RO_nsir
:
172 db_nsir_update
["_admin.deployed.RO"] = RO_nsir
174 # If netslice-vld doesn't exists then create it
176 # TODO: Check VDU type in all descriptors finding SRIOV / PT
177 # Updating network names and datacenters from instantiation parameters for each VLD
178 for instantiation_params_vld
in get_iterable(
179 db_nsir
["instantiation_parameters"], "netslice-vld"
181 if instantiation_params_vld
.get("name") == netslice_vld
["name"]:
182 ip_vld
= deepcopy(instantiation_params_vld
)
184 nsi_vld_instantiationi_params
[netslice_vld
["name"]] = ip_vld
186 db_nsir_update_RO
= {}
187 db_nsir_update_RO
["vld_id"] = netslice_vld
["name"]
188 if self
.ro_config
["ng"]:
189 db_nsir_update_RO
["netslice_scenario_id"] = (
190 vld_shared
.get("instance_scenario_id")
192 else "nsir:{}:vld.{}".format(nsir_id
, netslice_vld
["name"])
194 else: # if not self.ro_config["ng"]:
195 if netslice_vld
.get("mgmt-network"):
198 RO_ns_params
["name"] = netslice_vld
["name"]
199 RO_ns_params
["datacenter"] = vim_account_2_RO(
200 db_nsir
["instantiation_parameters"]["vimAccountId"]
203 # Creating scenario if vim-network-name / vim-network-id are present as instantiation parameter
204 # Use vim-network-id instantiation parameter
205 vim_network_option
= None
207 if ip_vld
.get("vim-network-id"):
208 vim_network_option
= "vim-network-id"
209 elif ip_vld
.get("vim-network-name"):
210 vim_network_option
= "vim-network-name"
211 if ip_vld
.get("ip-profile"):
214 ("networks", netslice_vld
["name"], "ip-profile"),
215 ip_profile_2_RO(ip_vld
["ip-profile"]),
218 if vim_network_option
:
219 if ip_vld
.get(vim_network_option
):
220 if isinstance(ip_vld
.get(vim_network_option
), list):
221 for vim_net_id
in ip_vld
.get(vim_network_option
):
222 for vim_account
, vim_net
in vim_net_id
.items():
225 "netmap-use": vim_net
,
226 "datacenter": vim_account_2_RO(
231 elif isinstance(ip_vld
.get(vim_network_option
), dict):
232 for vim_account
, vim_net
in ip_vld
.get(
237 "netmap-use": vim_net
,
238 "datacenter": vim_account_2_RO(vim_account
),
244 "netmap-use": ip_vld
[vim_network_option
],
245 "datacenter": vim_account_2_RO(
246 netslice_vld
["vimAccountId"]
251 # Use default netslice vim-network-name from template
253 for nss_conn_point_ref
in get_iterable(
254 netslice_vld
, "nss-connection-point-ref"
256 if nss_conn_point_ref
.get("vimAccountId"):
258 nss_conn_point_ref
["vimAccountId"]
259 != netslice_vld
["vimAccountId"]
263 "netmap-create": None,
264 "datacenter": vim_account_2_RO(
265 nss_conn_point_ref
["vimAccountId"]
273 ("networks", netslice_vld
["name"], "use-network"),
280 ("networks", netslice_vld
["name"], "sites"),
284 RO_ns_params
["scenario"] = {
287 "name": netslice_vld
["name"],
288 "external": mgmt_network
,
294 # self.logger.debug(logging_text + step)
295 desc
= await RO
.create("ns", descriptor
=RO_ns_params
)
296 db_nsir_update_RO
["netslice_scenario_id"] = desc
["uuid"]
297 db_nsir_update
["_admin.deployed.RO"].append(db_nsir_update_RO
)
299 def overwrite_nsd_params(self
, db_nsir
, nslcmop
):
300 nonlocal nsi_vld_instantiationi_params
301 nonlocal db_nsir_update
304 nsr_id
= nslcmop
.get("nsInstanceId")
305 # Overwrite instantiation parameters in netslice runtime
306 RO_list
= db_nsir_admin
["deployed"]["RO"]
308 for ro_item_index
, RO_item
in enumerate(RO_list
):
312 for n
in get_iterable(db_nsir
["_admin"], "netslice-vld")
313 if RO_item
.get("vld_id") == n
.get("id")
319 # if is equal vld of _admin with vld of netslice-vld then go for the CPs
320 # Search the cp of netslice-vld that match with nst:netslice-subnet
321 for nss_cp_item
in get_iterable(
322 netslice_vld
, "nss-connection-point-ref"
324 # Search the netslice-subnet of nst that match
328 for nss
in get_iterable(
329 db_nsir
["_admin"], "netslice-subnet"
331 if nss_cp_item
["nss-ref"] == nss
["nss-id"]
335 # Compare nss-ref equal nss from nst
338 db_nsds
= self
.db
.get_one("nsds", {"_id": nss
["nsdId"]})
339 # Go for nsd, and search the CP that match with nst:CP to get vld-id-ref
340 for cp_nsd
in db_nsds
.get("sapd", ()):
341 if cp_nsd
["id"] == nss_cp_item
["nsd-connection-point-ref"]:
342 if nslcmop
.get("operationParams"):
344 nslcmop
["operationParams"].get("nsName")
347 vld_id
= RO_item
["vld_id"]
348 netslice_scenario_id
= RO_item
[
349 "netslice_scenario_id"
352 nslcmop_vld
["name"] = cp_nsd
["virtual-link-desc"]
353 for vld
in get_iterable(
354 nslcmop
["operationParams"], "vld"
356 if vld
["name"] == cp_nsd
["virtual-link-desc"]:
357 nslcmop_vld
.update(vld
)
358 if self
.ro_config
["ng"]:
359 nslcmop_vld
["common_id"] = netslice_scenario_id
361 nsi_vld_instantiationi_params
.get(
362 RO_item
["vld_id"], {}
366 nslcmop_vld
["ns-net"] = {
367 vld_id
: netslice_scenario_id
369 vld_op_list
.append(nslcmop_vld
)
370 nslcmop
["operationParams"]["vld"] = vld_op_list
372 "nslcmops", nslcmop
["_id"], {"operationParams.vld": vld_op_list
}
374 return nsr_id
, nslcmop
377 # wait for any previous tasks in process
378 await self
.lcm_tasks
.waitfor_related_HA("nsi", "nsilcmops", nsilcmop_id
)
380 step
= "Getting nsir={} from db".format(nsir_id
)
381 db_nsir
= self
.db
.get_one("nsis", {"_id": nsir_id
})
382 step
= "Getting nsilcmop={} from db".format(nsilcmop_id
)
383 db_nsilcmop
= self
.db
.get_one("nsilcmops", {"_id": nsilcmop_id
})
385 start_deploy
= time()
386 nsi_params
= db_nsilcmop
.get("operationParams")
387 if nsi_params
and nsi_params
.get("timeout_nsi_deploy"):
388 timeout_nsi_deploy
= nsi_params
["timeout_nsi_deploy"]
390 timeout_nsi_deploy
= self
.timeout
.get("nsi_deploy")
392 # Empty list to keep track of network service records status in the netslice
393 nsir_admin
= db_nsir_admin
= db_nsir
.get("_admin")
395 step
= "Creating slice operational-status init"
396 # Slice status Creating
397 db_nsir_update
["detailed-status"] = "creating"
398 db_nsir_update
["operational-status"] = "init"
399 db_nsir_update
["_admin.nsiState"] = "INSTANTIATED"
401 step
= "Instantiating netslice VLDs before NS instantiation"
402 # Creating netslice VLDs networking before NS instantiation
403 db_nsir_update
["detailed-status"] = step
404 self
.update_db_2("nsis", nsir_id
, db_nsir_update
)
405 db_nsir_update
["_admin.deployed.RO"] = db_nsir_admin
["deployed"]["RO"]
406 for vld_item
in get_iterable(nsir_admin
, "netslice-vld"):
407 await netslice_scenario_create(
408 self
, vld_item
, nsir_id
, db_nsir
, db_nsir_admin
, db_nsir_update
411 step
= "Instantiating netslice subnets"
412 db_nsir_update
["detailed-status"] = step
413 self
.update_db_2("nsis", nsir_id
, db_nsir_update
)
415 db_nsir
= self
.db
.get_one("nsis", {"_id": nsir_id
})
417 # Check status of the VLDs and wait for creation
418 # netslice_scenarios = db_nsir["_admin"]["deployed"]["RO"]
419 # db_nsir_update_RO = deepcopy(netslice_scenarios)
420 # for netslice_scenario in netslice_scenarios:
421 # await netslice_scenario_check(self, netslice_scenario["netslice_scenario_id"],
422 # nsir_id, db_nsir_update_RO)
424 # db_nsir_update["_admin.deployed.RO"] = db_nsir_update_RO
425 # self.update_db_2("nsis", nsir_id, db_nsir_update)
427 # Iterate over the network services operation ids to instantiate NSs
428 step
= "Instantiating Netslice Subnets"
429 db_nsir
= self
.db
.get_one("nsis", {"_id": nsir_id
})
430 nslcmop_ids
= db_nsilcmop
["operationParams"].get("nslcmops_ids")
431 for nslcmop_id
in nslcmop_ids
:
432 nslcmop
= self
.db
.get_one("nslcmops", {"_id": nslcmop_id
})
433 # Overwriting netslice-vld vim-net-id to ns
434 nsr_id
, nslcmop
= overwrite_nsd_params(self
, db_nsir
, nslcmop
)
435 step
= "Launching ns={} instantiate={} task".format(nsr_id
, nslcmop_id
)
436 task
= asyncio
.ensure_future(self
.ns
.instantiate(nsr_id
, nslcmop_id
))
437 self
.lcm_tasks
.register(
438 "ns", nsr_id
, nslcmop_id
, "ns_instantiate", task
441 # Wait until Network Slice is ready
442 step
= " Waiting nsi ready."
443 nsrs_detailed_list_old
= None
444 self
.logger
.debug(logging_text
+ step
)
446 # For HA, it is checked from database, as the ns operation may be managed by other LCM worker
447 while time() <= start_deploy
+ timeout_nsi_deploy
:
448 # Check ns instantiation status
450 nsir
= self
.db
.get_one("nsis", {"_id": nsir_id
})
451 nsrs_detailed_list
= nsir
["_admin"]["nsrs-detailed-list"]
452 nsrs_detailed_list_new
= []
453 for nslcmop_item
in nslcmop_ids
:
454 nslcmop
= self
.db
.get_one("nslcmops", {"_id": nslcmop_item
})
455 status
= nslcmop
.get("operationState")
456 # TODO: (future improvement) other possible status: ROLLING_BACK,ROLLED_BACK
457 for nss
in nsrs_detailed_list
:
458 if nss
["nsrId"] == nslcmop
["nsInstanceId"]:
461 "nsrId": nslcmop
["nsInstanceId"],
462 "status": nslcmop
["operationState"],
463 "detailed-status": nslcmop
.get("detailed-status"),
464 "instantiated": True,
467 nsrs_detailed_list_new
.append(nss
)
470 "PARTIALLY_COMPLETED",
476 if nsrs_detailed_list_new
!= nsrs_detailed_list_old
:
477 nsrs_detailed_list_old
= nsrs_detailed_list_new
481 {"_admin.nsrs-detailed-list": nsrs_detailed_list_new
},
486 step
= "Network Slice Instance instantiated"
487 for nss
in nsrs_detailed_list
:
488 if nss
["status"] in ("FAILED", "FAILED_TEMP"):
490 "NS {} {}: {}".format(
491 nss
["nsrId"], nss
["status"], nss
["detailed-status"]
495 step
= "instantiating"
496 raise LcmException("; ".join(error_list
))
499 # TODO: future improvement due to synchronism -> await asyncio.wait(vca_task_list, timeout=300)
500 await asyncio
.sleep(5)
502 else: # timeout_nsi_deploy reached:
503 raise LcmException("Timeout waiting nsi to be ready.")
505 db_nsir_update
["operational-status"] = "running"
506 db_nsir_update
["detailed-status"] = "done"
507 db_nsir_update
["config-status"] = "configured"
510 ] = nsilcmop_operation_state
= "COMPLETED"
511 db_nsilcmop_update
["statusEnteredTime"] = time()
512 db_nsilcmop_update
["detailed-status"] = "done"
515 except (LcmException
, DbException
) as e
:
517 logging_text
+ "Exit Exception while '{}': {}".format(step
, e
)
520 except asyncio
.CancelledError
:
522 logging_text
+ "Cancelled Exception while '{}'".format(step
)
524 exc
= "Operation was cancelled"
525 except Exception as e
:
526 exc
= traceback
.format_exc()
527 self
.logger
.critical(
529 + "Exit Exception {} while '{}': {}".format(type(e
).__name
__, step
, e
),
535 db_nsir_update
["detailed-status"] = "ERROR {}: {}".format(step
, exc
)
536 db_nsir_update
["operational-status"] = "failed"
537 db_nsir_update
["config-status"] = "configured"
539 db_nsilcmop_update
["detailed-status"] = "FAILED {}: {}".format(
544 ] = nsilcmop_operation_state
= "FAILED"
545 db_nsilcmop_update
["statusEnteredTime"] = time()
548 db_nsir_update
["_admin.nsilcmop"] = None
549 self
.update_db_2("nsis", nsir_id
, db_nsir_update
)
551 self
.update_db_2("nsilcmops", nsilcmop_id
, db_nsilcmop_update
)
552 except DbException
as e
:
553 self
.logger
.error(logging_text
+ "Cannot update database: {}".format(e
))
554 if nsilcmop_operation_state
:
556 await self
.msg
.aiowrite(
561 "nsilcmop_id": nsilcmop_id
,
562 "operationState": nsilcmop_operation_state
,
565 except Exception as e
:
567 logging_text
+ "kafka_write notification Exception {}".format(e
)
569 self
.logger
.debug(logging_text
+ "Exit")
570 self
.lcm_tasks
.remove("nsi", nsir_id
, nsilcmop_id
, "nsi_instantiate")
572 async def terminate(self
, nsir_id
, nsilcmop_id
):
573 # Try to lock HA task here
574 task_is_locked_by_me
= self
.lcm_tasks
.lock_HA("nsi", "nsilcmops", nsilcmop_id
)
575 if not task_is_locked_by_me
:
578 logging_text
= "Task nsi={} terminate={} ".format(nsir_id
, nsilcmop_id
)
579 self
.logger
.debug(logging_text
+ "Enter")
583 db_nsir_update
= {"_admin.nsilcmop": nsilcmop_id
}
584 db_nsilcmop_update
= {}
585 RO
= ROclient
.ROClient(**self
.ro_config
)
587 failed_detail
= [] # annotates all failed error messages
588 nsilcmop_operation_state
= None
589 autoremove
= False # autoremove after terminated
591 # wait for any previous tasks in process
592 await self
.lcm_tasks
.waitfor_related_HA("nsi", "nsilcmops", nsilcmop_id
)
594 step
= "Getting nsir={} from db".format(nsir_id
)
595 db_nsir
= self
.db
.get_one("nsis", {"_id": nsir_id
})
596 nsir_deployed
= deepcopy(db_nsir
["_admin"].get("deployed"))
597 step
= "Getting nsilcmop={} from db".format(nsilcmop_id
)
598 db_nsilcmop
= self
.db
.get_one("nsilcmops", {"_id": nsilcmop_id
})
600 # TODO: Check if makes sense check the nsiState=NOT_INSTANTIATED when terminate
601 # CASE: Instance was terminated but there is a second request to terminate the instance
602 if db_nsir
["_admin"]["nsiState"] == "NOT_INSTANTIATED":
605 # Slice status Terminating
606 db_nsir_update
["operational-status"] = "terminating"
607 db_nsir_update
["config-status"] = "terminating"
608 db_nsir_update
["detailed-status"] = "Terminating Netslice subnets"
609 self
.update_db_2("nsis", nsir_id
, db_nsir_update
)
611 # Gets the list to keep track of network service records status in the netslice
612 nsrs_detailed_list
= []
614 # Iterate over the network services operation ids to terminate NSs
615 # TODO: (future improvement) look another way check the tasks instead of keep asking
616 # -> https://docs.python.org/3/library/asyncio-task.html#waiting-primitives
617 # steps: declare ns_tasks, add task when terminate is called, await asyncio.wait(vca_task_list, timeout=300)
618 step
= "Terminating Netslice Subnets"
619 nslcmop_ids
= db_nsilcmop
["operationParams"].get("nslcmops_ids")
621 for nslcmop_id
in nslcmop_ids
:
622 nslcmop
= self
.db
.get_one("nslcmops", {"_id": nslcmop_id
})
623 nsr_id
= nslcmop
["operationParams"].get("nsInstanceId")
624 nss_in_use
= self
.db
.get_list(
627 "_admin.netslice-vld.ANYINDEX.shared-nsrs-list": nsr_id
,
628 "operational-status": {"$nin": ["terminated", "failed"]},
631 if len(nss_in_use
) < 2:
632 task
= asyncio
.ensure_future(self
.ns
.terminate(nsr_id
, nslcmop_id
))
633 self
.lcm_tasks
.register(
634 "ns", nsr_id
, nslcmop_id
, "ns_instantiate", task
636 nslcmop_new
.append(nslcmop_id
)
638 # Update shared nslcmop shared with active nsi
639 netsliceInstanceId
= db_nsir
["_id"]
640 for nsis_item
in nss_in_use
:
641 if db_nsir
["_id"] != nsis_item
["_id"]:
642 netsliceInstanceId
= nsis_item
["_id"]
647 {"operationParams.netsliceInstanceId": netsliceInstanceId
},
651 {"_id": nsilcmop_id
},
652 {"operationParams.nslcmops_ids": nslcmop_new
},
655 # Wait until Network Slice is terminated
656 step
= nsir_status_detailed
= " Waiting nsi terminated. nsi_id={}".format(
659 nsrs_detailed_list_old
= None
660 self
.logger
.debug(logging_text
+ step
)
662 termination_timeout
= 2 * 3600 # Two hours
663 while termination_timeout
> 0:
664 # Check ns termination status
666 db_nsir
= self
.db
.get_one("nsis", {"_id": nsir_id
})
667 nsrs_detailed_list
= db_nsir
["_admin"].get("nsrs-detailed-list")
668 nsrs_detailed_list_new
= []
669 for nslcmop_item
in nslcmop_ids
:
670 nslcmop
= self
.db
.get_one("nslcmops", {"_id": nslcmop_item
})
671 status
= nslcmop
["operationState"]
672 # TODO: (future improvement) other possible status: ROLLING_BACK,ROLLED_BACK
673 for nss
in nsrs_detailed_list
:
674 if nss
["nsrId"] == nslcmop
["nsInstanceId"]:
677 "nsrId": nslcmop
["nsInstanceId"],
678 "status": nslcmop
["operationState"],
679 "detailed-status": nsir_status_detailed
680 + "; {}".format(nslcmop
.get("detailed-status")),
683 nsrs_detailed_list_new
.append(nss
)
686 "PARTIALLY_COMPLETED",
692 if nsrs_detailed_list_new
!= nsrs_detailed_list_old
:
693 nsrs_detailed_list_old
= nsrs_detailed_list_new
697 {"_admin.nsrs-detailed-list": nsrs_detailed_list_new
},
701 # Check if it is the last used nss and mark isinstantiate: False
702 db_nsir
= self
.db
.get_one("nsis", {"_id": nsir_id
})
703 nsrs_detailed_list
= db_nsir
["_admin"].get("nsrs-detailed-list")
704 for nss
in nsrs_detailed_list
:
706 "_admin.nsrs-detailed-list.ANYINDEX.nsrId": nss
["nsrId"],
707 "operational-status.ne": "terminated",
710 nsis_list
= self
.db
.get_one(
711 "nsis", _filter
, fail_on_empty
=False, fail_on_more
=False
714 nss
.update({"instantiated": False})
716 step
= "Network Slice Instance is terminated. nsi_id={}".format(
719 for items
in nsrs_detailed_list
:
720 if "FAILED" in items
.values():
722 "Error terminating NSI: {}".format(nsir_id
)
726 await asyncio
.sleep(5)
727 termination_timeout
-= 5
729 if termination_timeout
<= 0:
731 "Timeout waiting nsi to be terminated. nsi_id={}".format(nsir_id
)
734 # Delete netslice-vlds
735 RO_nsir_id
= RO_delete_action
= None
736 for nsir_deployed_RO
in get_iterable(nsir_deployed
, "RO"):
737 RO_nsir_id
= nsir_deployed_RO
.get("netslice_scenario_id")
739 if not self
.ro_config
["ng"]:
740 step
= db_nsir_update
[
742 ] = "Deleting netslice-vld at RO"
745 ] = "Deleting netslice-vld at RO"
746 self
.logger
.debug(logging_text
+ step
)
747 desc
= await RO
.delete("ns", RO_nsir_id
)
748 RO_delete_action
= desc
["action_id"]
749 nsir_deployed_RO
["vld_delete_action_id"] = RO_delete_action
750 nsir_deployed_RO
["vld_status"] = "DELETING"
751 db_nsir_update
["_admin.deployed"] = nsir_deployed
752 self
.update_db_2("nsis", nsir_id
, db_nsir_update
)
754 # wait until NS is deleted from VIM
755 step
= "Waiting ns deleted from VIM. RO_id={}".format(
758 self
.logger
.debug(logging_text
+ step
)
759 except ROclient
.ROClientException
as e
:
760 if e
.http_code
== 404: # not found
761 nsir_deployed_RO
["vld_id"] = None
762 nsir_deployed_RO
["vld_status"] = "DELETED"
765 + "RO_ns_id={} already deleted".format(RO_nsir_id
)
767 elif e
.http_code
== 409: # conflict
768 failed_detail
.append(
769 "RO_ns_id={} delete conflict: {}".format(RO_nsir_id
, e
)
771 self
.logger
.debug(logging_text
+ failed_detail
[-1])
773 failed_detail
.append(
774 "RO_ns_id={} delete error: {}".format(RO_nsir_id
, e
)
776 self
.logger
.error(logging_text
+ failed_detail
[-1])
779 self
.logger
.error(logging_text
+ " ;".join(failed_detail
))
780 db_nsir_update
["operational-status"] = "failed"
781 db_nsir_update
["detailed-status"] = "Deletion errors " + "; ".join(
784 db_nsilcmop_update
["detailed-status"] = "; ".join(failed_detail
)
787 ] = nsilcmop_operation_state
= "FAILED"
788 db_nsilcmop_update
["statusEnteredTime"] = time()
790 db_nsir_update
["operational-status"] = "terminating"
791 db_nsir_update
["config-status"] = "terminating"
792 db_nsir_update
["_admin.nsiState"] = "NOT_INSTANTIATED"
795 ] = nsilcmop_operation_state
= "COMPLETED"
796 db_nsilcmop_update
["statusEnteredTime"] = time()
797 if db_nsilcmop
["operationParams"].get("autoremove"):
800 db_nsir_update
["detailed-status"] = "done"
801 db_nsir_update
["operational-status"] = "terminated"
802 db_nsir_update
["config-status"] = "terminated"
803 db_nsilcmop_update
["statusEnteredTime"] = time()
804 db_nsilcmop_update
["detailed-status"] = "done"
807 except (LcmException
, DbException
) as e
:
809 logging_text
+ "Exit Exception while '{}': {}".format(step
, e
)
812 except asyncio
.CancelledError
:
814 logging_text
+ "Cancelled Exception while '{}'".format(step
)
816 exc
= "Operation was cancelled"
817 except Exception as e
:
818 exc
= traceback
.format_exc()
819 self
.logger
.critical(
821 + "Exit Exception {} while '{}': {}".format(type(e
).__name
__, step
, e
),
827 db_nsir_update
["_admin.deployed"] = nsir_deployed
828 db_nsir_update
["detailed-status"] = "ERROR {}: {}".format(step
, exc
)
829 db_nsir_update
["operational-status"] = "failed"
831 db_nsilcmop_update
["detailed-status"] = "FAILED {}: {}".format(
836 ] = nsilcmop_operation_state
= "FAILED"
837 db_nsilcmop_update
["statusEnteredTime"] = time()
840 db_nsir_update
["_admin.deployed"] = nsir_deployed
841 db_nsir_update
["_admin.nsilcmop"] = None
842 self
.update_db_2("nsis", nsir_id
, db_nsir_update
)
844 self
.update_db_2("nsilcmops", nsilcmop_id
, db_nsilcmop_update
)
845 except DbException
as e
:
846 self
.logger
.error(logging_text
+ "Cannot update database: {}".format(e
))
848 if nsilcmop_operation_state
:
850 await self
.msg
.aiowrite(
855 "nsilcmop_id": nsilcmop_id
,
856 "operationState": nsilcmop_operation_state
,
857 "autoremove": autoremove
,
860 except Exception as e
:
862 logging_text
+ "kafka_write notification Exception {}".format(e
)
864 self
.logger
.debug(logging_text
+ "Exit")
865 self
.lcm_tasks
.remove("nsi", nsir_id
, nsilcmop_id
, "nsi_terminate")