| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| tierno | 8069ce5 | 2019-08-28 15:34:33 +0000 | [diff] [blame] | 2 | ## |
| 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 |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 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 |
| 13 | # under the License. |
| 14 | ## |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 15 | |
| 16 | import asyncio |
| 17 | import logging |
| 18 | import logging.handlers |
| 19 | import traceback |
| tierno | b996d94 | 2020-07-03 14:52:28 +0000 | [diff] [blame] | 20 | from osm_lcm import ROclient |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 21 | from osm_lcm.lcm_utils import ( |
| 22 | LcmException, |
| 23 | LcmBase, |
| 24 | populate_dict, |
| 25 | get_iterable, |
| 26 | deep_get, |
| 27 | ) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 28 | from osm_common.dbbase import DbException |
| 29 | from time import time |
| Felipe Vicens | 6559b4a | 2018-12-01 04:40:48 +0100 | [diff] [blame] | 30 | from copy import deepcopy |
| 31 | |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 32 | |
| 33 | __author__ = "Felipe Vicens, Pol Alemany, Alfonso Tierno" |
| 34 | |
| 35 | |
| 36 | class NetsliceLcm(LcmBase): |
| Gabriel Cuba | e789898 | 2023-05-11 01:57:21 -0500 | [diff] [blame] | 37 | def __init__(self, msg, lcm_tasks, config, ns): |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 38 | """ |
| 39 | Init, Connect to database, filesystem storage, and messaging |
| 40 | :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', |
| 41 | :return: None |
| 42 | """ |
| 43 | # logging |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 44 | self.logger = logging.getLogger("lcm.netslice") |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 45 | self.lcm_tasks = lcm_tasks |
| tierno | b996d94 | 2020-07-03 14:52:28 +0000 | [diff] [blame] | 46 | self.ns = ns |
| Luis Vega | a27dc53 | 2022-11-11 20:10:49 +0000 | [diff] [blame] | 47 | self.ro_config = config["RO"] |
| tierno | 744303e | 2020-01-13 16:46:31 +0000 | [diff] [blame] | 48 | self.timeout = config["timeout"] |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 49 | |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 50 | super().__init__(msg, self.logger) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 51 | |
| Felipe Vicens | 0f389ce | 2019-01-12 12:20:11 +0100 | [diff] [blame] | 52 | def nsi_update_nsir(self, nsi_update_nsir, db_nsir, nsir_desc_RO): |
| 53 | """ |
| 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 |
| 59 | """ |
| 60 | |
| 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"): |
| 64 | continue |
| 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 |
| 70 | break |
| 71 | else: |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 72 | raise LcmException( |
| 73 | "ns_update_nsir: Not found vld={} at RO info".format(vld["id"]) |
| 74 | ) |
| Felipe Vicens | 0f389ce | 2019-01-12 12:20:11 +0100 | [diff] [blame] | 75 | |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 76 | async def instantiate(self, nsir_id, nsilcmop_id): |
| kuuse | d124bfe | 2019-06-18 12:09:24 +0200 | [diff] [blame] | 77 | # Try to lock HA task here |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 78 | task_is_locked_by_me = self.lcm_tasks.lock_HA("nsi", "nsilcmops", nsilcmop_id) |
| kuuse | d124bfe | 2019-06-18 12:09:24 +0200 | [diff] [blame] | 79 | if not task_is_locked_by_me: |
| 80 | return |
| 81 | |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 82 | logging_text = "Task netslice={} instantiate={} ".format(nsir_id, nsilcmop_id) |
| 83 | self.logger.debug(logging_text + "Enter") |
| 84 | # get all needed from database |
| Felipe Vicens | 0f389ce | 2019-01-12 12:20:11 +0100 | [diff] [blame] | 85 | exc = None |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 86 | db_nsir = None |
| 87 | db_nsilcmop = None |
| 88 | db_nsir_update = {"_admin.nsilcmop": nsilcmop_id} |
| 89 | db_nsilcmop_update = {} |
| 90 | nsilcmop_operation_state = None |
| Felipe Vicens | 6559b4a | 2018-12-01 04:40:48 +0100 | [diff] [blame] | 91 | vim_2_RO = {} |
| Gabriel Cuba | e789898 | 2023-05-11 01:57:21 -0500 | [diff] [blame] | 92 | RO = ROclient.ROClient(**self.ro_config) |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 93 | nsi_vld_instantiationi_params = {} |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 94 | |
| 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"): |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 101 | RO_ip_profile["dns-address"].append(ds["address"]) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 102 | else: |
| 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") |
| 110 | return RO_ip_profile |
| Felipe Vicens | 6559b4a | 2018-12-01 04:40:48 +0100 | [diff] [blame] | 111 | |
| 112 | def vim_account_2_RO(vim_account): |
| 113 | """ |
| 114 | Translate a RO vim_account from OSM vim_account params |
| 115 | :param ns_params: OSM instantiate params |
| 116 | :return: The RO ns descriptor |
| 117 | """ |
| 118 | if vim_account in vim_2_RO: |
| 119 | return vim_2_RO[vim_account] |
| 120 | |
| 121 | db_vim = self.db.get_one("vim_accounts", {"_id": vim_account}) |
| 122 | if db_vim["_admin"]["operationalState"] != "ENABLED": |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 123 | raise LcmException( |
| 124 | "VIM={} is not available. operationalState={}".format( |
| 125 | vim_account, db_vim["_admin"]["operationalState"] |
| 126 | ) |
| 127 | ) |
| Felipe Vicens | 6559b4a | 2018-12-01 04:40:48 +0100 | [diff] [blame] | 128 | RO_vim_id = db_vim["_admin"]["deployed"]["RO"] |
| 129 | vim_2_RO[vim_account] = RO_vim_id |
| 130 | return RO_vim_id |
| 131 | |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 132 | async def netslice_scenario_create( |
| 133 | self, vld_item, nsir_id, db_nsir, db_nsir_admin, db_nsir_update |
| 134 | ): |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 135 | """ |
| 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 |
| 139 | """ |
| Anirudh Gupta | c2be949 | 2025-05-13 05:53:38 +0000 | [diff] [blame] | 140 | # nonlocal nsi_vld_instantiationi_params |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 141 | ip_vld = None |
| 142 | mgmt_network = False |
| 143 | RO_vld_sites = [] |
| 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") |
| 148 | |
| 149 | vld_shared = None |
| 150 | for shared_nsrs_item in get_iterable(vld_item, "shared-nsrs-list"): |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 151 | _filter = { |
| 152 | "_id.ne": nsir_id, |
| 153 | "_admin.nsrs-detailed-list.ANYINDEX.nsrId": shared_nsrs_item, |
| 154 | } |
| 155 | shared_nsi = self.db.get_one( |
| 156 | "nsis", _filter, fail_on_empty=False, fail_on_more=False |
| 157 | ) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 158 | if shared_nsi: |
| 159 | for vlds in get_iterable(shared_nsi["_admin"]["deployed"], "RO"): |
| 160 | if vld_id == vlds["vld_id"]: |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 161 | vld_shared = { |
| 162 | "instance_scenario_id": vlds["netslice_scenario_id"], |
| 163 | "osm_id": vld_id, |
| 164 | } |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 165 | break |
| 166 | break |
| 167 | |
| 168 | # Creating netslice-vld at RO |
| tierno | 744303e | 2020-01-13 16:46:31 +0000 | [diff] [blame] | 169 | RO_nsir = deep_get(db_nsir, ("_admin", "deployed", "RO"), []) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 170 | |
| 171 | if vld_id in RO_nsir: |
| 172 | db_nsir_update["_admin.deployed.RO"] = RO_nsir |
| 173 | |
| 174 | # If netslice-vld doesn't exists then create it |
| 175 | else: |
| 176 | # TODO: Check VDU type in all descriptors finding SRIOV / PT |
| 177 | # Updating network names and datacenters from instantiation parameters for each VLD |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 178 | for instantiation_params_vld in get_iterable( |
| 179 | db_nsir["instantiation_parameters"], "netslice-vld" |
| 180 | ): |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 181 | if instantiation_params_vld.get("name") == netslice_vld["name"]: |
| 182 | ip_vld = deepcopy(instantiation_params_vld) |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 183 | ip_vld.pop("name") |
| 184 | nsi_vld_instantiationi_params[netslice_vld["name"]] = ip_vld |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 185 | |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 186 | db_nsir_update_RO = {} |
| 187 | db_nsir_update_RO["vld_id"] = netslice_vld["name"] |
| 188 | if self.ro_config["ng"]: |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 189 | db_nsir_update_RO["netslice_scenario_id"] = ( |
| 190 | vld_shared.get("instance_scenario_id") |
| 191 | if vld_shared |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 192 | else "nsir:{}:vld.{}".format(nsir_id, netslice_vld["name"]) |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 193 | ) |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 194 | else: # if not self.ro_config["ng"]: |
| 195 | if netslice_vld.get("mgmt-network"): |
| 196 | mgmt_network = True |
| 197 | RO_ns_params = {} |
| 198 | RO_ns_params["name"] = netslice_vld["name"] |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 199 | RO_ns_params["datacenter"] = vim_account_2_RO( |
| 200 | db_nsir["instantiation_parameters"]["vimAccountId"] |
| 201 | ) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 202 | |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 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 |
| 206 | if ip_vld: |
| 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"): |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 212 | populate_dict( |
| 213 | RO_ns_params, |
| 214 | ("networks", netslice_vld["name"], "ip-profile"), |
| 215 | ip_profile_2_RO(ip_vld["ip-profile"]), |
| 216 | ) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 217 | |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 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(): |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 223 | RO_vld_sites.append( |
| 224 | { |
| 225 | "netmap-use": vim_net, |
| 226 | "datacenter": vim_account_2_RO( |
| 227 | vim_account |
| 228 | ), |
| 229 | } |
| 230 | ) |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 231 | elif isinstance(ip_vld.get(vim_network_option), dict): |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 232 | for vim_account, vim_net in ip_vld.get( |
| 233 | vim_network_option |
| 234 | ).items(): |
| 235 | RO_vld_sites.append( |
| 236 | { |
| 237 | "netmap-use": vim_net, |
| 238 | "datacenter": vim_account_2_RO(vim_account), |
| 239 | } |
| 240 | ) |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 241 | else: |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 242 | RO_vld_sites.append( |
| 243 | { |
| 244 | "netmap-use": ip_vld[vim_network_option], |
| 245 | "datacenter": vim_account_2_RO( |
| 246 | netslice_vld["vimAccountId"] |
| 247 | ), |
| 248 | } |
| 249 | ) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 250 | |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 251 | # Use default netslice vim-network-name from template |
| 252 | else: |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 253 | for nss_conn_point_ref in get_iterable( |
| 254 | netslice_vld, "nss-connection-point-ref" |
| 255 | ): |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 256 | if nss_conn_point_ref.get("vimAccountId"): |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 257 | if ( |
| 258 | nss_conn_point_ref["vimAccountId"] |
| 259 | != netslice_vld["vimAccountId"] |
| 260 | ): |
| 261 | RO_vld_sites.append( |
| 262 | { |
| 263 | "netmap-create": None, |
| 264 | "datacenter": vim_account_2_RO( |
| 265 | nss_conn_point_ref["vimAccountId"] |
| 266 | ), |
| 267 | } |
| 268 | ) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 269 | |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 270 | if vld_shared: |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 271 | populate_dict( |
| 272 | RO_ns_params, |
| 273 | ("networks", netslice_vld["name"], "use-network"), |
| 274 | vld_shared, |
| 275 | ) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 276 | |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 277 | if RO_vld_sites: |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 278 | populate_dict( |
| 279 | RO_ns_params, |
| 280 | ("networks", netslice_vld["name"], "sites"), |
| 281 | RO_vld_sites, |
| 282 | ) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 283 | |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 284 | RO_ns_params["scenario"] = { |
| 285 | "nets": [ |
| 286 | { |
| 287 | "name": netslice_vld["name"], |
| 288 | "external": mgmt_network, |
| 289 | "type": "bridge", |
| 290 | } |
| 291 | ] |
| 292 | } |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 293 | |
| 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"] |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 297 | db_nsir_update["_admin.deployed.RO"].append(db_nsir_update_RO) |
| kuuse | d124bfe | 2019-06-18 12:09:24 +0200 | [diff] [blame] | 298 | |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 299 | def overwrite_nsd_params(self, db_nsir, nslcmop): |
| Anirudh Gupta | c2be949 | 2025-05-13 05:53:38 +0000 | [diff] [blame] | 300 | # nonlocal nsi_vld_instantiationi_params |
| 301 | # nonlocal db_nsir_update |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 302 | vld_op_list = [] |
| 303 | vld = None |
| 304 | nsr_id = nslcmop.get("nsInstanceId") |
| 305 | # Overwrite instantiation parameters in netslice runtime |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 306 | RO_list = db_nsir_admin["deployed"]["RO"] |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 307 | |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 308 | for ro_item_index, RO_item in enumerate(RO_list): |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 309 | netslice_vld = next( |
| 310 | ( |
| 311 | n |
| 312 | for n in get_iterable(db_nsir["_admin"], "netslice-vld") |
| 313 | if RO_item.get("vld_id") == n.get("id") |
| 314 | ), |
| 315 | None, |
| 316 | ) |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 317 | if not netslice_vld: |
| 318 | continue |
| 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 |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 321 | for nss_cp_item in get_iterable( |
| 322 | netslice_vld, "nss-connection-point-ref" |
| 323 | ): |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 324 | # Search the netslice-subnet of nst that match |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 325 | nss = next( |
| 326 | ( |
| 327 | nss |
| 328 | for nss in get_iterable( |
| 329 | db_nsir["_admin"], "netslice-subnet" |
| 330 | ) |
| 331 | if nss_cp_item["nss-ref"] == nss["nss-id"] |
| 332 | ), |
| 333 | None, |
| 334 | ) |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 335 | # Compare nss-ref equal nss from nst |
| 336 | if not nss: |
| 337 | continue |
| 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 |
| bravof | a7cb70b | 2020-12-11 16:37:01 -0300 | [diff] [blame] | 340 | for cp_nsd in db_nsds.get("sapd", ()): |
| 341 | if cp_nsd["id"] == nss_cp_item["nsd-connection-point-ref"]: |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 342 | if nslcmop.get("operationParams"): |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 343 | if ( |
| 344 | nslcmop["operationParams"].get("nsName") |
| 345 | == nss["nsName"] |
| 346 | ): |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 347 | vld_id = RO_item["vld_id"] |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 348 | netslice_scenario_id = RO_item[ |
| 349 | "netslice_scenario_id" |
| 350 | ] |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 351 | nslcmop_vld = {} |
| bravof | a7cb70b | 2020-12-11 16:37:01 -0300 | [diff] [blame] | 352 | nslcmop_vld["name"] = cp_nsd["virtual-link-desc"] |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 353 | for vld in get_iterable( |
| 354 | nslcmop["operationParams"], "vld" |
| 355 | ): |
| bravof | a7cb70b | 2020-12-11 16:37:01 -0300 | [diff] [blame] | 356 | if vld["name"] == cp_nsd["virtual-link-desc"]: |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 357 | nslcmop_vld.update(vld) |
| 358 | if self.ro_config["ng"]: |
| 359 | nslcmop_vld["common_id"] = netslice_scenario_id |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 360 | nslcmop_vld.update( |
| 361 | nsi_vld_instantiationi_params.get( |
| 362 | RO_item["vld_id"], {} |
| 363 | ) |
| 364 | ) |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 365 | else: |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 366 | nslcmop_vld["ns-net"] = { |
| 367 | vld_id: netslice_scenario_id |
| 368 | } |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 369 | vld_op_list.append(nslcmop_vld) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 370 | nslcmop["operationParams"]["vld"] = vld_op_list |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 371 | self.update_db_2( |
| 372 | "nslcmops", nslcmop["_id"], {"operationParams.vld": vld_op_list} |
| 373 | ) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 374 | return nsr_id, nslcmop |
| 375 | |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 376 | try: |
| kuuse | d124bfe | 2019-06-18 12:09:24 +0200 | [diff] [blame] | 377 | # wait for any previous tasks in process |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 378 | await self.lcm_tasks.waitfor_related_HA("nsi", "nsilcmops", nsilcmop_id) |
| kuuse | d124bfe | 2019-06-18 12:09:24 +0200 | [diff] [blame] | 379 | |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 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}) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 384 | |
| tierno | 744303e | 2020-01-13 16:46:31 +0000 | [diff] [blame] | 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"] |
| 389 | else: |
| Gabriel Cuba | a89a5a7 | 2022-11-26 18:55:15 -0500 | [diff] [blame] | 390 | timeout_nsi_deploy = self.timeout.get("nsi_deploy") |
| tierno | 744303e | 2020-01-13 16:46:31 +0000 | [diff] [blame] | 391 | |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 392 | # Empty list to keep track of network service records status in the netslice |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 393 | nsir_admin = db_nsir_admin = db_nsir.get("_admin") |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 394 | |
| Felipe Vicens | b0e5fe4 | 2019-12-05 10:30:38 +0100 | [diff] [blame] | 395 | step = "Creating slice operational-status init" |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 396 | # Slice status Creating |
| 397 | db_nsir_update["detailed-status"] = "creating" |
| 398 | db_nsir_update["operational-status"] = "init" |
| tierno | 5e98d46 | 2020-08-10 13:21:28 +0000 | [diff] [blame] | 399 | db_nsir_update["_admin.nsiState"] = "INSTANTIATED" |
| kuuse | d124bfe | 2019-06-18 12:09:24 +0200 | [diff] [blame] | 400 | |
| tierno | 5e98d46 | 2020-08-10 13:21:28 +0000 | [diff] [blame] | 401 | step = "Instantiating netslice VLDs before NS instantiation" |
| Felipe Vicens | 0f389ce | 2019-01-12 12:20:11 +0100 | [diff] [blame] | 402 | # Creating netslice VLDs networking before NS instantiation |
| tierno | 5e98d46 | 2020-08-10 13:21:28 +0000 | [diff] [blame] | 403 | db_nsir_update["detailed-status"] = step |
| Felipe Vicens | b0e5fe4 | 2019-12-05 10:30:38 +0100 | [diff] [blame] | 404 | self.update_db_2("nsis", nsir_id, db_nsir_update) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 405 | db_nsir_update["_admin.deployed.RO"] = db_nsir_admin["deployed"]["RO"] |
| 406 | for vld_item in get_iterable(nsir_admin, "netslice-vld"): |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 407 | await netslice_scenario_create( |
| 408 | self, vld_item, nsir_id, db_nsir, db_nsir_admin, db_nsir_update |
| 409 | ) |
| kuuse | d124bfe | 2019-06-18 12:09:24 +0200 | [diff] [blame] | 410 | |
| tierno | 5e98d46 | 2020-08-10 13:21:28 +0000 | [diff] [blame] | 411 | step = "Instantiating netslice subnets" |
| 412 | db_nsir_update["detailed-status"] = step |
| kuuse | d124bfe | 2019-06-18 12:09:24 +0200 | [diff] [blame] | 413 | self.update_db_2("nsis", nsir_id, db_nsir_update) |
| Felipe Vicens | 0f389ce | 2019-01-12 12:20:11 +0100 | [diff] [blame] | 414 | |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 415 | db_nsir = self.db.get_one("nsis", {"_id": nsir_id}) |
| Felipe Vicens | 0f389ce | 2019-01-12 12:20:11 +0100 | [diff] [blame] | 416 | |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 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: |
| kuuse | d124bfe | 2019-06-18 12:09:24 +0200 | [diff] [blame] | 421 | # await netslice_scenario_check(self, netslice_scenario["netslice_scenario_id"], |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 422 | # nsir_id, db_nsir_update_RO) |
| kuuse | d124bfe | 2019-06-18 12:09:24 +0200 | [diff] [blame] | 423 | |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 424 | # db_nsir_update["_admin.deployed.RO"] = db_nsir_update_RO |
| 425 | # self.update_db_2("nsis", nsir_id, db_nsir_update) |
| Felipe Vicens | 6559b4a | 2018-12-01 04:40:48 +0100 | [diff] [blame] | 426 | |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 427 | # Iterate over the network services operation ids to instantiate NSs |
| Felipe Vicens | b0e5fe4 | 2019-12-05 10:30:38 +0100 | [diff] [blame] | 428 | step = "Instantiating Netslice Subnets" |
| Felipe Vicens | 0f389ce | 2019-01-12 12:20:11 +0100 | [diff] [blame] | 429 | db_nsir = self.db.get_one("nsis", {"_id": nsir_id}) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 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}) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 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) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 436 | task = asyncio.ensure_future(self.ns.instantiate(nsr_id, nslcmop_id)) |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 437 | self.lcm_tasks.register( |
| 438 | "ns", nsr_id, nslcmop_id, "ns_instantiate", task |
| 439 | ) |
| kuuse | d124bfe | 2019-06-18 12:09:24 +0200 | [diff] [blame] | 440 | |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 441 | # Wait until Network Slice is ready |
| tierno | 5e98d46 | 2020-08-10 13:21:28 +0000 | [diff] [blame] | 442 | step = " Waiting nsi ready." |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 443 | nsrs_detailed_list_old = None |
| 444 | self.logger.debug(logging_text + step) |
| kuuse | d124bfe | 2019-06-18 12:09:24 +0200 | [diff] [blame] | 445 | |
| tierno | 5e98d46 | 2020-08-10 13:21:28 +0000 | [diff] [blame] | 446 | # For HA, it is checked from database, as the ns operation may be managed by other LCM worker |
| tierno | 744303e | 2020-01-13 16:46:31 +0000 | [diff] [blame] | 447 | while time() <= start_deploy + timeout_nsi_deploy: |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 448 | # Check ns instantiation status |
| 449 | nsi_ready = True |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 450 | nsir = self.db.get_one("nsis", {"_id": nsir_id}) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 451 | nsrs_detailed_list = nsir["_admin"]["nsrs-detailed-list"] |
| 452 | nsrs_detailed_list_new = [] |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 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 |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 457 | for nss in nsrs_detailed_list: |
| 458 | if nss["nsrId"] == nslcmop["nsInstanceId"]: |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 459 | nss.update( |
| 460 | { |
| 461 | "nsrId": nslcmop["nsInstanceId"], |
| 462 | "status": nslcmop["operationState"], |
| 463 | "detailed-status": nslcmop.get("detailed-status"), |
| 464 | "instantiated": True, |
| 465 | } |
| 466 | ) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 467 | nsrs_detailed_list_new.append(nss) |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 468 | if status not in [ |
| 469 | "COMPLETED", |
| 470 | "PARTIALLY_COMPLETED", |
| 471 | "FAILED", |
| 472 | "FAILED_TEMP", |
| 473 | ]: |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 474 | nsi_ready = False |
| 475 | |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 476 | if nsrs_detailed_list_new != nsrs_detailed_list_old: |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 477 | nsrs_detailed_list_old = nsrs_detailed_list_new |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 478 | self.update_db_2( |
| 479 | "nsis", |
| 480 | nsir_id, |
| 481 | {"_admin.nsrs-detailed-list": nsrs_detailed_list_new}, |
| 482 | ) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 483 | |
| 484 | if nsi_ready: |
| tierno | 5e98d46 | 2020-08-10 13:21:28 +0000 | [diff] [blame] | 485 | error_list = [] |
| 486 | step = "Network Slice Instance instantiated" |
| 487 | for nss in nsrs_detailed_list: |
| 488 | if nss["status"] in ("FAILED", "FAILED_TEMP"): |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 489 | error_list.append( |
| 490 | "NS {} {}: {}".format( |
| 491 | nss["nsrId"], nss["status"], nss["detailed-status"] |
| 492 | ) |
| 493 | ) |
| tierno | 5e98d46 | 2020-08-10 13:21:28 +0000 | [diff] [blame] | 494 | if error_list: |
| 495 | step = "instantiating" |
| 496 | raise LcmException("; ".join(error_list)) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 497 | break |
| Felipe Vicens | b0e5fe4 | 2019-12-05 10:30:38 +0100 | [diff] [blame] | 498 | |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 499 | # TODO: future improvement due to synchronism -> await asyncio.wait(vca_task_list, timeout=300) |
| Gabriel Cuba | e789898 | 2023-05-11 01:57:21 -0500 | [diff] [blame] | 500 | await asyncio.sleep(5) |
| Felipe Vicens | b0e5fe4 | 2019-12-05 10:30:38 +0100 | [diff] [blame] | 501 | |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 502 | else: # timeout_nsi_deploy reached: |
| tierno | 5e98d46 | 2020-08-10 13:21:28 +0000 | [diff] [blame] | 503 | raise LcmException("Timeout waiting nsi to be ready.") |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 504 | |
| 505 | db_nsir_update["operational-status"] = "running" |
| 506 | db_nsir_update["detailed-status"] = "done" |
| 507 | db_nsir_update["config-status"] = "configured" |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 508 | db_nsilcmop_update[ |
| 509 | "operationState" |
| 510 | ] = nsilcmop_operation_state = "COMPLETED" |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 511 | db_nsilcmop_update["statusEnteredTime"] = time() |
| 512 | db_nsilcmop_update["detailed-status"] = "done" |
| 513 | return |
| 514 | |
| 515 | except (LcmException, DbException) as e: |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 516 | self.logger.error( |
| 517 | logging_text + "Exit Exception while '{}': {}".format(step, e) |
| 518 | ) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 519 | exc = e |
| 520 | except asyncio.CancelledError: |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 521 | self.logger.error( |
| 522 | logging_text + "Cancelled Exception while '{}'".format(step) |
| 523 | ) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 524 | exc = "Operation was cancelled" |
| 525 | except Exception as e: |
| 526 | exc = traceback.format_exc() |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 527 | self.logger.critical( |
| 528 | logging_text |
| 529 | + "Exit Exception {} while '{}': {}".format(type(e).__name__, step, e), |
| 530 | exc_info=True, |
| 531 | ) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 532 | finally: |
| 533 | if exc: |
| 534 | if db_nsir: |
| 535 | db_nsir_update["detailed-status"] = "ERROR {}: {}".format(step, exc) |
| 536 | db_nsir_update["operational-status"] = "failed" |
| tierno | 5e98d46 | 2020-08-10 13:21:28 +0000 | [diff] [blame] | 537 | db_nsir_update["config-status"] = "configured" |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 538 | if db_nsilcmop: |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 539 | db_nsilcmop_update["detailed-status"] = "FAILED {}: {}".format( |
| 540 | step, exc |
| 541 | ) |
| 542 | db_nsilcmop_update[ |
| 543 | "operationState" |
| 544 | ] = nsilcmop_operation_state = "FAILED" |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 545 | db_nsilcmop_update["statusEnteredTime"] = time() |
| tierno | baa5110 | 2018-12-14 13:16:18 +0000 | [diff] [blame] | 546 | try: |
| 547 | if db_nsir: |
| tierno | baa5110 | 2018-12-14 13:16:18 +0000 | [diff] [blame] | 548 | db_nsir_update["_admin.nsilcmop"] = None |
| 549 | self.update_db_2("nsis", nsir_id, db_nsir_update) |
| 550 | if db_nsilcmop: |
| 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)) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 554 | if nsilcmop_operation_state: |
| 555 | try: |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 556 | await self.msg.aiowrite( |
| 557 | "nsi", |
| 558 | "instantiated", |
| 559 | { |
| 560 | "nsir_id": nsir_id, |
| 561 | "nsilcmop_id": nsilcmop_id, |
| 562 | "operationState": nsilcmop_operation_state, |
| 563 | }, |
| 564 | ) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 565 | except Exception as e: |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 566 | self.logger.error( |
| 567 | logging_text + "kafka_write notification Exception {}".format(e) |
| 568 | ) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 569 | self.logger.debug(logging_text + "Exit") |
| 570 | self.lcm_tasks.remove("nsi", nsir_id, nsilcmop_id, "nsi_instantiate") |
| 571 | |
| 572 | async def terminate(self, nsir_id, nsilcmop_id): |
| kuuse | d124bfe | 2019-06-18 12:09:24 +0200 | [diff] [blame] | 573 | # Try to lock HA task here |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 574 | task_is_locked_by_me = self.lcm_tasks.lock_HA("nsi", "nsilcmops", nsilcmop_id) |
| kuuse | d124bfe | 2019-06-18 12:09:24 +0200 | [diff] [blame] | 575 | if not task_is_locked_by_me: |
| 576 | return |
| 577 | |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 578 | logging_text = "Task nsi={} terminate={} ".format(nsir_id, nsilcmop_id) |
| 579 | self.logger.debug(logging_text + "Enter") |
| kuuse | d124bfe | 2019-06-18 12:09:24 +0200 | [diff] [blame] | 580 | exc = None |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 581 | db_nsir = None |
| 582 | db_nsilcmop = None |
| 583 | db_nsir_update = {"_admin.nsilcmop": nsilcmop_id} |
| 584 | db_nsilcmop_update = {} |
| Gabriel Cuba | e789898 | 2023-05-11 01:57:21 -0500 | [diff] [blame] | 585 | RO = ROclient.ROClient(**self.ro_config) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 586 | nsir_deployed = None |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 587 | failed_detail = [] # annotates all failed error messages |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 588 | nsilcmop_operation_state = None |
| tierno | c2564fe | 2019-01-28 16:18:56 +0000 | [diff] [blame] | 589 | autoremove = False # autoremove after terminated |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 590 | try: |
| kuuse | d124bfe | 2019-06-18 12:09:24 +0200 | [diff] [blame] | 591 | # wait for any previous tasks in process |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 592 | await self.lcm_tasks.waitfor_related_HA("nsi", "nsilcmops", nsilcmop_id) |
| kuuse | d124bfe | 2019-06-18 12:09:24 +0200 | [diff] [blame] | 593 | |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 594 | step = "Getting nsir={} from db".format(nsir_id) |
| 595 | db_nsir = self.db.get_one("nsis", {"_id": nsir_id}) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 596 | nsir_deployed = deepcopy(db_nsir["_admin"].get("deployed")) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 597 | step = "Getting nsilcmop={} from db".format(nsilcmop_id) |
| 598 | db_nsilcmop = self.db.get_one("nsilcmops", {"_id": nsilcmop_id}) |
| kuuse | d124bfe | 2019-06-18 12:09:24 +0200 | [diff] [blame] | 599 | |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 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": |
| 603 | return |
| 604 | |
| 605 | # Slice status Terminating |
| 606 | db_nsir_update["operational-status"] = "terminating" |
| 607 | db_nsir_update["config-status"] = "terminating" |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 608 | db_nsir_update["detailed-status"] = "Terminating Netslice subnets" |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 609 | self.update_db_2("nsis", nsir_id, db_nsir_update) |
| 610 | |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 611 | # Gets the list to keep track of network service records status in the netslice |
| kuuse | d124bfe | 2019-06-18 12:09:24 +0200 | [diff] [blame] | 612 | nsrs_detailed_list = [] |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 613 | |
| 614 | # Iterate over the network services operation ids to terminate NSs |
| kuuse | d124bfe | 2019-06-18 12:09:24 +0200 | [diff] [blame] | 615 | # TODO: (future improvement) look another way check the tasks instead of keep asking |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 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) |
| Felipe Vicens | b0e5fe4 | 2019-12-05 10:30:38 +0100 | [diff] [blame] | 618 | step = "Terminating Netslice Subnets" |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 619 | nslcmop_ids = db_nsilcmop["operationParams"].get("nslcmops_ids") |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 620 | nslcmop_new = [] |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 621 | for nslcmop_id in nslcmop_ids: |
| 622 | nslcmop = self.db.get_one("nslcmops", {"_id": nslcmop_id}) |
| 623 | nsr_id = nslcmop["operationParams"].get("nsInstanceId") |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 624 | nss_in_use = self.db.get_list( |
| 625 | "nsis", |
| 626 | { |
| 627 | "_admin.netslice-vld.ANYINDEX.shared-nsrs-list": nsr_id, |
| 628 | "operational-status": {"$nin": ["terminated", "failed"]}, |
| 629 | }, |
| 630 | ) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 631 | if len(nss_in_use) < 2: |
| 632 | task = asyncio.ensure_future(self.ns.terminate(nsr_id, nslcmop_id)) |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 633 | self.lcm_tasks.register( |
| 634 | "ns", nsr_id, nslcmop_id, "ns_instantiate", task |
| 635 | ) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 636 | nslcmop_new.append(nslcmop_id) |
| 637 | else: |
| 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"] |
| 643 | break |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 644 | self.db.set_one( |
| 645 | "nslcmops", |
| 646 | {"_id": nslcmop_id}, |
| 647 | {"operationParams.netsliceInstanceId": netsliceInstanceId}, |
| 648 | ) |
| 649 | self.db.set_one( |
| 650 | "nsilcmops", |
| 651 | {"_id": nsilcmop_id}, |
| 652 | {"operationParams.nslcmops_ids": nslcmop_new}, |
| 653 | ) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 654 | |
| 655 | # Wait until Network Slice is terminated |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 656 | step = nsir_status_detailed = " Waiting nsi terminated. nsi_id={}".format( |
| 657 | nsir_id |
| 658 | ) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 659 | nsrs_detailed_list_old = None |
| 660 | self.logger.debug(logging_text + step) |
| kuuse | d124bfe | 2019-06-18 12:09:24 +0200 | [diff] [blame] | 661 | |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 662 | termination_timeout = 2 * 3600 # Two hours |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 663 | while termination_timeout > 0: |
| 664 | # Check ns termination status |
| 665 | nsi_ready = True |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 666 | db_nsir = self.db.get_one("nsis", {"_id": nsir_id}) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 667 | nsrs_detailed_list = db_nsir["_admin"].get("nsrs-detailed-list") |
| 668 | nsrs_detailed_list_new = [] |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 669 | for nslcmop_item in nslcmop_ids: |
| 670 | nslcmop = self.db.get_one("nslcmops", {"_id": nslcmop_item}) |
| 671 | status = nslcmop["operationState"] |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 672 | # TODO: (future improvement) other possible status: ROLLING_BACK,ROLLED_BACK |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 673 | for nss in nsrs_detailed_list: |
| 674 | if nss["nsrId"] == nslcmop["nsInstanceId"]: |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 675 | nss.update( |
| 676 | { |
| 677 | "nsrId": nslcmop["nsInstanceId"], |
| 678 | "status": nslcmop["operationState"], |
| 679 | "detailed-status": nsir_status_detailed |
| 680 | + "; {}".format(nslcmop.get("detailed-status")), |
| 681 | } |
| 682 | ) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 683 | nsrs_detailed_list_new.append(nss) |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 684 | if status not in [ |
| 685 | "COMPLETED", |
| 686 | "PARTIALLY_COMPLETED", |
| 687 | "FAILED", |
| 688 | "FAILED_TEMP", |
| 689 | ]: |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 690 | nsi_ready = False |
| 691 | |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 692 | if nsrs_detailed_list_new != nsrs_detailed_list_old: |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 693 | nsrs_detailed_list_old = nsrs_detailed_list_new |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 694 | self.update_db_2( |
| 695 | "nsis", |
| 696 | nsir_id, |
| 697 | {"_admin.nsrs-detailed-list": nsrs_detailed_list_new}, |
| 698 | ) |
| Felipe Vicens | b0e5fe4 | 2019-12-05 10:30:38 +0100 | [diff] [blame] | 699 | |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 700 | if nsi_ready: |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 701 | # Check if it is the last used nss and mark isinstantiate: False |
| 702 | db_nsir = self.db.get_one("nsis", {"_id": nsir_id}) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 703 | nsrs_detailed_list = db_nsir["_admin"].get("nsrs-detailed-list") |
| 704 | for nss in nsrs_detailed_list: |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 705 | _filter = { |
| 706 | "_admin.nsrs-detailed-list.ANYINDEX.nsrId": nss["nsrId"], |
| 707 | "operational-status.ne": "terminated", |
| 708 | "_id.ne": nsir_id, |
| 709 | } |
| 710 | nsis_list = self.db.get_one( |
| 711 | "nsis", _filter, fail_on_empty=False, fail_on_more=False |
| 712 | ) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 713 | if not nsis_list: |
| 714 | nss.update({"instantiated": False}) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 715 | |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 716 | step = "Network Slice Instance is terminated. nsi_id={}".format( |
| 717 | nsir_id |
| 718 | ) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 719 | for items in nsrs_detailed_list: |
| 720 | if "FAILED" in items.values(): |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 721 | raise LcmException( |
| 722 | "Error terminating NSI: {}".format(nsir_id) |
| 723 | ) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 724 | break |
| 725 | |
| Gabriel Cuba | e789898 | 2023-05-11 01:57:21 -0500 | [diff] [blame] | 726 | await asyncio.sleep(5) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 727 | termination_timeout -= 5 |
| 728 | |
| 729 | if termination_timeout <= 0: |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 730 | raise LcmException( |
| 731 | "Timeout waiting nsi to be terminated. nsi_id={}".format(nsir_id) |
| 732 | ) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 733 | |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 734 | # Delete netslice-vlds |
| Felipe Vicens | 6559b4a | 2018-12-01 04:40:48 +0100 | [diff] [blame] | 735 | RO_nsir_id = RO_delete_action = None |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 736 | for nsir_deployed_RO in get_iterable(nsir_deployed, "RO"): |
| 737 | RO_nsir_id = nsir_deployed_RO.get("netslice_scenario_id") |
| 738 | try: |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 739 | if not self.ro_config["ng"]: |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 740 | step = db_nsir_update[ |
| 741 | "detailed-status" |
| 742 | ] = "Deleting netslice-vld at RO" |
| 743 | db_nsilcmop_update[ |
| 744 | "detailed-status" |
| 745 | ] = "Deleting netslice-vld at RO" |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 746 | self.logger.debug(logging_text + step) |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 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) |
| 753 | if RO_delete_action: |
| 754 | # wait until NS is deleted from VIM |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 755 | step = "Waiting ns deleted from VIM. RO_id={}".format( |
| 756 | RO_nsir_id |
| 757 | ) |
| bravof | 922c417 | 2020-11-24 21:21:43 -0300 | [diff] [blame] | 758 | self.logger.debug(logging_text + step) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 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" |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 763 | self.logger.debug( |
| 764 | logging_text |
| 765 | + "RO_ns_id={} already deleted".format(RO_nsir_id) |
| 766 | ) |
| 767 | elif e.http_code == 409: # conflict |
| 768 | failed_detail.append( |
| 769 | "RO_ns_id={} delete conflict: {}".format(RO_nsir_id, e) |
| 770 | ) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 771 | self.logger.debug(logging_text + failed_detail[-1]) |
| 772 | else: |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 773 | failed_detail.append( |
| 774 | "RO_ns_id={} delete error: {}".format(RO_nsir_id, e) |
| 775 | ) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 776 | self.logger.error(logging_text + failed_detail[-1]) |
| Felipe Vicens | 6559b4a | 2018-12-01 04:40:48 +0100 | [diff] [blame] | 777 | |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 778 | if failed_detail: |
| 779 | self.logger.error(logging_text + " ;".join(failed_detail)) |
| 780 | db_nsir_update["operational-status"] = "failed" |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 781 | db_nsir_update["detailed-status"] = "Deletion errors " + "; ".join( |
| 782 | failed_detail |
| 783 | ) |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 784 | db_nsilcmop_update["detailed-status"] = "; ".join(failed_detail) |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 785 | db_nsilcmop_update[ |
| 786 | "operationState" |
| 787 | ] = nsilcmop_operation_state = "FAILED" |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 788 | db_nsilcmop_update["statusEnteredTime"] = time() |
| Felipe Vicens | 6559b4a | 2018-12-01 04:40:48 +0100 | [diff] [blame] | 789 | else: |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 790 | db_nsir_update["operational-status"] = "terminating" |
| 791 | db_nsir_update["config-status"] = "terminating" |
| 792 | db_nsir_update["_admin.nsiState"] = "NOT_INSTANTIATED" |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 793 | db_nsilcmop_update[ |
| 794 | "operationState" |
| 795 | ] = nsilcmop_operation_state = "COMPLETED" |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 796 | db_nsilcmop_update["statusEnteredTime"] = time() |
| 797 | if db_nsilcmop["operationParams"].get("autoremove"): |
| 798 | autoremove = True |
| Felipe Vicens | 6559b4a | 2018-12-01 04:40:48 +0100 | [diff] [blame] | 799 | |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 800 | db_nsir_update["detailed-status"] = "done" |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 801 | db_nsir_update["operational-status"] = "terminated" |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 802 | db_nsir_update["config-status"] = "terminated" |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 803 | db_nsilcmop_update["statusEnteredTime"] = time() |
| 804 | db_nsilcmop_update["detailed-status"] = "done" |
| 805 | return |
| 806 | |
| 807 | except (LcmException, DbException) as e: |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 808 | self.logger.error( |
| 809 | logging_text + "Exit Exception while '{}': {}".format(step, e) |
| 810 | ) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 811 | exc = e |
| 812 | except asyncio.CancelledError: |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 813 | self.logger.error( |
| 814 | logging_text + "Cancelled Exception while '{}'".format(step) |
| 815 | ) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 816 | exc = "Operation was cancelled" |
| 817 | except Exception as e: |
| 818 | exc = traceback.format_exc() |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 819 | self.logger.critical( |
| 820 | logging_text |
| 821 | + "Exit Exception {} while '{}': {}".format(type(e).__name__, step, e), |
| 822 | exc_info=True, |
| 823 | ) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 824 | finally: |
| 825 | if exc: |
| 826 | if db_nsir: |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 827 | db_nsir_update["_admin.deployed"] = nsir_deployed |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 828 | db_nsir_update["detailed-status"] = "ERROR {}: {}".format(step, exc) |
| 829 | db_nsir_update["operational-status"] = "failed" |
| 830 | if db_nsilcmop: |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 831 | db_nsilcmop_update["detailed-status"] = "FAILED {}: {}".format( |
| 832 | step, exc |
| 833 | ) |
| 834 | db_nsilcmop_update[ |
| 835 | "operationState" |
| 836 | ] = nsilcmop_operation_state = "FAILED" |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 837 | db_nsilcmop_update["statusEnteredTime"] = time() |
| tierno | baa5110 | 2018-12-14 13:16:18 +0000 | [diff] [blame] | 838 | try: |
| 839 | if db_nsir: |
| Felipe Vicens | 720b07a | 2019-01-31 02:32:09 +0100 | [diff] [blame] | 840 | db_nsir_update["_admin.deployed"] = nsir_deployed |
| tierno | baa5110 | 2018-12-14 13:16:18 +0000 | [diff] [blame] | 841 | db_nsir_update["_admin.nsilcmop"] = None |
| tierno | baa5110 | 2018-12-14 13:16:18 +0000 | [diff] [blame] | 842 | self.update_db_2("nsis", nsir_id, db_nsir_update) |
| 843 | if db_nsilcmop: |
| 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)) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 847 | |
| 848 | if nsilcmop_operation_state: |
| 849 | try: |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 850 | await self.msg.aiowrite( |
| 851 | "nsi", |
| 852 | "terminated", |
| 853 | { |
| 854 | "nsir_id": nsir_id, |
| 855 | "nsilcmop_id": nsilcmop_id, |
| 856 | "operationState": nsilcmop_operation_state, |
| 857 | "autoremove": autoremove, |
| 858 | }, |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 859 | ) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 860 | except Exception as e: |
| garciadeblas | 5697b8b | 2021-03-24 09:17:02 +0100 | [diff] [blame] | 861 | self.logger.error( |
| 862 | logging_text + "kafka_write notification Exception {}".format(e) |
| 863 | ) |
| Felipe Vicens | c2033f2 | 2018-11-15 15:09:58 +0100 | [diff] [blame] | 864 | self.logger.debug(logging_text + "Exit") |
| 865 | self.lcm_tasks.remove("nsi", nsir_id, nsilcmop_id, "nsi_terminate") |