blob: 176f86d0df0d0c2778d76ddcf955d30aa7c62693 [file] [log] [blame]
tiernob24258a2018-10-04 18:39:49 +02001# -*- coding: utf-8 -*-
2
tiernod125caf2018-11-22 16:05:54 +00003# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain 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,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12# implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
tiernob24258a2018-10-04 18:39:49 +020016# import logging
Guillermo Calvino7fcbd4f2022-01-26 17:37:56 +010017import json
tiernob24258a2018-10-04 18:39:49 +020018from uuid import uuid4
19from http import HTTPStatus
20from time import time
tiernocc103432018-10-19 14:10:35 +020021from copy import copy, deepcopy
garciadeblas4568a372021-03-24 09:19:48 +010022from osm_nbi.validation import (
23 validate_input,
24 ValidationError,
25 ns_instantiate,
26 ns_terminate,
27 ns_action,
28 ns_scale,
aticig544a2ae2022-04-05 09:00:17 +030029 ns_update,
garciadeblas0964edf2022-02-11 00:43:44 +010030 ns_heal,
garciadeblas4568a372021-03-24 09:19:48 +010031 nsi_instantiate,
elumalai8e3806c2022-04-28 17:26:24 +053032 ns_migrate,
govindarajul519da482022-04-29 19:05:22 +053033 ns_verticalscale,
garciadeblas4568a372021-03-24 09:19:48 +010034)
35from osm_nbi.base_topic import (
36 BaseTopic,
37 EngineException,
38 get_iterable,
39 deep_get,
40 increment_ip_mac,
41)
tiernobee085c2018-12-12 17:03:04 +000042from yaml import safe_dump
Felipe Vicens09e65422019-01-22 15:06:46 +010043from osm_common.dbbase import DbException
tierno1bfe4e22019-09-02 16:03:25 +000044from osm_common.msgbase import MsgException
45from osm_common.fsbase import FsException
garciaale7cbd03c2020-11-27 10:38:35 -030046from osm_nbi import utils
garciadeblas4568a372021-03-24 09:19:48 +010047from re import (
48 match,
49) # For checking that additional parameter names are valid Jinja2 identifiers
tiernob24258a2018-10-04 18:39:49 +020050
51__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
52
53
54class NsrTopic(BaseTopic):
55 topic = "nsrs"
56 topic_msg = "ns"
tierno6b02b052020-06-02 10:07:41 +000057 quota_name = "ns_instances"
tiernod77ba6f2019-06-27 14:31:10 +000058 schema_new = ns_instantiate
tiernob24258a2018-10-04 18:39:49 +020059
delacruzramo32bab472019-09-13 12:24:22 +020060 def __init__(self, db, fs, msg, auth):
61 BaseTopic.__init__(self, db, fs, msg, auth)
tiernob24258a2018-10-04 18:39:49 +020062
63 def _check_descriptor_dependencies(self, session, descriptor):
64 """
65 Check that the dependent descriptors exist on a new descriptor or edition
66 :param session: client session information
67 :param descriptor: descriptor to be inserted or edit
68 :return: None or raises exception
69 """
70 if not descriptor.get("nsdId"):
71 return
72 nsd_id = descriptor["nsdId"]
73 if not self.get_item_list(session, "nsds", {"id": nsd_id}):
garciadeblas4568a372021-03-24 09:19:48 +010074 raise EngineException(
75 "Descriptor error at nsdId='{}' references a non exist nsd".format(
76 nsd_id
77 ),
78 http_code=HTTPStatus.CONFLICT,
79 )
tiernob24258a2018-10-04 18:39:49 +020080
81 @staticmethod
82 def format_on_new(content, project_id=None, make_public=False):
83 BaseTopic.format_on_new(content, project_id=project_id, make_public=make_public)
84 content["_admin"]["nsState"] = "NOT_INSTANTIATED"
tiernobdebce92019-07-01 15:36:49 +000085 return None
tiernob24258a2018-10-04 18:39:49 +020086
tiernob4844ab2019-05-23 08:42:12 +000087 def check_conflict_on_del(self, session, _id, db_content):
88 """
89 Check that NSR is not instantiated
90 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
91 :param _id: nsr internal id
92 :param db_content: The database content of the nsr
93 :return: None or raises EngineException with the conflict
94 """
tierno65ca36d2019-02-12 19:27:52 +010095 if session["force"]:
tiernob24258a2018-10-04 18:39:49 +020096 return
tiernob4844ab2019-05-23 08:42:12 +000097 nsr = db_content
tiernob24258a2018-10-04 18:39:49 +020098 if nsr["_admin"].get("nsState") == "INSTANTIATED":
garciadeblas4568a372021-03-24 09:19:48 +010099 raise EngineException(
100 "nsr '{}' cannot be deleted because it is in 'INSTANTIATED' state. "
101 "Launch 'terminate' operation first; or force deletion".format(_id),
102 http_code=HTTPStatus.CONFLICT,
103 )
tiernob24258a2018-10-04 18:39:49 +0200104
tiernobee3bad2019-12-05 12:26:01 +0000105 def delete_extra(self, session, _id, db_content, not_send_msg=None):
tiernob4844ab2019-05-23 08:42:12 +0000106 """
107 Deletes associated nslcmops and vnfrs from database. Deletes associated filesystem.
108 Set usageState of pdu, vnfd, nsd
109 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
110 :param _id: server internal id
111 :param db_content: The database content of the descriptor
tiernobee3bad2019-12-05 12:26:01 +0000112 :param not_send_msg: To not send message (False) or store content (list) instead
tiernob4844ab2019-05-23 08:42:12 +0000113 :return: None if ok or raises EngineException with the problem
114 """
tiernobee085c2018-12-12 17:03:04 +0000115 self.fs.file_delete(_id, ignore_non_exist=True)
tiernob24258a2018-10-04 18:39:49 +0200116 self.db.del_list("nslcmops", {"nsInstanceId": _id})
117 self.db.del_list("vnfrs", {"nsr-id-ref": _id})
tiernob4844ab2019-05-23 08:42:12 +0000118
tiernob24258a2018-10-04 18:39:49 +0200119 # set all used pdus as free
garciadeblas4568a372021-03-24 09:19:48 +0100120 self.db.set_list(
121 "pdus",
122 {"_admin.usage.nsr_id": _id},
123 {"_admin.usageState": "NOT_IN_USE", "_admin.usage": None},
124 )
tiernob24258a2018-10-04 18:39:49 +0200125
tiernob4844ab2019-05-23 08:42:12 +0000126 # Set NSD usageState
127 nsr = db_content
128 used_nsd_id = nsr.get("nsd-id")
129 if used_nsd_id:
130 # check if used by another NSR
garciadeblas4568a372021-03-24 09:19:48 +0100131 nsrs_list = self.db.get_one(
132 "nsrs", {"nsd-id": used_nsd_id}, fail_on_empty=False, fail_on_more=False
133 )
tiernob4844ab2019-05-23 08:42:12 +0000134 if not nsrs_list:
garciadeblas4568a372021-03-24 09:19:48 +0100135 self.db.set_one(
136 "nsds", {"_id": used_nsd_id}, {"_admin.usageState": "NOT_IN_USE"}
137 )
tiernob4844ab2019-05-23 08:42:12 +0000138
139 # Set VNFD usageState
140 used_vnfd_id_list = nsr.get("vnfd-id")
141 if used_vnfd_id_list:
142 for used_vnfd_id in used_vnfd_id_list:
143 # check if used by another NSR
garciadeblas4568a372021-03-24 09:19:48 +0100144 nsrs_list = self.db.get_one(
145 "nsrs",
146 {"vnfd-id": used_vnfd_id},
147 fail_on_empty=False,
148 fail_on_more=False,
149 )
tiernob4844ab2019-05-23 08:42:12 +0000150 if not nsrs_list:
garciadeblas4568a372021-03-24 09:19:48 +0100151 self.db.set_one(
152 "vnfds",
153 {"_id": used_vnfd_id},
154 {"_admin.usageState": "NOT_IN_USE"},
155 )
tiernob4844ab2019-05-23 08:42:12 +0000156
tiernof0441ea2020-05-26 15:39:18 +0000157 # delete extra ro_nsrs used for internal RO module
158 self.db.del_one("ro_nsrs", q_filter={"_id": _id}, fail_on_empty=False)
159
tiernobee085c2018-12-12 17:03:04 +0000160 @staticmethod
161 def _format_ns_request(ns_request):
162 formated_request = copy(ns_request)
163 formated_request.pop("additionalParamsForNs", None)
164 formated_request.pop("additionalParamsForVnf", None)
165 return formated_request
166
167 @staticmethod
garciadeblas4568a372021-03-24 09:19:48 +0100168 def _format_additional_params(
169 ns_request, member_vnf_index=None, vdu_id=None, kdu_name=None, descriptor=None
170 ):
tiernobee085c2018-12-12 17:03:04 +0000171 """
172 Get and format user additional params for NS or VNF
173 :param ns_request: User instantiation additional parameters
174 :param member_vnf_index: None for extract NS params, or member_vnf_index to extract VNF params
175 :param descriptor: If not None it check that needed parameters of descriptor are supplied
tierno54db2e42020-04-06 15:29:42 +0000176 :return: tuple with a formatted copy of additional params or None if not supplied, plus other parameters
tiernobee085c2018-12-12 17:03:04 +0000177 """
178 additional_params = None
tierno54db2e42020-04-06 15:29:42 +0000179 other_params = None
tiernobee085c2018-12-12 17:03:04 +0000180 if not member_vnf_index:
181 additional_params = copy(ns_request.get("additionalParamsForNs"))
182 where_ = "additionalParamsForNs"
183 elif ns_request.get("additionalParamsForVnf"):
garciadeblas4568a372021-03-24 09:19:48 +0100184 where_ = "additionalParamsForVnf[member-vnf-index={}]".format(
185 member_vnf_index
186 )
187 item = next(
188 (
189 x
190 for x in ns_request["additionalParamsForVnf"]
191 if x["member-vnf-index"] == member_vnf_index
192 ),
193 None,
194 )
tierno714954e2019-11-29 13:43:26 +0000195 if item:
tierno54db2e42020-04-06 15:29:42 +0000196 if not vdu_id and not kdu_name:
197 other_params = item
tierno714954e2019-11-29 13:43:26 +0000198 additional_params = copy(item.get("additionalParams")) or {}
199 if vdu_id and item.get("additionalParamsForVdu"):
garciadeblas4568a372021-03-24 09:19:48 +0100200 item_vdu = next(
201 (
202 x
203 for x in item["additionalParamsForVdu"]
204 if x["vdu_id"] == vdu_id
205 ),
206 None,
207 )
tiernobce98f02020-04-17 11:27:47 +0000208 other_params = item_vdu
tierno714954e2019-11-29 13:43:26 +0000209 if item_vdu and item_vdu.get("additionalParams"):
210 where_ += ".additionalParamsForVdu[vdu_id={}]".format(vdu_id)
tiernob091dc12019-12-02 15:53:25 +0000211 additional_params = item_vdu["additionalParams"]
212 if kdu_name:
213 additional_params = {}
214 if item.get("additionalParamsForKdu"):
garciadeblas4568a372021-03-24 09:19:48 +0100215 item_kdu = next(
216 (
217 x
218 for x in item["additionalParamsForKdu"]
219 if x["kdu_name"] == kdu_name
220 ),
221 None,
222 )
tiernobce98f02020-04-17 11:27:47 +0000223 other_params = item_kdu
tiernob091dc12019-12-02 15:53:25 +0000224 if item_kdu and item_kdu.get("additionalParams"):
garciadeblas4568a372021-03-24 09:19:48 +0100225 where_ += ".additionalParamsForKdu[kdu_name={}]".format(
226 kdu_name
227 )
tiernob091dc12019-12-02 15:53:25 +0000228 additional_params = item_kdu["additionalParams"]
tierno714954e2019-11-29 13:43:26 +0000229
tiernobee085c2018-12-12 17:03:04 +0000230 if additional_params:
231 for k, v in additional_params.items():
tierno714954e2019-11-29 13:43:26 +0000232 # BEGIN Check that additional parameter names are valid Jinja2 identifiers if target is not Kdu
garciadeblas4568a372021-03-24 09:19:48 +0100233 if not kdu_name and not match("^[a-zA-Z_][a-zA-Z0-9_]*$", k):
234 raise EngineException(
235 "Invalid param name at {}:{}. Must contain only alphanumeric characters "
236 "and underscores, and cannot start with a digit".format(
237 where_, k
238 )
239 )
delacruzramo36ffe552019-05-03 14:52:37 +0200240 # END Check that additional parameter names are valid Jinja2 identifiers
tiernobee085c2018-12-12 17:03:04 +0000241 if not isinstance(k, str):
garciadeblas4568a372021-03-24 09:19:48 +0100242 raise EngineException(
243 "Invalid param at {}:{}. Only string keys are allowed".format(
244 where_, k
245 )
246 )
Guillermo Calvino7fcbd4f2022-01-26 17:37:56 +0100247 if "$" in k:
garciadeblas4568a372021-03-24 09:19:48 +0100248 raise EngineException(
Guillermo Calvino7fcbd4f2022-01-26 17:37:56 +0100249 "Invalid param at {}:{}. Keys must not contain $ symbol".format(
garciadeblas4568a372021-03-24 09:19:48 +0100250 where_, k
251 )
252 )
tiernobee085c2018-12-12 17:03:04 +0000253 if isinstance(v, (dict, tuple, list)):
254 additional_params[k] = "!!yaml " + safe_dump(v)
Guillermo Calvino7fcbd4f2022-01-26 17:37:56 +0100255 if kdu_name:
256 additional_params = json.dumps(additional_params)
tiernobee085c2018-12-12 17:03:04 +0000257
258 if descriptor:
bravof41a52052021-02-17 18:08:01 -0300259 for df in descriptor.get("df", []):
260 # check that enough parameters are supplied for the initial-config-primitive
261 # TODO: check for cloud-init
262 if member_vnf_index:
garciaale7cbd03c2020-11-27 10:38:35 -0300263 initial_primitives = []
garciadeblas4568a372021-03-24 09:19:48 +0100264 if (
265 "lcm-operations-configuration" in df
266 and "operate-vnf-op-config"
267 in df["lcm-operations-configuration"]
268 ):
269 for config in df["lcm-operations-configuration"][
270 "operate-vnf-op-config"
271 ].get("day1-2", []):
272 for primitive in get_iterable(
273 config.get("initial-config-primitive")
274 ):
bravof41a52052021-02-17 18:08:01 -0300275 initial_primitives.append(primitive)
276 else:
garciadeblas4568a372021-03-24 09:19:48 +0100277 initial_primitives = deep_get(
278 descriptor, ("ns-configuration", "initial-config-primitive")
279 )
tiernobee085c2018-12-12 17:03:04 +0000280
bravof41a52052021-02-17 18:08:01 -0300281 for initial_primitive in get_iterable(initial_primitives):
282 for param in get_iterable(initial_primitive.get("parameter")):
garciadeblas4568a372021-03-24 09:19:48 +0100283 if param["value"].startswith("<") and param["value"].endswith(
284 ">"
285 ):
286 if param["value"] in (
287 "<rw_mgmt_ip>",
288 "<VDU_SCALE_INFO>",
289 "<ns_config_info>",
290 ):
bravof41a52052021-02-17 18:08:01 -0300291 continue
garciadeblas4568a372021-03-24 09:19:48 +0100292 if (
293 not additional_params
294 or param["value"][1:-1] not in additional_params
295 ):
296 raise EngineException(
297 "Parameter '{}' needed for vnfd[id={}]:day1-2 configuration:"
298 "initial-config-primitive[name={}] not supplied".format(
299 param["value"],
300 descriptor["id"],
301 initial_primitive["name"],
302 )
303 )
tierno714954e2019-11-29 13:43:26 +0000304
tierno54db2e42020-04-06 15:29:42 +0000305 return additional_params or None, other_params or None
tiernobee085c2018-12-12 17:03:04 +0000306
tierno65ca36d2019-02-12 19:27:52 +0100307 def new(self, rollback, session, indata=None, kwargs=None, headers=None):
tiernob24258a2018-10-04 18:39:49 +0200308 """
309 Creates a new nsr into database. It also creates needed vnfrs
310 :param rollback: list to append the created items at database in case a rollback must be done
tierno65ca36d2019-02-12 19:27:52 +0100311 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
tiernob24258a2018-10-04 18:39:49 +0200312 :param indata: params to be used for the nsr
313 :param kwargs: used to override the indata descriptor
314 :param headers: http request headers
tierno1bfe4e22019-09-02 16:03:25 +0000315 :return: the _id of nsr descriptor created at database. Or an exception of type
316 EngineException, ValidationError, DbException, FsException, MsgException.
317 Note: Exceptions are not captured on purpose. They should be captured at called
tiernob24258a2018-10-04 18:39:49 +0200318 """
tiernob24258a2018-10-04 18:39:49 +0200319 try:
delacruzramo32bab472019-09-13 12:24:22 +0200320 step = "checking quotas"
321 self.check_quota(session)
322
tierno99d4b172019-07-02 09:28:40 +0000323 step = "validating input parameters"
tiernob24258a2018-10-04 18:39:49 +0200324 ns_request = self._remove_envelop(indata)
tiernob24258a2018-10-04 18:39:49 +0200325 self._update_input_with_kwargs(ns_request, kwargs)
bravofb995ea22021-02-10 10:57:52 -0300326 ns_request = self._validate_input_new(ns_request, session["force"])
tiernob24258a2018-10-04 18:39:49 +0200327
tiernob24258a2018-10-04 18:39:49 +0200328 step = "getting nsd id='{}' from database".format(ns_request.get("nsdId"))
garciaale7cbd03c2020-11-27 10:38:35 -0300329 nsd = self._get_nsd_from_db(ns_request["nsdId"], session)
330 ns_k8s_namespace = self._get_ns_k8s_namespace(nsd, ns_request, session)
tiernob24258a2018-10-04 18:39:49 +0200331
Frank Bryden3c64ab62020-07-21 14:25:32 +0000332 step = "checking nsdOperationalState"
garciaale7cbd03c2020-11-27 10:38:35 -0300333 self._check_nsd_operational_state(nsd, ns_request)
Frank Bryden3c64ab62020-07-21 14:25:32 +0000334
tiernob24258a2018-10-04 18:39:49 +0200335 step = "filling nsr from input data"
garciaale7cbd03c2020-11-27 10:38:35 -0300336 nsr_id = str(uuid4())
garciadeblas4568a372021-03-24 09:19:48 +0100337 nsr_descriptor = self._create_nsr_descriptor_from_nsd(
338 nsd, ns_request, nsr_id, session
339 )
tierno54db2e42020-04-06 15:29:42 +0000340
garciaale7cbd03c2020-11-27 10:38:35 -0300341 # Create VNFRs
tiernob24258a2018-10-04 18:39:49 +0200342 needed_vnfds = {}
garciaale7cbd03c2020-11-27 10:38:35 -0300343 # TODO: Change for multiple df support
K Sai Kiranbb006022021-05-20 11:09:49 +0530344 vnf_profiles = nsd.get("df", [{}])[0].get("vnf-profile", ())
garciaale7cbd03c2020-11-27 10:38:35 -0300345 for vnfp in vnf_profiles:
346 vnfd_id = vnfp.get("vnfd-id")
347 vnf_index = vnfp.get("id")
garciadeblas4568a372021-03-24 09:19:48 +0100348 step = (
349 "getting vnfd id='{}' constituent-vnfd='{}' from database".format(
350 vnfd_id, vnf_index
351 )
352 )
tiernob24258a2018-10-04 18:39:49 +0200353 if vnfd_id not in needed_vnfds:
garciaale7cbd03c2020-11-27 10:38:35 -0300354 vnfd = self._get_vnfd_from_db(vnfd_id, session)
beierlmcee2ebf2022-03-29 17:42:48 -0400355 if "revision" in vnfd["_admin"]:
356 vnfd["revision"] = vnfd["_admin"]["revision"]
357 vnfd.pop("_admin")
tiernob24258a2018-10-04 18:39:49 +0200358 needed_vnfds[vnfd_id] = vnfd
tiernob4844ab2019-05-23 08:42:12 +0000359 nsr_descriptor["vnfd-id"].append(vnfd["_id"])
tiernob24258a2018-10-04 18:39:49 +0200360 else:
361 vnfd = needed_vnfds[vnfd_id]
tierno36ec8602018-11-02 17:27:11 +0100362
garciadeblas4568a372021-03-24 09:19:48 +0100363 step = "filling vnfr vnfd-id='{}' constituent-vnfd='{}'".format(
364 vnfd_id, vnf_index
365 )
366 vnfr_descriptor = self._create_vnfr_descriptor_from_vnfd(
367 nsd,
368 vnfd,
369 vnfd_id,
370 vnf_index,
371 nsr_descriptor,
372 ns_request,
373 ns_k8s_namespace,
374 )
tierno36ec8602018-11-02 17:27:11 +0100375
garciadeblas4568a372021-03-24 09:19:48 +0100376 step = "creating vnfr vnfd-id='{}' constituent-vnfd='{}' at database".format(
377 vnfd_id, vnf_index
378 )
garciaale7cbd03c2020-11-27 10:38:35 -0300379 self._add_vnfr_to_db(vnfr_descriptor, rollback, session)
380 nsr_descriptor["constituent-vnfr-ref"].append(vnfr_descriptor["id"])
tiernob24258a2018-10-04 18:39:49 +0200381
382 step = "creating nsr at database"
garciaale7cbd03c2020-11-27 10:38:35 -0300383 self._add_nsr_to_db(nsr_descriptor, rollback, session)
tiernobee085c2018-12-12 17:03:04 +0000384
385 step = "creating nsr temporal folder"
386 self.fs.mkdir(nsr_id)
387
tiernobdebce92019-07-01 15:36:49 +0000388 return nsr_id, None
garciadeblas4568a372021-03-24 09:19:48 +0100389 except (
390 ValidationError,
391 EngineException,
392 DbException,
393 MsgException,
394 FsException,
395 ) as e:
Frank Bryden3c64ab62020-07-21 14:25:32 +0000396 raise type(e)("{} while '{}'".format(e, step), http_code=e.http_code)
tiernob24258a2018-10-04 18:39:49 +0200397
garciaale7cbd03c2020-11-27 10:38:35 -0300398 def _get_nsd_from_db(self, nsd_id, session):
399 _filter = self._get_project_filter(session)
400 _filter["_id"] = nsd_id
401 return self.db.get_one("nsds", _filter)
402
403 def _get_vnfd_from_db(self, vnfd_id, session):
404 _filter = self._get_project_filter(session)
405 _filter["id"] = vnfd_id
406 vnfd = self.db.get_one("vnfds", _filter, fail_on_empty=True, fail_on_more=True)
garciaale7cbd03c2020-11-27 10:38:35 -0300407 return vnfd
408
409 def _add_nsr_to_db(self, nsr_descriptor, rollback, session):
garciadeblas4568a372021-03-24 09:19:48 +0100410 self.format_on_new(
411 nsr_descriptor, session["project_id"], make_public=session["public"]
412 )
garciaale7cbd03c2020-11-27 10:38:35 -0300413 self.db.create("nsrs", nsr_descriptor)
414 rollback.append({"topic": "nsrs", "_id": nsr_descriptor["id"]})
415
416 def _add_vnfr_to_db(self, vnfr_descriptor, rollback, session):
garciadeblas4568a372021-03-24 09:19:48 +0100417 self.format_on_new(
418 vnfr_descriptor, session["project_id"], make_public=session["public"]
419 )
garciaale7cbd03c2020-11-27 10:38:35 -0300420 self.db.create("vnfrs", vnfr_descriptor)
421 rollback.append({"topic": "vnfrs", "_id": vnfr_descriptor["id"]})
422
423 def _check_nsd_operational_state(self, nsd, ns_request):
424 if nsd["_admin"]["operationalState"] == "DISABLED":
garciadeblas4568a372021-03-24 09:19:48 +0100425 raise EngineException(
426 "nsd with id '{}' is DISABLED, and thus cannot be used to create "
427 "a network service".format(ns_request["nsdId"]),
428 http_code=HTTPStatus.CONFLICT,
429 )
garciaale7cbd03c2020-11-27 10:38:35 -0300430
431 def _get_ns_k8s_namespace(self, nsd, ns_request, session):
garciadeblas4568a372021-03-24 09:19:48 +0100432 additional_params, _ = self._format_additional_params(
433 ns_request, descriptor=nsd
434 )
garciaale7cbd03c2020-11-27 10:38:35 -0300435 # use for k8s-namespace from ns_request or additionalParamsForNs. By default, the project_id
436 ns_k8s_namespace = session["project_id"][0] if session["project_id"] else None
437 if ns_request and ns_request.get("k8s-namespace"):
438 ns_k8s_namespace = ns_request["k8s-namespace"]
439 if additional_params and additional_params.get("k8s-namespace"):
440 ns_k8s_namespace = additional_params["k8s-namespace"]
441
442 return ns_k8s_namespace
443
elumalai6c5ea6b2022-04-25 22:27:59 +0530444 def _add_flavor_to_nsr(self, vdu, vnfd, nsr_descriptor):
445 flavor_data = {}
446 guest_epa = {}
447 # Find this vdu compute and storage descriptors
448 vdu_virtual_compute = {}
449 vdu_virtual_storage = {}
450 for vcd in vnfd.get("virtual-compute-desc", ()):
451 if vcd.get("id") == vdu.get("virtual-compute-desc"):
452 vdu_virtual_compute = vcd
453 for vsd in vnfd.get("virtual-storage-desc", ()):
454 if vsd.get("id") == vdu.get("virtual-storage-desc", [[]])[0]:
455 vdu_virtual_storage = vsd
456 # Get this vdu vcpus, memory and storage info for flavor_data
457 if vdu_virtual_compute.get("virtual-cpu", {}).get(
458 "num-virtual-cpu"
459 ):
460 flavor_data["vcpu-count"] = vdu_virtual_compute["virtual-cpu"][
461 "num-virtual-cpu"
462 ]
463 if vdu_virtual_compute.get("virtual-memory", {}).get("size"):
464 flavor_data["memory-mb"] = (
465 float(vdu_virtual_compute["virtual-memory"]["size"])
466 * 1024.0
467 )
468 if vdu_virtual_storage.get("size-of-storage"):
469 flavor_data["storage-gb"] = vdu_virtual_storage[
470 "size-of-storage"
471 ]
472 # Get this vdu EPA info for guest_epa
473 if vdu_virtual_compute.get("virtual-cpu", {}).get("cpu-quota"):
474 guest_epa["cpu-quota"] = vdu_virtual_compute["virtual-cpu"][
475 "cpu-quota"
476 ]
477 if vdu_virtual_compute.get("virtual-cpu", {}).get("pinning"):
478 vcpu_pinning = vdu_virtual_compute["virtual-cpu"]["pinning"]
479 if vcpu_pinning.get("thread-policy"):
480 guest_epa["cpu-thread-pinning-policy"] = vcpu_pinning[
481 "thread-policy"
482 ]
483 if vcpu_pinning.get("policy"):
484 cpu_policy = (
485 "SHARED"
486 if vcpu_pinning["policy"] == "dynamic"
487 else "DEDICATED"
488 )
489 guest_epa["cpu-pinning-policy"] = cpu_policy
490 if vdu_virtual_compute.get("virtual-memory", {}).get("mem-quota"):
491 guest_epa["mem-quota"] = vdu_virtual_compute["virtual-memory"][
492 "mem-quota"
493 ]
494 if vdu_virtual_compute.get("virtual-memory", {}).get(
495 "mempage-size"
496 ):
497 guest_epa["mempage-size"] = vdu_virtual_compute[
498 "virtual-memory"
499 ]["mempage-size"]
500 if vdu_virtual_compute.get("virtual-memory", {}).get(
501 "numa-node-policy"
502 ):
503 guest_epa["numa-node-policy"] = vdu_virtual_compute[
504 "virtual-memory"
505 ]["numa-node-policy"]
506 if vdu_virtual_storage.get("disk-io-quota"):
507 guest_epa["disk-io-quota"] = vdu_virtual_storage[
508 "disk-io-quota"
509 ]
510
511 if guest_epa:
512 flavor_data["guest-epa"] = guest_epa
513
514 flavor_data["name"] = vdu["id"][:56] + "-flv"
515 flavor_data["id"] = str(len(nsr_descriptor["flavor"]))
516 nsr_descriptor["flavor"].append(flavor_data)
517
bravofe76b8822021-02-26 16:57:52 -0300518 def _create_nsr_descriptor_from_nsd(self, nsd, ns_request, nsr_id, session):
garciaale7cbd03c2020-11-27 10:38:35 -0300519 now = time()
garciadeblas4568a372021-03-24 09:19:48 +0100520 additional_params, _ = self._format_additional_params(
521 ns_request, descriptor=nsd
522 )
garciaale7cbd03c2020-11-27 10:38:35 -0300523
524 nsr_descriptor = {
525 "name": ns_request["nsName"],
526 "name-ref": ns_request["nsName"],
527 "short-name": ns_request["nsName"],
528 "admin-status": "ENABLED",
529 "nsState": "NOT_INSTANTIATED",
530 "currentOperation": "IDLE",
531 "currentOperationID": None,
532 "errorDescription": None,
533 "errorDetail": None,
534 "deploymentStatus": None,
535 "configurationStatus": None,
536 "vcaStatus": None,
537 "nsd": {k: v for k, v in nsd.items()},
538 "datacenter": ns_request["vimAccountId"],
539 "resource-orchestrator": "osmopenmano",
540 "description": ns_request.get("nsDescription", ""),
541 "constituent-vnfr-ref": [],
542 "operational-status": "init", # typedef ns-operational-
543 "config-status": "init", # typedef config-states
544 "detailed-status": "scheduled",
545 "orchestration-progress": {},
546 "create-time": now,
547 "nsd-name-ref": nsd["name"],
548 "operational-events": [], # "id", "timestamp", "description", "event",
549 "nsd-ref": nsd["id"],
550 "nsd-id": nsd["_id"],
551 "vnfd-id": [],
552 "instantiate_params": self._format_ns_request(ns_request),
553 "additionalParamsForNs": additional_params,
554 "ns-instance-config-ref": nsr_id,
555 "id": nsr_id,
556 "_id": nsr_id,
557 "ssh-authorized-key": ns_request.get("ssh_keys"), # TODO remove
558 "flavor": [],
559 "image": [],
Alexis Romero03fb5842022-03-11 15:53:40 +0100560 "affinity-or-anti-affinity-group": [],
garciaale7cbd03c2020-11-27 10:38:35 -0300561 }
beierlmbc5a5242022-05-17 21:25:29 -0400562 if "revision" in nsd["_admin"]:
563 nsr_descriptor["revision"] = nsd["_admin"]["revision"]
564
garciaale7cbd03c2020-11-27 10:38:35 -0300565 ns_request["nsr_id"] = nsr_id
566 if ns_request and ns_request.get("config-units"):
567 nsr_descriptor["config-units"] = ns_request["config-units"]
garciaale7cbd03c2020-11-27 10:38:35 -0300568 # Create vld
569 if nsd.get("virtual-link-desc"):
570 nsr_vld = deepcopy(nsd.get("virtual-link-desc", []))
571 # Fill each vld with vnfd-connection-point-ref data
572 # TODO: Change for multiple df support
573 all_vld_connection_point_data = {vld.get("id"): [] for vld in nsr_vld}
574 vnf_profiles = nsd.get("df", [[]])[0].get("vnf-profile", ())
575 for vnf_profile in vnf_profiles:
576 for vlc in vnf_profile.get("virtual-link-connectivity", ()):
577 for cpd in vlc.get("constituent-cpd-id", ()):
garciadeblas4568a372021-03-24 09:19:48 +0100578 all_vld_connection_point_data[
579 vlc.get("virtual-link-profile-id")
580 ].append(
581 {
582 "member-vnf-index-ref": cpd.get(
583 "constituent-base-element-id"
584 ),
585 "vnfd-connection-point-ref": cpd.get(
586 "constituent-cpd-id"
587 ),
588 "vnfd-id-ref": vnf_profile.get("vnfd-id"),
589 }
590 )
garciaale7cbd03c2020-11-27 10:38:35 -0300591
bravofe76b8822021-02-26 16:57:52 -0300592 vnfd = self._get_vnfd_from_db(vnf_profile.get("vnfd-id"), session)
beierlmcee2ebf2022-03-29 17:42:48 -0400593 vnfd.pop("_admin")
garciaale7cbd03c2020-11-27 10:38:35 -0300594
595 for vdu in vnfd.get("vdu", ()):
elumalai6c5ea6b2022-04-25 22:27:59 +0530596 self._add_flavor_to_nsr(vdu, vnfd, nsr_descriptor)
garciaale7cbd03c2020-11-27 10:38:35 -0300597 sw_image_id = vdu.get("sw-image-desc")
598 if sw_image_id:
lloretgalleg28c13b62021-02-08 11:48:48 +0000599 image_data = self._get_image_data_from_vnfd(vnfd, sw_image_id)
600 self._add_image_to_nsr(nsr_descriptor, image_data)
601
602 # also add alternative images to the list of images
603 for alt_image in vdu.get("alternative-sw-image-desc", ()):
604 image_data = self._get_image_data_from_vnfd(vnfd, alt_image)
605 self._add_image_to_nsr(nsr_descriptor, image_data)
garciaale7cbd03c2020-11-27 10:38:35 -0300606
Alexis Romero03fb5842022-03-11 15:53:40 +0100607 # Add Affinity or Anti-affinity group information to NSR
608 vdu_profiles = vnfd.get("df", [[]])[0].get("vdu-profile", ())
Alexis Romeroee31f532022-04-26 19:10:21 +0200609 affinity_group_prefix_name = "{}-{}".format(
610 nsr_descriptor["name"][:16], vnf_profile.get("id")[:16]
611 )
Alexis Romero03fb5842022-03-11 15:53:40 +0100612
613 for vdu_profile in vdu_profiles:
Alexis Romeroee31f532022-04-26 19:10:21 +0200614 affinity_group_data = {}
615 for affinity_group in vdu_profile.get(
616 "affinity-or-anti-affinity-group", ()
617 ):
618 affinity_group_data = (
619 self._get_affinity_or_anti_affinity_group_data_from_vnfd(
620 vnfd, affinity_group["id"]
621 )
622 )
623 affinity_group_data["member-vnf-index"] = vnf_profile.get("id")
624 self._add_affinity_or_anti_affinity_group_to_nsr(
625 nsr_descriptor,
626 affinity_group_data,
627 affinity_group_prefix_name,
628 )
Alexis Romero03fb5842022-03-11 15:53:40 +0100629
garciaale7cbd03c2020-11-27 10:38:35 -0300630 for vld in nsr_vld:
garciadeblas4568a372021-03-24 09:19:48 +0100631 vld["vnfd-connection-point-ref"] = all_vld_connection_point_data.get(
632 vld.get("id"), []
633 )
garciaale7cbd03c2020-11-27 10:38:35 -0300634 vld["name"] = vld["id"]
635 nsr_descriptor["vld"] = nsr_vld
636
637 return nsr_descriptor
638
Alexis Romeroee31f532022-04-26 19:10:21 +0200639 def _get_affinity_or_anti_affinity_group_data_from_vnfd(
640 self, vnfd, affinity_group_id
641 ):
Alexis Romero03fb5842022-03-11 15:53:40 +0100642 """
643 Gets affinity-or-anti-affinity-group info from df and returns the desired affinity group
644 """
Alexis Romeroee31f532022-04-26 19:10:21 +0200645 affinity_group = utils.find_in_list(
646 vnfd.get("df", [[]])[0].get("affinity-or-anti-affinity-group", ()),
647 lambda ag: ag["id"] == affinity_group_id,
Alexis Romero03fb5842022-03-11 15:53:40 +0100648 )
Alexis Romeroee31f532022-04-26 19:10:21 +0200649 affinity_group_data = {}
650 if affinity_group:
651 if affinity_group.get("id"):
652 affinity_group_data["ag-id"] = affinity_group["id"]
653 if affinity_group.get("type"):
654 affinity_group_data["type"] = affinity_group["type"]
655 if affinity_group.get("scope"):
656 affinity_group_data["scope"] = affinity_group["scope"]
657 return affinity_group_data
Alexis Romero03fb5842022-03-11 15:53:40 +0100658
Alexis Romeroee31f532022-04-26 19:10:21 +0200659 def _add_affinity_or_anti_affinity_group_to_nsr(
660 self, nsr_descriptor, affinity_group_data, affinity_group_prefix_name
661 ):
Alexis Romero03fb5842022-03-11 15:53:40 +0100662 """
663 Adds affinity-or-anti-affinity-group to nsr checking first it is not already added
664 """
Alexis Romeroee31f532022-04-26 19:10:21 +0200665 affinity_group = next(
Alexis Romero03fb5842022-03-11 15:53:40 +0100666 (
667 f
668 for f in nsr_descriptor["affinity-or-anti-affinity-group"]
Alexis Romeroee31f532022-04-26 19:10:21 +0200669 if all(f.get(k) == affinity_group_data[k] for k in affinity_group_data)
Alexis Romero03fb5842022-03-11 15:53:40 +0100670 ),
671 None,
672 )
Alexis Romeroee31f532022-04-26 19:10:21 +0200673 if not affinity_group:
674 affinity_group_data["id"] = str(
675 len(nsr_descriptor["affinity-or-anti-affinity-group"])
676 )
677 affinity_group_data["name"] = "{}-{}".format(
678 affinity_group_prefix_name, affinity_group_data["ag-id"][:32]
679 )
680 nsr_descriptor["affinity-or-anti-affinity-group"].append(
681 affinity_group_data
682 )
Alexis Romero03fb5842022-03-11 15:53:40 +0100683
lloretgalleg28c13b62021-02-08 11:48:48 +0000684 def _get_image_data_from_vnfd(self, vnfd, sw_image_id):
garciadeblas4568a372021-03-24 09:19:48 +0100685 sw_image_desc = utils.find_in_list(
686 vnfd.get("sw-image-desc", ()), lambda sw: sw["id"] == sw_image_id
687 )
lloretgalleg28c13b62021-02-08 11:48:48 +0000688 image_data = {}
689 if sw_image_desc.get("image"):
690 image_data["image"] = sw_image_desc["image"]
691 if sw_image_desc.get("checksum"):
692 image_data["image_checksum"] = sw_image_desc["checksum"]["hash"]
693 if sw_image_desc.get("vim-type"):
694 image_data["vim-type"] = sw_image_desc["vim-type"]
695 return image_data
696
697 def _add_image_to_nsr(self, nsr_descriptor, image_data):
698 """
699 Adds image to nsr checking first it is not already added
700 """
garciadeblas4568a372021-03-24 09:19:48 +0100701 img = next(
702 (
703 f
704 for f in nsr_descriptor["image"]
705 if all(f.get(k) == image_data[k] for k in image_data)
706 ),
707 None,
708 )
lloretgalleg28c13b62021-02-08 11:48:48 +0000709 if not img:
710 image_data["id"] = str(len(nsr_descriptor["image"]))
711 nsr_descriptor["image"].append(image_data)
712
garciadeblas4568a372021-03-24 09:19:48 +0100713 def _create_vnfr_descriptor_from_vnfd(
714 self,
715 nsd,
716 vnfd,
717 vnfd_id,
718 vnf_index,
719 nsr_descriptor,
720 ns_request,
721 ns_k8s_namespace,
722 ):
garciaale7cbd03c2020-11-27 10:38:35 -0300723 vnfr_id = str(uuid4())
724 nsr_id = nsr_descriptor["id"]
725 now = time()
garciadeblas4568a372021-03-24 09:19:48 +0100726 additional_params, vnf_params = self._format_additional_params(
727 ns_request, vnf_index, descriptor=vnfd
728 )
garciaale7cbd03c2020-11-27 10:38:35 -0300729
730 vnfr_descriptor = {
731 "id": vnfr_id,
732 "_id": vnfr_id,
733 "nsr-id-ref": nsr_id,
734 "member-vnf-index-ref": vnf_index,
735 "additionalParamsForVnf": additional_params,
736 "created-time": now,
737 # "vnfd": vnfd, # at OSM model.but removed to avoid data duplication TODO: revise
738 "vnfd-ref": vnfd_id,
739 "vnfd-id": vnfd["_id"], # not at OSM model, but useful
740 "vim-account-id": None,
David Garciaecb41322021-03-31 19:10:46 +0200741 "vca-id": None,
garciaale7cbd03c2020-11-27 10:38:35 -0300742 "vdur": [],
743 "connection-point": [],
744 "ip-address": None, # mgmt-interface filled by LCM
745 }
beierlmcee2ebf2022-03-29 17:42:48 -0400746
747 # Revision backwards compatility. Only specify the revision in the record if
748 # the original VNFD has a revision.
749 if "revision" in vnfd:
750 vnfr_descriptor["revision"] = vnfd["revision"]
751
752
garciaale7cbd03c2020-11-27 10:38:35 -0300753 vnf_k8s_namespace = ns_k8s_namespace
754 if vnf_params:
755 if vnf_params.get("k8s-namespace"):
756 vnf_k8s_namespace = vnf_params["k8s-namespace"]
757 if vnf_params.get("config-units"):
758 vnfr_descriptor["config-units"] = vnf_params["config-units"]
759
760 # Create vld
761 if vnfd.get("int-virtual-link-desc"):
762 vnfr_descriptor["vld"] = []
763 for vnfd_vld in vnfd.get("int-virtual-link-desc"):
764 vnfr_descriptor["vld"].append({key: vnfd_vld[key] for key in vnfd_vld})
765
766 for cp in vnfd.get("ext-cpd", ()):
767 vnf_cp = {
768 "name": cp.get("id"),
David Garcia1409c272020-12-02 15:47:46 +0100769 "connection-point-id": cp.get("int-cpd", {}).get("cpd"),
770 "connection-point-vdu-id": cp.get("int-cpd", {}).get("vdu-id"),
garciaale7cbd03c2020-11-27 10:38:35 -0300771 "id": cp.get("id"),
772 # "ip-address", "mac-address" # filled by LCM
773 # vim-id # TODO it would be nice having a vim port id
774 }
775 vnfr_descriptor["connection-point"].append(vnf_cp)
776
777 # Create k8s-cluster information
778 # TODO: Validate if a k8s-cluster net can have more than one ext-cpd ?
779 if vnfd.get("k8s-cluster"):
780 vnfr_descriptor["k8s-cluster"] = vnfd["k8s-cluster"]
781 all_k8s_cluster_nets_cpds = {}
782 for cpd in get_iterable(vnfd.get("ext-cpd")):
783 if cpd.get("k8s-cluster-net"):
garciadeblas4568a372021-03-24 09:19:48 +0100784 all_k8s_cluster_nets_cpds[cpd.get("k8s-cluster-net")] = cpd.get(
785 "id"
786 )
garciaale7cbd03c2020-11-27 10:38:35 -0300787 for net in get_iterable(vnfr_descriptor["k8s-cluster"].get("nets")):
788 if net.get("id") in all_k8s_cluster_nets_cpds:
garciadeblas4568a372021-03-24 09:19:48 +0100789 net["external-connection-point-ref"] = all_k8s_cluster_nets_cpds[
790 net.get("id")
791 ]
garciaale7cbd03c2020-11-27 10:38:35 -0300792
793 # update kdus
garciaale7cbd03c2020-11-27 10:38:35 -0300794 for kdu in get_iterable(vnfd.get("kdu")):
garciadeblas4568a372021-03-24 09:19:48 +0100795 additional_params, kdu_params = self._format_additional_params(
796 ns_request, vnf_index, kdu_name=kdu["name"], descriptor=vnfd
797 )
garciaale7cbd03c2020-11-27 10:38:35 -0300798 kdu_k8s_namespace = vnf_k8s_namespace
799 kdu_model = kdu_params.get("kdu_model") if kdu_params else None
800 if kdu_params and kdu_params.get("k8s-namespace"):
801 kdu_k8s_namespace = kdu_params["k8s-namespace"]
802
romeromonserbfebfc02021-05-28 10:51:35 +0200803 kdu_deployment_name = ""
804 if kdu_params and kdu_params.get("kdu-deployment-name"):
805 kdu_deployment_name = kdu_params.get("kdu-deployment-name")
806
garciaale7cbd03c2020-11-27 10:38:35 -0300807 kdur = {
808 "additionalParams": additional_params,
809 "k8s-namespace": kdu_k8s_namespace,
romeromonserbfebfc02021-05-28 10:51:35 +0200810 "kdu-deployment-name": kdu_deployment_name,
garciadeblas61e0c522020-12-15 10:33:40 +0000811 "kdu-name": kdu["name"],
garciaale7cbd03c2020-11-27 10:38:35 -0300812 # TODO "name": "" Name of the VDU in the VIM
813 "ip-address": None, # mgmt-interface filled by LCM
814 "k8s-cluster": {},
815 }
816 if kdu_params and kdu_params.get("config-units"):
817 kdur["config-units"] = kdu_params["config-units"]
garciadeblas61e0c522020-12-15 10:33:40 +0000818 if kdu.get("helm-version"):
819 kdur["helm-version"] = kdu["helm-version"]
820 for k8s_type in ("helm-chart", "juju-bundle"):
821 if kdu.get(k8s_type):
822 kdur[k8s_type] = kdu_model or kdu[k8s_type]
garciaale7cbd03c2020-11-27 10:38:35 -0300823 if not vnfr_descriptor.get("kdur"):
824 vnfr_descriptor["kdur"] = []
825 vnfr_descriptor["kdur"].append(kdur)
826
827 vnfd_mgmt_cp = vnfd.get("mgmt-cp")
bravof41a52052021-02-17 18:08:01 -0300828
garciaale7cbd03c2020-11-27 10:38:35 -0300829 for vdu in vnfd.get("vdu", ()):
bravoff3c39552021-02-24 17:22:24 -0300830 vdu_mgmt_cp = []
831 try:
garciadeblas4568a372021-03-24 09:19:48 +0100832 configs = vnfd.get("df")[0]["lcm-operations-configuration"][
833 "operate-vnf-op-config"
834 ]["day1-2"]
835 vdu_config = utils.find_in_list(
836 configs, lambda config: config["id"] == vdu["id"]
837 )
bravoff3c39552021-02-24 17:22:24 -0300838 except Exception:
839 vdu_config = None
bravof4ca51522021-04-22 10:03:02 -0400840
841 try:
842 vdu_instantiation_level = utils.find_in_list(
843 vnfd.get("df")[0]["instantiation-level"][0]["vdu-level"],
garciadeblas4568a372021-03-24 09:19:48 +0100844 lambda a_vdu_profile: a_vdu_profile["vdu-id"] == vdu["id"],
bravof4ca51522021-04-22 10:03:02 -0400845 )
846 except Exception:
847 vdu_instantiation_level = None
848
bravoff3c39552021-02-24 17:22:24 -0300849 if vdu_config:
850 external_connection_ee = utils.filter_in_list(
851 vdu_config.get("execution-environment-list", []),
garciadeblas4568a372021-03-24 09:19:48 +0100852 lambda ee: "external-connection-point-ref" in ee,
bravoff3c39552021-02-24 17:22:24 -0300853 )
854 for ee in external_connection_ee:
855 vdu_mgmt_cp.append(ee["external-connection-point-ref"])
856
garciaale7cbd03c2020-11-27 10:38:35 -0300857 additional_params, vdu_params = self._format_additional_params(
garciadeblas4568a372021-03-24 09:19:48 +0100858 ns_request, vnf_index, vdu_id=vdu["id"], descriptor=vnfd
859 )
bravof65e22e52021-11-10 17:58:58 -0300860
861 try:
862 vdu_virtual_storage_descriptors = utils.filter_in_list(
863 vnfd.get("virtual-storage-desc", []),
864 lambda stg_desc: stg_desc["id"] in vdu["virtual-storage-desc"]
865 )
866 except Exception:
867 vdu_virtual_storage_descriptors = []
garciaale7cbd03c2020-11-27 10:38:35 -0300868 vdur = {
869 "vdu-id-ref": vdu["id"],
870 # TODO "name": "" Name of the VDU in the VIM
871 "ip-address": None, # mgmt-interface filled by LCM
872 # "vim-id", "flavor-id", "image-id", "management-ip" # filled by LCM
873 "internal-connection-point": [],
874 "interfaces": [],
875 "additionalParams": additional_params,
garciadeblas4568a372021-03-24 09:19:48 +0100876 "vdu-name": vdu["name"],
bravof65e22e52021-11-10 17:58:58 -0300877 "virtual-storages": vdu_virtual_storage_descriptors
garciaale7cbd03c2020-11-27 10:38:35 -0300878 }
879 if vdu_params and vdu_params.get("config-units"):
880 vdur["config-units"] = vdu_params["config-units"]
881 if deep_get(vdu, ("supplemental-boot-data", "boot-data-drive")):
garciadeblas4568a372021-03-24 09:19:48 +0100882 vdur["boot-data-drive"] = vdu["supplemental-boot-data"][
883 "boot-data-drive"
884 ]
garciaale7cbd03c2020-11-27 10:38:35 -0300885 if vdu.get("pdu-type"):
886 vdur["pdu-type"] = vdu["pdu-type"]
887 vdur["name"] = vdu["pdu-type"]
888 # TODO volumes: name, volume-id
889 for icp in vdu.get("int-cpd", ()):
890 vdu_icp = {
891 "id": icp["id"],
892 "connection-point-id": icp["id"],
893 "name": icp.get("id"),
894 }
bravof35766442021-02-04 14:58:04 -0300895
garciaale7cbd03c2020-11-27 10:38:35 -0300896 vdur["internal-connection-point"].append(vdu_icp)
897
898 for iface in icp.get("virtual-network-interface-requirement", ()):
aticigc9c03392022-06-16 01:39:44 +0300899 # Name, mac-address and interface position is taken from VNFD
900 # and included into VNFR. By this way RO can process this information
901 # while creating the VDU.
902 iface_fields = ("name", "mac-address", "position")
garciadeblas4568a372021-03-24 09:19:48 +0100903 vdu_iface = {
904 x: iface[x] for x in iface_fields if iface.get(x) is not None
905 }
garciaale7cbd03c2020-11-27 10:38:35 -0300906
907 vdu_iface["internal-connection-point-ref"] = vdu_icp["id"]
sousaedu003844e2021-03-02 00:19:15 +0100908 if "port-security-enabled" in icp:
garciadeblas4568a372021-03-24 09:19:48 +0100909 vdu_iface["port-security-enabled"] = icp[
910 "port-security-enabled"
911 ]
sousaedu003844e2021-03-02 00:19:15 +0100912
913 if "port-security-disable-strategy" in icp:
garciadeblas4568a372021-03-24 09:19:48 +0100914 vdu_iface["port-security-disable-strategy"] = icp[
915 "port-security-disable-strategy"
916 ]
sousaedu003844e2021-03-02 00:19:15 +0100917
garciaale7cbd03c2020-11-27 10:38:35 -0300918 for ext_cp in vnfd.get("ext-cpd", ()):
919 if not ext_cp.get("int-cpd"):
920 continue
921 if ext_cp["int-cpd"].get("vdu-id") != vdu["id"]:
922 continue
923 if icp["id"] == ext_cp["int-cpd"].get("cpd"):
garciadeblas4568a372021-03-24 09:19:48 +0100924 vdu_iface["external-connection-point-ref"] = ext_cp.get(
925 "id"
926 )
sousaedu003844e2021-03-02 00:19:15 +0100927
928 if "port-security-enabled" in ext_cp:
garciadeblas4568a372021-03-24 09:19:48 +0100929 vdu_iface["port-security-enabled"] = ext_cp[
930 "port-security-enabled"
931 ]
sousaedu003844e2021-03-02 00:19:15 +0100932
933 if "port-security-disable-strategy" in ext_cp:
garciadeblas4568a372021-03-24 09:19:48 +0100934 vdu_iface["port-security-disable-strategy"] = ext_cp[
935 "port-security-disable-strategy"
936 ]
sousaedu003844e2021-03-02 00:19:15 +0100937
garciaale7cbd03c2020-11-27 10:38:35 -0300938 break
939
garciadeblas4568a372021-03-24 09:19:48 +0100940 if (
941 vnfd_mgmt_cp
942 and vdu_iface.get("external-connection-point-ref")
943 == vnfd_mgmt_cp
944 ):
garciaale7cbd03c2020-11-27 10:38:35 -0300945 vdu_iface["mgmt-vnf"] = True
bravoff3c39552021-02-24 17:22:24 -0300946 vdu_iface["mgmt-interface"] = True
947
948 for ecp in vdu_mgmt_cp:
949 if vdu_iface.get("external-connection-point-ref") == ecp:
950 vdu_iface["mgmt-interface"] = True
garciaale7cbd03c2020-11-27 10:38:35 -0300951
952 if iface.get("virtual-interface"):
953 vdu_iface.update(deepcopy(iface["virtual-interface"]))
954
955 # look for network where this interface is connected
956 iface_ext_cp = vdu_iface.get("external-connection-point-ref")
957 if iface_ext_cp:
958 # TODO: Change for multiple df support
959 for df in get_iterable(nsd.get("df")):
960 for vnf_profile in get_iterable(df.get("vnf-profile")):
garciadeblas4568a372021-03-24 09:19:48 +0100961 for vlc_index, vlc in enumerate(
962 get_iterable(
963 vnf_profile.get("virtual-link-connectivity")
964 )
965 ):
966 for cpd in get_iterable(
967 vlc.get("constituent-cpd-id")
968 ):
969 if (
970 cpd.get("constituent-cpd-id")
971 == iface_ext_cp
972 ):
973 vdu_iface["ns-vld-id"] = vlc.get(
974 "virtual-link-profile-id"
975 )
garciadeblas61c95912021-02-12 11:23:50 +0000976 # if iface type is SRIOV or PASSTHROUGH, set pci-interfaces flag to True
garciadeblas4568a372021-03-24 09:19:48 +0100977 if vdu_iface.get("type") in (
978 "SR-IOV",
979 "PCI-PASSTHROUGH",
980 ):
981 nsr_descriptor["vld"][vlc_index][
982 "pci-interfaces"
983 ] = True
garciaale7cbd03c2020-11-27 10:38:35 -0300984 break
985 elif vdu_iface.get("internal-connection-point-ref"):
986 vdu_iface["vnf-vld-id"] = icp.get("int-virtual-link-desc")
garciadeblas61c95912021-02-12 11:23:50 +0000987 # TODO: store fixed IP address in the record (if it exists in the ICP)
988 # if iface type is SRIOV or PASSTHROUGH, set pci-interfaces flag to True
989 if vdu_iface.get("type") in ("SR-IOV", "PCI-PASSTHROUGH"):
garciadeblas4568a372021-03-24 09:19:48 +0100990 ivld_index = utils.find_index_in_list(
991 vnfd.get("int-virtual-link-desc", ()),
992 lambda ivld: ivld["id"]
993 == icp.get("int-virtual-link-desc"),
994 )
garciadeblas61c95912021-02-12 11:23:50 +0000995 vnfr_descriptor["vld"][ivld_index]["pci-interfaces"] = True
garciaale7cbd03c2020-11-27 10:38:35 -0300996
997 vdur["interfaces"].append(vdu_iface)
998
999 if vdu.get("sw-image-desc"):
1000 sw_image = utils.find_in_list(
1001 vnfd.get("sw-image-desc", ()),
garciadeblas4568a372021-03-24 09:19:48 +01001002 lambda image: image["id"] == vdu.get("sw-image-desc"),
1003 )
garciaale7cbd03c2020-11-27 10:38:35 -03001004 nsr_sw_image_data = utils.find_in_list(
1005 nsr_descriptor["image"],
garciadeblas4568a372021-03-24 09:19:48 +01001006 lambda nsr_image: (nsr_image.get("image") == sw_image.get("image")),
garciaale7cbd03c2020-11-27 10:38:35 -03001007 )
1008 vdur["ns-image-id"] = nsr_sw_image_data["id"]
1009
lloretgalleg28c13b62021-02-08 11:48:48 +00001010 if vdu.get("alternative-sw-image-desc"):
1011 alt_image_ids = []
1012 for alt_image_id in vdu.get("alternative-sw-image-desc", ()):
1013 sw_image = utils.find_in_list(
1014 vnfd.get("sw-image-desc", ()),
garciadeblas4568a372021-03-24 09:19:48 +01001015 lambda image: image["id"] == alt_image_id,
1016 )
lloretgalleg28c13b62021-02-08 11:48:48 +00001017 nsr_sw_image_data = utils.find_in_list(
1018 nsr_descriptor["image"],
garciadeblas4568a372021-03-24 09:19:48 +01001019 lambda nsr_image: (
1020 nsr_image.get("image") == sw_image.get("image")
1021 ),
lloretgalleg28c13b62021-02-08 11:48:48 +00001022 )
1023 alt_image_ids.append(nsr_sw_image_data["id"])
1024 vdur["alt-image-ids"] = alt_image_ids
1025
garciaale7cbd03c2020-11-27 10:38:35 -03001026 flavor_data_name = vdu["id"][:56] + "-flv"
1027 nsr_flavor_desc = utils.find_in_list(
1028 nsr_descriptor["flavor"],
garciadeblas4568a372021-03-24 09:19:48 +01001029 lambda flavor: flavor["name"] == flavor_data_name,
1030 )
garciaale7cbd03c2020-11-27 10:38:35 -03001031
1032 if nsr_flavor_desc:
1033 vdur["ns-flavor-id"] = nsr_flavor_desc["id"]
1034
Alexis Romero03fb5842022-03-11 15:53:40 +01001035 # Adding Affinity groups information to vdur
1036 try:
Alexis Romeroee31f532022-04-26 19:10:21 +02001037 vdu_profile_affinity_group = utils.find_in_list(
Alexis Romero03fb5842022-03-11 15:53:40 +01001038 vnfd.get("df")[0]["vdu-profile"],
1039 lambda a_vdu: a_vdu["id"] == vdu["id"],
1040 )
1041 except Exception:
Alexis Romeroee31f532022-04-26 19:10:21 +02001042 vdu_profile_affinity_group = None
Alexis Romero03fb5842022-03-11 15:53:40 +01001043
Alexis Romeroee31f532022-04-26 19:10:21 +02001044 if vdu_profile_affinity_group:
1045 affinity_group_ids = []
1046 for affinity_group in vdu_profile_affinity_group.get(
1047 "affinity-or-anti-affinity-group", ()
1048 ):
1049 vdu_affinity_group = utils.find_in_list(
1050 vdu_profile_affinity_group.get(
1051 "affinity-or-anti-affinity-group", ()
1052 ),
1053 lambda ag_fp: ag_fp["id"] == affinity_group["id"],
Alexis Romero03fb5842022-03-11 15:53:40 +01001054 )
Alexis Romeroee31f532022-04-26 19:10:21 +02001055 nsr_affinity_group = utils.find_in_list(
Alexis Romero03fb5842022-03-11 15:53:40 +01001056 nsr_descriptor["affinity-or-anti-affinity-group"],
1057 lambda nsr_ag: (
Alexis Romeroee31f532022-04-26 19:10:21 +02001058 nsr_ag.get("ag-id") == vdu_affinity_group.get("id")
1059 and nsr_ag.get("member-vnf-index")
1060 == vnfr_descriptor.get("member-vnf-index-ref")
Alexis Romero03fb5842022-03-11 15:53:40 +01001061 ),
1062 )
Alexis Romeroee31f532022-04-26 19:10:21 +02001063 # Update Affinity Group VIM name if VDU instantiation parameter is present
1064 if vnf_params and vnf_params.get("affinity-or-anti-affinity-group"):
1065 vnf_params_affinity_group = utils.find_in_list(
1066 vnf_params["affinity-or-anti-affinity-group"],
1067 lambda vnfp_ag: (
1068 vnfp_ag.get("id") == vdu_affinity_group.get("id")
1069 ),
1070 )
1071 if vnf_params_affinity_group.get("vim-affinity-group-id"):
1072 nsr_affinity_group[
1073 "vim-affinity-group-id"
1074 ] = vnf_params_affinity_group["vim-affinity-group-id"]
1075 affinity_group_ids.append(nsr_affinity_group["id"])
1076 vdur["affinity-or-anti-affinity-group-id"] = affinity_group_ids
Alexis Romero03fb5842022-03-11 15:53:40 +01001077
bravof4ca51522021-04-22 10:03:02 -04001078 if vdu_instantiation_level:
1079 count = vdu_instantiation_level.get("number-of-instances")
1080 else:
1081 count = 1
1082
garciaale7cbd03c2020-11-27 10:38:35 -03001083 for index in range(0, count):
1084 vdur = deepcopy(vdur)
1085 for iface in vdur["interfaces"]:
bravofb7cdee12021-07-01 09:32:30 -04001086 if iface.get("ip-address") and index != 0:
garciaale7cbd03c2020-11-27 10:38:35 -03001087 iface["ip-address"] = increment_ip_mac(iface["ip-address"])
bravofb7cdee12021-07-01 09:32:30 -04001088 if iface.get("mac-address") and index != 0:
garciaale7cbd03c2020-11-27 10:38:35 -03001089 iface["mac-address"] = increment_ip_mac(iface["mac-address"])
1090
1091 vdur["_id"] = str(uuid4())
1092 vdur["id"] = vdur["_id"]
1093 vdur["count-index"] = index
1094 vnfr_descriptor["vdur"].append(vdur)
1095
1096 return vnfr_descriptor
1097
K Sai Kiran57589552021-01-27 21:38:34 +05301098 def vca_status_refresh(self, session, ns_instance_content, filter_q):
1099 """
1100 vcaStatus in ns_instance_content maybe stale, check if it is stale and create lcm op
1101 to refresh vca status by sending message to LCM when it is stale. Ignore otherwise.
1102 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
1103 :param ns_instance_content: ns instance content
1104 :param filter_q: dict: query parameter containing vcaStatus-refresh as true or false
1105 :return: None
1106 """
1107 time_now, time_delta = time(), time() - ns_instance_content["_admin"]["modified"]
1108 force_refresh = isinstance(filter_q, dict) and filter_q.get('vcaStatusRefresh') == 'true'
1109 threshold_reached = time_delta > 120
1110 if force_refresh or threshold_reached:
1111 operation, _id = "vca_status_refresh", ns_instance_content["_id"]
1112 ns_instance_content["_admin"]["modified"] = time_now
1113 self.db.set_one(self.topic, {"_id": _id}, ns_instance_content)
1114 nslcmop_desc = NsLcmOpTopic._create_nslcmop(_id, operation, None)
1115 self.format_on_new(nslcmop_desc, session["project_id"], make_public=session["public"])
1116 nslcmop_desc["_admin"].pop("nsState")
1117 self.msg.write("ns", operation, nslcmop_desc)
1118 return
1119
1120 def show(self, session, _id, filter_q=None, api_req=False):
1121 """
1122 Get complete information on an ns instance.
1123 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
1124 :param _id: string, ns instance id
1125 :param filter_q: dict: query parameter containing vcaStatusRefresh as true or false
1126 :param api_req: True if this call is serving an external API request. False if serving internal request.
1127 :return: dictionary, raise exception if not found.
1128 """
1129 ns_instance_content = super().show(session, _id, api_req)
1130 self.vca_status_refresh(session, ns_instance_content, filter_q)
1131 return ns_instance_content
1132
tierno65ca36d2019-02-12 19:27:52 +01001133 def edit(self, session, _id, indata=None, kwargs=None, content=None):
garciadeblas4568a372021-03-24 09:19:48 +01001134 raise EngineException(
1135 "Method edit called directly", HTTPStatus.INTERNAL_SERVER_ERROR
1136 )
tiernob24258a2018-10-04 18:39:49 +02001137
1138
1139class VnfrTopic(BaseTopic):
1140 topic = "vnfrs"
1141 topic_msg = None
1142
delacruzramo32bab472019-09-13 12:24:22 +02001143 def __init__(self, db, fs, msg, auth):
1144 BaseTopic.__init__(self, db, fs, msg, auth)
tiernob24258a2018-10-04 18:39:49 +02001145
tiernobee3bad2019-12-05 12:26:01 +00001146 def delete(self, session, _id, dry_run=False, not_send_msg=None):
garciadeblas4568a372021-03-24 09:19:48 +01001147 raise EngineException(
1148 "Method delete called directly", HTTPStatus.INTERNAL_SERVER_ERROR
1149 )
tiernob24258a2018-10-04 18:39:49 +02001150
tierno65ca36d2019-02-12 19:27:52 +01001151 def edit(self, session, _id, indata=None, kwargs=None, content=None):
garciadeblas4568a372021-03-24 09:19:48 +01001152 raise EngineException(
1153 "Method edit called directly", HTTPStatus.INTERNAL_SERVER_ERROR
1154 )
tiernob24258a2018-10-04 18:39:49 +02001155
tierno65ca36d2019-02-12 19:27:52 +01001156 def new(self, rollback, session, indata=None, kwargs=None, headers=None):
tiernob24258a2018-10-04 18:39:49 +02001157 # Not used because vnfrs are created and deleted by NsrTopic class directly
garciadeblas4568a372021-03-24 09:19:48 +01001158 raise EngineException(
1159 "Method new called directly", HTTPStatus.INTERNAL_SERVER_ERROR
1160 )
tiernob24258a2018-10-04 18:39:49 +02001161
1162
1163class NsLcmOpTopic(BaseTopic):
1164 topic = "nslcmops"
1165 topic_msg = "ns"
garciadeblas4568a372021-03-24 09:19:48 +01001166 operation_schema = { # mapping between operation and jsonschema to validate
tiernob24258a2018-10-04 18:39:49 +02001167 "instantiate": ns_instantiate,
1168 "action": ns_action,
aticig544a2ae2022-04-05 09:00:17 +03001169 "update": ns_update,
tiernob24258a2018-10-04 18:39:49 +02001170 "scale": ns_scale,
garciadeblas0964edf2022-02-11 00:43:44 +01001171 "heal": ns_heal,
tierno1c38f2f2020-03-24 11:51:39 +00001172 "terminate": ns_terminate,
elumalai8e3806c2022-04-28 17:26:24 +05301173 "migrate": ns_migrate,
govindarajul519da482022-04-29 19:05:22 +05301174 "verticalscale": ns_verticalscale,
tiernob24258a2018-10-04 18:39:49 +02001175 }
1176
delacruzramo32bab472019-09-13 12:24:22 +02001177 def __init__(self, db, fs, msg, auth):
1178 BaseTopic.__init__(self, db, fs, msg, auth)
elumalai6c5ea6b2022-04-25 22:27:59 +05301179 self.nsrtopic = NsrTopic(db, fs, msg, auth)
tiernob24258a2018-10-04 18:39:49 +02001180
tiernob24258a2018-10-04 18:39:49 +02001181 def _check_ns_operation(self, session, nsr, operation, indata):
1182 """
1183 Check that user has enter right parameters for the operation
tierno65ca36d2019-02-12 19:27:52 +01001184 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
garciadeblas0964edf2022-02-11 00:43:44 +01001185 :param operation: it can be: instantiate, terminate, action, update, heal
tiernob24258a2018-10-04 18:39:49 +02001186 :param indata: descriptor with the parameters of the operation
1187 :return: None
1188 """
garciaale7cbd03c2020-11-27 10:38:35 -03001189 if operation == "action":
1190 self._check_action_ns_operation(indata, nsr)
1191 elif operation == "scale":
1192 self._check_scale_ns_operation(indata, nsr)
aticig544a2ae2022-04-05 09:00:17 +03001193 elif operation == "update":
1194 self._check_update_ns_operation(indata, nsr)
garciadeblas0964edf2022-02-11 00:43:44 +01001195 elif operation == "heal":
1196 self._check_heal_ns_operation(indata, nsr)
garciaale7cbd03c2020-11-27 10:38:35 -03001197 elif operation == "instantiate":
1198 self._check_instantiate_ns_operation(indata, nsr, session)
1199
1200 def _check_action_ns_operation(self, indata, nsr):
1201 nsd = nsr["nsd"]
1202 # check vnf_member_index
1203 if indata.get("vnf_member_index"):
garciadeblas4568a372021-03-24 09:19:48 +01001204 indata["member_vnf_index"] = indata.pop(
1205 "vnf_member_index"
1206 ) # for backward compatibility
garciaale7cbd03c2020-11-27 10:38:35 -03001207 if indata.get("member_vnf_index"):
garciadeblas4568a372021-03-24 09:19:48 +01001208 vnfd = self._get_vnfd_from_vnf_member_index(
1209 indata["member_vnf_index"], nsr["_id"]
1210 )
bravof41a52052021-02-17 18:08:01 -03001211 try:
garciadeblas4568a372021-03-24 09:19:48 +01001212 configs = vnfd.get("df")[0]["lcm-operations-configuration"][
1213 "operate-vnf-op-config"
1214 ]["day1-2"]
bravof41a52052021-02-17 18:08:01 -03001215 except Exception:
1216 configs = []
1217
garciaale7cbd03c2020-11-27 10:38:35 -03001218 if indata.get("vdu_id"):
1219 self._check_valid_vdu(vnfd, indata["vdu_id"])
bravof41a52052021-02-17 18:08:01 -03001220 descriptor_configuration = utils.find_in_list(
garciadeblas4568a372021-03-24 09:19:48 +01001221 configs, lambda config: config["id"] == indata["vdu_id"]
limon9b33fa82021-03-17 13:24:00 +01001222 )
garciaale7cbd03c2020-11-27 10:38:35 -03001223 elif indata.get("kdu_name"):
1224 self._check_valid_kdu(vnfd, indata["kdu_name"])
bravof41a52052021-02-17 18:08:01 -03001225 descriptor_configuration = utils.find_in_list(
garciadeblas4568a372021-03-24 09:19:48 +01001226 configs, lambda config: config["id"] == indata.get("kdu_name")
limon9b33fa82021-03-17 13:24:00 +01001227 )
garciaale7cbd03c2020-11-27 10:38:35 -03001228 else:
bravof41a52052021-02-17 18:08:01 -03001229 descriptor_configuration = utils.find_in_list(
garciadeblas4568a372021-03-24 09:19:48 +01001230 configs, lambda config: config["id"] == vnfd["id"]
limon9b33fa82021-03-17 13:24:00 +01001231 )
1232 if descriptor_configuration is not None:
garciadeblas4568a372021-03-24 09:19:48 +01001233 descriptor_configuration = descriptor_configuration.get(
1234 "config-primitive"
1235 )
garciaale7cbd03c2020-11-27 10:38:35 -03001236 else: # use a NSD
garciadeblas4568a372021-03-24 09:19:48 +01001237 descriptor_configuration = nsd.get("ns-configuration", {}).get(
1238 "config-primitive"
1239 )
garciaale7cbd03c2020-11-27 10:38:35 -03001240
1241 # For k8s allows default primitives without validating the parameters
garciadeblas4568a372021-03-24 09:19:48 +01001242 if indata.get("kdu_name") and indata["primitive"] in (
1243 "upgrade",
1244 "rollback",
1245 "status",
1246 "inspect",
1247 "readme",
1248 ):
garciaale7cbd03c2020-11-27 10:38:35 -03001249 # TODO should be checked that rollback only can contains revsision_numbe????
1250 if not indata.get("member_vnf_index"):
garciadeblas4568a372021-03-24 09:19:48 +01001251 raise EngineException(
1252 "Missing action parameter 'member_vnf_index' for default KDU primitive '{}'".format(
1253 indata["primitive"]
1254 )
1255 )
garciaale7cbd03c2020-11-27 10:38:35 -03001256 return
1257 # if not, check primitive
1258 for config_primitive in get_iterable(descriptor_configuration):
1259 if indata["primitive"] == config_primitive["name"]:
1260 # check needed primitive_params are provided
1261 if indata.get("primitive_params"):
1262 in_primitive_params_copy = copy(indata["primitive_params"])
1263 else:
1264 in_primitive_params_copy = {}
1265 for paramd in get_iterable(config_primitive.get("parameter")):
1266 if paramd["name"] in in_primitive_params_copy:
1267 del in_primitive_params_copy[paramd["name"]]
1268 elif not paramd.get("default-value"):
garciadeblas4568a372021-03-24 09:19:48 +01001269 raise EngineException(
1270 "Needed parameter {} not provided for primitive '{}'".format(
1271 paramd["name"], indata["primitive"]
1272 )
1273 )
garciaale7cbd03c2020-11-27 10:38:35 -03001274 # check no extra primitive params are provided
1275 if in_primitive_params_copy:
garciadeblas4568a372021-03-24 09:19:48 +01001276 raise EngineException(
1277 "parameter/s '{}' not present at vnfd /nsd for primitive '{}'".format(
1278 list(in_primitive_params_copy.keys()), indata["primitive"]
1279 )
1280 )
garciaale7cbd03c2020-11-27 10:38:35 -03001281 break
1282 else:
garciadeblas4568a372021-03-24 09:19:48 +01001283 raise EngineException(
1284 "Invalid primitive '{}' is not present at vnfd/nsd".format(
1285 indata["primitive"]
1286 )
1287 )
garciaale7cbd03c2020-11-27 10:38:35 -03001288
aticig544a2ae2022-04-05 09:00:17 +03001289 def _check_update_ns_operation(self, indata, nsr) -> None:
1290 """Validates the ns-update request according to updateType
1291
1292 If updateType is CHANGE_VNFPKG:
1293 - it checks the vnfInstanceId, whether it's available under ns instance
1294 - it checks the vnfdId whether it matches with the vnfd-id in the vnf-record of specified VNF.
1295 Otherwise exception will be raised.
elumalai6380e7c2022-04-28 00:15:59 +05301296 If updateType is REMOVE_VNF:
1297 - it checks if the vnfInstanceId is available in the ns instance
1298 - Otherwise exception will be raised.
aticig544a2ae2022-04-05 09:00:17 +03001299
1300 Args:
1301 indata: includes updateType such as CHANGE_VNFPKG,
1302 nsr: network service record
1303
1304 Raises:
1305 EngineException:
1306 a meaningful error if given update parameters are not proper such as
1307 "Error in validating ns-update request: <ID> does not match
1308 with the vnfd-id of vnfinstance
1309 http_code=HTTPStatus.UNPROCESSABLE_ENTITY"
1310
1311 """
1312 try:
1313 if indata["updateType"] == "CHANGE_VNFPKG":
1314 # vnfInstanceId, nsInstanceId, vnfdId are mandatory
1315 vnf_instance_id = indata["changeVnfPackageData"]["vnfInstanceId"]
1316 ns_instance_id = indata["nsInstanceId"]
1317 vnfd_id_2update = indata["changeVnfPackageData"]["vnfdId"]
1318
1319 if vnf_instance_id not in nsr["constituent-vnfr-ref"]:
1320
1321 raise EngineException(
1322 f"Error in validating ns-update request: vnf {vnf_instance_id} does not "
1323 f"belong to NS {ns_instance_id}",
1324 http_code=HTTPStatus.UNPROCESSABLE_ENTITY,
1325 )
1326
1327 # Getting vnfrs through the ns_instance_id
1328 vnfrs = self.db.get_list("vnfrs", {"nsr-id-ref": ns_instance_id})
1329 constituent_vnfd_id = next(
1330 (
1331 vnfr["vnfd-id"]
1332 for vnfr in vnfrs
1333 if vnfr["id"] == vnf_instance_id
1334 ),
1335 None,
1336 )
1337
1338 # Check the given vnfd-id belongs to given vnf instance
1339 if constituent_vnfd_id and (vnfd_id_2update != constituent_vnfd_id):
1340
1341 raise EngineException(
1342 f"Error in validating ns-update request: vnfd-id {vnfd_id_2update} does not "
1343 f"match with the vnfd-id: {constituent_vnfd_id} of VNF instance: {vnf_instance_id}",
1344 http_code=HTTPStatus.UNPROCESSABLE_ENTITY,
1345 )
1346
1347 # Validating the ns update timeout
1348 if (
1349 indata.get("timeout_ns_update")
1350 and indata["timeout_ns_update"] < 300
1351 ):
1352 raise EngineException(
1353 "Error in validating ns-update request: {} second is not enough "
1354 "to upgrade the VNF instance: {}".format(
1355 indata["timeout_ns_update"], vnf_instance_id
1356 ),
1357 http_code=HTTPStatus.UNPROCESSABLE_ENTITY,
1358 )
elumalai6380e7c2022-04-28 00:15:59 +05301359 elif indata["updateType"] == "REMOVE_VNF":
1360 vnf_instance_id = indata["removeVnfInstanceId"]
1361 ns_instance_id = indata["nsInstanceId"]
1362 if vnf_instance_id not in nsr["constituent-vnfr-ref"]:
1363 raise EngineException(
1364 "Invalid VNF Instance Id. '{}' is not "
1365 "present in the NS '{}'".format(vnf_instance_id, ns_instance_id)
1366 )
aticig544a2ae2022-04-05 09:00:17 +03001367
1368 except (
1369 DbException,
1370 AttributeError,
1371 IndexError,
1372 KeyError,
1373 ValueError,
1374 ) as e:
1375 raise type(e)(
1376 "Ns update request could not be processed with error: {}.".format(e)
1377 )
1378
garciaale7cbd03c2020-11-27 10:38:35 -03001379 def _check_scale_ns_operation(self, indata, nsr):
garciadeblas4568a372021-03-24 09:19:48 +01001380 vnfd = self._get_vnfd_from_vnf_member_index(
1381 indata["scaleVnfData"]["scaleByStepData"]["member-vnf-index"], nsr["_id"]
1382 )
lloretgallegdf9fd612020-12-01 12:51:52 +00001383 for scaling_aspect in get_iterable(vnfd.get("df", ())[0]["scaling-aspect"]):
garciadeblas4568a372021-03-24 09:19:48 +01001384 if (
1385 indata["scaleVnfData"]["scaleByStepData"]["scaling-group-descriptor"]
1386 == scaling_aspect["id"]
1387 ):
garciaale7cbd03c2020-11-27 10:38:35 -03001388 break
1389 else:
garciadeblas4568a372021-03-24 09:19:48 +01001390 raise EngineException(
1391 "Invalid scaleVnfData:scaleByStepData:scaling-group-descriptor '{}' is not "
1392 "present at vnfd:scaling-aspect".format(
1393 indata["scaleVnfData"]["scaleByStepData"][
1394 "scaling-group-descriptor"
1395 ]
1396 )
1397 )
garciaale7cbd03c2020-11-27 10:38:35 -03001398
garciadeblas0964edf2022-02-11 00:43:44 +01001399 def _check_heal_ns_operation(self, indata, nsr):
1400 return
1401
garciaale7cbd03c2020-11-27 10:38:35 -03001402 def _check_instantiate_ns_operation(self, indata, nsr, session):
tierno982da4e2019-09-03 11:51:55 +00001403 vnf_member_index_to_vnfd = {} # map between vnf_member_index to vnf descriptor.
tiernob24258a2018-10-04 18:39:49 +02001404 vim_accounts = []
tierno4f9d4ae2019-03-20 17:24:11 +00001405 wim_accounts = []
tiernob24258a2018-10-04 18:39:49 +02001406 nsd = nsr["nsd"]
garciaale7cbd03c2020-11-27 10:38:35 -03001407 self._check_valid_vim_account(indata["vimAccountId"], vim_accounts, session)
1408 self._check_valid_wim_account(indata.get("wimAccountId"), wim_accounts, session)
1409 for in_vnf in get_iterable(indata.get("vnf")):
1410 member_vnf_index = in_vnf["member-vnf-index"]
tierno982da4e2019-09-03 11:51:55 +00001411 if vnf_member_index_to_vnfd.get(member_vnf_index):
garciaale7cbd03c2020-11-27 10:38:35 -03001412 vnfd = vnf_member_index_to_vnfd[member_vnf_index]
tierno260dd6f2019-09-02 10:48:56 +00001413 else:
garciadeblas4568a372021-03-24 09:19:48 +01001414 vnfd = self._get_vnfd_from_vnf_member_index(
1415 member_vnf_index, nsr["_id"]
1416 )
1417 vnf_member_index_to_vnfd[
1418 member_vnf_index
1419 ] = vnfd # add to cache, avoiding a later look for
garciaale7cbd03c2020-11-27 10:38:35 -03001420 self._check_vnf_instantiation_params(in_vnf, vnfd)
1421 if in_vnf.get("vimAccountId"):
garciadeblas4568a372021-03-24 09:19:48 +01001422 self._check_valid_vim_account(
1423 in_vnf["vimAccountId"], vim_accounts, session
1424 )
tierno260dd6f2019-09-02 10:48:56 +00001425
garciaale7cbd03c2020-11-27 10:38:35 -03001426 for in_vld in get_iterable(indata.get("vld")):
garciadeblas4568a372021-03-24 09:19:48 +01001427 self._check_valid_wim_account(
1428 in_vld.get("wimAccountId"), wim_accounts, session
1429 )
garciaale7cbd03c2020-11-27 10:38:35 -03001430 for vldd in get_iterable(nsd.get("virtual-link-desc")):
1431 if in_vld["name"] == vldd["id"]:
1432 break
tierno9cb7d672019-10-30 12:13:48 +00001433 else:
garciadeblas4568a372021-03-24 09:19:48 +01001434 raise EngineException(
1435 "Invalid parameter vld:name='{}' is not present at nsd:vld".format(
1436 in_vld["name"]
1437 )
1438 )
tierno9cb7d672019-10-30 12:13:48 +00001439
garciaale7cbd03c2020-11-27 10:38:35 -03001440 def _get_vnfd_from_vnf_member_index(self, member_vnf_index, nsr_id):
1441 # Obtain vnf descriptor. The vnfr is used to get the vnfd._id used for this member_vnf_index
garciadeblas4568a372021-03-24 09:19:48 +01001442 vnfr = self.db.get_one(
1443 "vnfrs",
1444 {"nsr-id-ref": nsr_id, "member-vnf-index-ref": member_vnf_index},
1445 fail_on_empty=False,
1446 )
garciaale7cbd03c2020-11-27 10:38:35 -03001447 if not vnfr:
garciadeblas4568a372021-03-24 09:19:48 +01001448 raise EngineException(
1449 "Invalid parameter member_vnf_index='{}' is not one of the "
1450 "nsd:constituent-vnfd".format(member_vnf_index)
1451 )
beierlmcee2ebf2022-03-29 17:42:48 -04001452
1453 ## Backwards compatibility: if there is no revision, get it from the one and only VNFD entry
1454 if "revision" in vnfr:
1455 vnfd_revision = vnfr["vnfd-id"] + ":" + str(vnfr["revision"])
1456 vnfd = self.db.get_one("vnfds_revisions", {"_id": vnfd_revision}, fail_on_empty=False)
1457 else:
1458 vnfd = self.db.get_one("vnfds", {"_id": vnfr["vnfd-id"]}, fail_on_empty=False)
1459
garciaale7cbd03c2020-11-27 10:38:35 -03001460 if not vnfd:
garciadeblas4568a372021-03-24 09:19:48 +01001461 raise EngineException(
1462 "vnfd id={} has been deleted!. Operation cannot be performed".format(
1463 vnfr["vnfd-id"]
1464 )
1465 )
garciaale7cbd03c2020-11-27 10:38:35 -03001466 return vnfd
gcalvino5e72d152018-10-23 11:46:57 +02001467
garciaale7cbd03c2020-11-27 10:38:35 -03001468 def _check_valid_vdu(self, vnfd, vdu_id):
1469 for vdud in get_iterable(vnfd.get("vdu")):
1470 if vdud["id"] == vdu_id:
1471 return vdud
1472 else:
garciadeblas4568a372021-03-24 09:19:48 +01001473 raise EngineException(
1474 "Invalid parameter vdu_id='{}' not present at vnfd:vdu:id".format(
1475 vdu_id
1476 )
1477 )
garciaale7cbd03c2020-11-27 10:38:35 -03001478
1479 def _check_valid_kdu(self, vnfd, kdu_name):
1480 for kdud in get_iterable(vnfd.get("kdu")):
1481 if kdud["name"] == kdu_name:
1482 return kdud
1483 else:
garciadeblas4568a372021-03-24 09:19:48 +01001484 raise EngineException(
1485 "Invalid parameter kdu_name='{}' not present at vnfd:kdu:name".format(
1486 kdu_name
1487 )
1488 )
garciaale7cbd03c2020-11-27 10:38:35 -03001489
1490 def _check_vnf_instantiation_params(self, in_vnf, vnfd):
1491 for in_vdu in get_iterable(in_vnf.get("vdu")):
1492 for vdu in get_iterable(vnfd.get("vdu")):
1493 if in_vdu["id"] == vdu["id"]:
1494 for volume in get_iterable(in_vdu.get("volume")):
1495 for volumed in get_iterable(vdu.get("virtual-storage-desc")):
aticigd7753fc2022-05-18 18:55:23 +03001496 if volumed == volume["name"]:
garciaale7cbd03c2020-11-27 10:38:35 -03001497 break
1498 else:
garciadeblas4568a372021-03-24 09:19:48 +01001499 raise EngineException(
1500 "Invalid parameter vnf[member-vnf-index='{}']:vdu[id='{}']:"
1501 "volume:name='{}' is not present at "
1502 "vnfd:vdu:virtual-storage-desc list".format(
1503 in_vnf["member-vnf-index"],
1504 in_vdu["id"],
1505 volume["id"],
1506 )
1507 )
garciaale7cbd03c2020-11-27 10:38:35 -03001508
1509 vdu_if_names = set()
1510 for cpd in get_iterable(vdu.get("int-cpd")):
garciadeblas4568a372021-03-24 09:19:48 +01001511 for iface in get_iterable(
1512 cpd.get("virtual-network-interface-requirement")
1513 ):
garciaale7cbd03c2020-11-27 10:38:35 -03001514 vdu_if_names.add(iface.get("name"))
1515
aticigd7753fc2022-05-18 18:55:23 +03001516 for in_iface in get_iterable(in_vdu.get("interface")):
garciaale7cbd03c2020-11-27 10:38:35 -03001517 if in_iface["name"] in vdu_if_names:
1518 break
1519 else:
garciadeblas4568a372021-03-24 09:19:48 +01001520 raise EngineException(
1521 "Invalid parameter vnf[member-vnf-index='{}']:vdu[id='{}']:"
1522 "int-cpd[id='{}'] is not present at vnfd:vdu:int-cpd".format(
1523 in_vnf["member-vnf-index"],
1524 in_vdu["id"],
1525 in_iface["name"],
1526 )
1527 )
garciaale7cbd03c2020-11-27 10:38:35 -03001528 break
1529
1530 else:
garciadeblas4568a372021-03-24 09:19:48 +01001531 raise EngineException(
1532 "Invalid parameter vnf[member-vnf-index='{}']:vdu[id='{}'] is not present "
1533 "at vnfd:vdu".format(in_vnf["member-vnf-index"], in_vdu["id"])
1534 )
garciaale7cbd03c2020-11-27 10:38:35 -03001535
garciadeblas4568a372021-03-24 09:19:48 +01001536 vnfd_ivlds_cpds = {
1537 ivld.get("id"): set()
1538 for ivld in get_iterable(vnfd.get("int-virtual-link-desc"))
1539 }
garciaale7cbd03c2020-11-27 10:38:35 -03001540 for vdu in get_iterable(vnfd.get("vdu")):
1541 for cpd in get_iterable(vnfd.get("int-cpd")):
1542 if cpd.get("int-virtual-link-desc"):
1543 vnfd_ivlds_cpds[cpd.get("int-virtual-link-desc")] = cpd.get("id")
1544
1545 for in_ivld in get_iterable(in_vnf.get("internal-vld")):
1546 if in_ivld.get("name") in vnfd_ivlds_cpds:
1547 for in_icp in get_iterable(in_ivld.get("internal-connection-point")):
1548 if in_icp["id-ref"] in vnfd_ivlds_cpds[in_ivld.get("name")]:
tierno40fbcad2018-10-26 10:58:15 +02001549 break
tiernob24258a2018-10-04 18:39:49 +02001550 else:
garciadeblas4568a372021-03-24 09:19:48 +01001551 raise EngineException(
1552 "Invalid parameter vnf[member-vnf-index='{}']:internal-vld[name"
1553 "='{}']:internal-connection-point[id-ref:'{}'] is not present at "
1554 "vnfd:internal-vld:name/id:internal-connection-point".format(
1555 in_vnf["member-vnf-index"],
1556 in_ivld["name"],
1557 in_icp["id-ref"],
1558 )
1559 )
tiernob24258a2018-10-04 18:39:49 +02001560 else:
garciadeblas4568a372021-03-24 09:19:48 +01001561 raise EngineException(
1562 "Invalid parameter vnf[member-vnf-index='{}']:internal-vld:name='{}'"
1563 " is not present at vnfd '{}'".format(
1564 in_vnf["member-vnf-index"], in_ivld["name"], vnfd["id"]
1565 )
1566 )
tiernob24258a2018-10-04 18:39:49 +02001567
garciaale7cbd03c2020-11-27 10:38:35 -03001568 def _check_valid_vim_account(self, vim_account, vim_accounts, session):
1569 if vim_account in vim_accounts:
1570 return
1571 try:
1572 db_filter = self._get_project_filter(session)
1573 db_filter["_id"] = vim_account
1574 self.db.get_one("vim_accounts", db_filter)
1575 except Exception:
garciadeblas4568a372021-03-24 09:19:48 +01001576 raise EngineException(
1577 "Invalid vimAccountId='{}' not present for the project".format(
1578 vim_account
1579 )
1580 )
garciaale7cbd03c2020-11-27 10:38:35 -03001581 vim_accounts.append(vim_account)
1582
David Garcia98de2982021-10-13 17:14:01 +02001583 def _get_vim_account(self, vim_id: str, session):
1584 try:
1585 db_filter = self._get_project_filter(session)
1586 db_filter["_id"] = vim_id
1587 return self.db.get_one("vim_accounts", db_filter)
1588 except Exception:
1589 raise EngineException(
1590 "Invalid vimAccountId='{}' not present for the project".format(
1591 vim_id
1592 )
1593 )
1594
garciaale7cbd03c2020-11-27 10:38:35 -03001595 def _check_valid_wim_account(self, wim_account, wim_accounts, session):
1596 if not isinstance(wim_account, str):
1597 return
1598 if wim_account in wim_accounts:
1599 return
1600 try:
1601 db_filter = self._get_project_filter(session, write=False, show_all=True)
1602 db_filter["_id"] = wim_account
1603 self.db.get_one("wim_accounts", db_filter)
1604 except Exception:
garciadeblas4568a372021-03-24 09:19:48 +01001605 raise EngineException(
1606 "Invalid wimAccountId='{}' not present for the project".format(
1607 wim_account
1608 )
1609 )
garciaale7cbd03c2020-11-27 10:38:35 -03001610 wim_accounts.append(wim_account)
tiernob24258a2018-10-04 18:39:49 +02001611
garciadeblas4568a372021-03-24 09:19:48 +01001612 def _look_for_pdu(
1613 self, session, rollback, vnfr, vim_account, vnfr_update, vnfr_update_rollback
1614 ):
tiernocc103432018-10-19 14:10:35 +02001615 """
tierno36ec8602018-11-02 17:27:11 +01001616 Look for a free PDU in the catalog matching vdur type and interfaces. Fills vnfr.vdur with the interface
1617 (ip_address, ...) information.
1618 Modifies PDU _admin.usageState to 'IN_USE'
tierno65ca36d2019-02-12 19:27:52 +01001619 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
tierno36ec8602018-11-02 17:27:11 +01001620 :param rollback: list with the database modifications to rollback if needed
1621 :param vnfr: vnfr to be updated. It is modified with pdu interface info if pdu is found
1622 :param vim_account: vim_account where this vnfr should be deployed
1623 :param vnfr_update: dictionary filled by this method with changes to be done at database vnfr
1624 :param vnfr_update_rollback: dictionary filled by this method with original content of vnfr in case a rollback
1625 of the changed vnfr is needed
1626
1627 :return: List of PDU interfaces that are connected to an existing VIM network. Each item contains:
1628 "vim-network-name": used at VIM
1629 "name": interface name
1630 "vnf-vld-id": internal VNFD vld where this interface is connected, or
1631 "ns-vld-id": NSD vld where this interface is connected.
1632 NOTE: One, and only one between 'vnf-vld-id' and 'ns-vld-id' contains a value. The other will be None
tiernocc103432018-10-19 14:10:35 +02001633 """
tierno36ec8602018-11-02 17:27:11 +01001634
1635 ifaces_forcing_vim_network = []
tiernocc103432018-10-19 14:10:35 +02001636 for vdur_index, vdur in enumerate(get_iterable(vnfr.get("vdur"))):
1637 if not vdur.get("pdu-type"):
1638 continue
1639 pdu_type = vdur.get("pdu-type")
tierno65ca36d2019-02-12 19:27:52 +01001640 pdu_filter = self._get_project_filter(session)
tierno36ec8602018-11-02 17:27:11 +01001641 pdu_filter["vim_accounts"] = vim_account
tiernocc103432018-10-19 14:10:35 +02001642 pdu_filter["type"] = pdu_type
1643 pdu_filter["_admin.operationalState"] = "ENABLED"
tierno36ec8602018-11-02 17:27:11 +01001644 pdu_filter["_admin.usageState"] = "NOT_IN_USE"
tiernocc103432018-10-19 14:10:35 +02001645 # TODO feature 1417: "shared": True,
1646
1647 available_pdus = self.db.get_list("pdus", pdu_filter)
1648 for pdu in available_pdus:
1649 # step 1 check if this pdu contains needed interfaces:
1650 match_interfaces = True
1651 for vdur_interface in vdur["interfaces"]:
1652 for pdu_interface in pdu["interfaces"]:
1653 if pdu_interface["name"] == vdur_interface["name"]:
1654 # TODO feature 1417: match per mgmt type
1655 break
1656 else: # no interface found for name
1657 match_interfaces = False
1658 break
1659 if match_interfaces:
1660 break
1661 else:
1662 raise EngineException(
tierno36ec8602018-11-02 17:27:11 +01001663 "No PDU of type={} at vim_account={} found for member_vnf_index={}, vdu={} matching interface "
garciadeblas4568a372021-03-24 09:19:48 +01001664 "names".format(
1665 pdu_type,
1666 vim_account,
1667 vnfr["member-vnf-index-ref"],
1668 vdur["vdu-id-ref"],
1669 )
1670 )
tiernocc103432018-10-19 14:10:35 +02001671
1672 # step 2. Update pdu
1673 rollback_pdu = {
1674 "_admin.usageState": pdu["_admin"]["usageState"],
1675 "_admin.usage.vnfr_id": None,
1676 "_admin.usage.nsr_id": None,
1677 "_admin.usage.vdur": None,
1678 }
garciadeblas4568a372021-03-24 09:19:48 +01001679 self.db.set_one(
1680 "pdus",
1681 {"_id": pdu["_id"]},
1682 {
1683 "_admin.usageState": "IN_USE",
1684 "_admin.usage": {
1685 "vnfr_id": vnfr["_id"],
1686 "nsr_id": vnfr["nsr-id-ref"],
1687 "vdur": vdur["vdu-id-ref"],
1688 },
1689 },
1690 )
1691 rollback.append(
1692 {
1693 "topic": "pdus",
1694 "_id": pdu["_id"],
1695 "operation": "set",
1696 "content": rollback_pdu,
1697 }
1698 )
tiernocc103432018-10-19 14:10:35 +02001699
1700 # step 3. Fill vnfr info by filling vdur
1701 vdu_text = "vdur.{}".format(vdur_index)
tierno36ec8602018-11-02 17:27:11 +01001702 vnfr_update_rollback[vdu_text + ".pdu-id"] = None
tiernocc103432018-10-19 14:10:35 +02001703 vnfr_update[vdu_text + ".pdu-id"] = pdu["_id"]
1704 for iface_index, vdur_interface in enumerate(vdur["interfaces"]):
1705 for pdu_interface in pdu["interfaces"]:
1706 if pdu_interface["name"] == vdur_interface["name"]:
1707 iface_text = vdu_text + ".interfaces.{}".format(iface_index)
1708 for k, v in pdu_interface.items():
garciadeblas4568a372021-03-24 09:19:48 +01001709 if k in (
1710 "ip-address",
1711 "mac-address",
1712 ): # TODO: switch-xxxxx must be inserted
tierno36ec8602018-11-02 17:27:11 +01001713 vnfr_update[iface_text + ".{}".format(k)] = v
garciadeblas4568a372021-03-24 09:19:48 +01001714 vnfr_update_rollback[
1715 iface_text + ".{}".format(k)
1716 ] = vdur_interface.get(v)
tierno36ec8602018-11-02 17:27:11 +01001717 if pdu_interface.get("ip-address"):
garciadeblas4568a372021-03-24 09:19:48 +01001718 if vdur_interface.get(
1719 "mgmt-interface"
1720 ) or vdur_interface.get("mgmt-vnf"):
1721 vnfr_update_rollback[
1722 vdu_text + ".ip-address"
1723 ] = vdur.get("ip-address")
1724 vnfr_update[vdu_text + ".ip-address"] = pdu_interface[
1725 "ip-address"
1726 ]
tierno36ec8602018-11-02 17:27:11 +01001727 if vdur_interface.get("mgmt-vnf"):
garciadeblas4568a372021-03-24 09:19:48 +01001728 vnfr_update_rollback["ip-address"] = vnfr.get(
1729 "ip-address"
1730 )
tierno36ec8602018-11-02 17:27:11 +01001731 vnfr_update["ip-address"] = pdu_interface["ip-address"]
garciadeblas4568a372021-03-24 09:19:48 +01001732 vnfr_update[vdu_text + ".ip-address"] = pdu_interface[
1733 "ip-address"
1734 ]
1735 if pdu_interface.get("vim-network-name") or pdu_interface.get(
1736 "vim-network-id"
1737 ):
1738 ifaces_forcing_vim_network.append(
1739 {
1740 "name": vdur_interface.get("vnf-vld-id")
1741 or vdur_interface.get("ns-vld-id"),
1742 "vnf-vld-id": vdur_interface.get("vnf-vld-id"),
1743 "ns-vld-id": vdur_interface.get("ns-vld-id"),
1744 }
1745 )
gcalvino17d5b732018-12-17 16:26:21 +01001746 if pdu_interface.get("vim-network-id"):
garciadeblas4568a372021-03-24 09:19:48 +01001747 ifaces_forcing_vim_network[-1][
1748 "vim-network-id"
1749 ] = pdu_interface["vim-network-id"]
gcalvino17d5b732018-12-17 16:26:21 +01001750 if pdu_interface.get("vim-network-name"):
garciadeblas4568a372021-03-24 09:19:48 +01001751 ifaces_forcing_vim_network[-1][
1752 "vim-network-name"
1753 ] = pdu_interface["vim-network-name"]
tiernocc103432018-10-19 14:10:35 +02001754 break
1755
tierno36ec8602018-11-02 17:27:11 +01001756 return ifaces_forcing_vim_network
tiernocc103432018-10-19 14:10:35 +02001757
garciadeblas4568a372021-03-24 09:19:48 +01001758 def _look_for_k8scluster(
1759 self, session, rollback, vnfr, vim_account, vnfr_update, vnfr_update_rollback
1760 ):
tierno9cb7d672019-10-30 12:13:48 +00001761 """
1762 Look for an available k8scluster for all the kuds in the vnfd matching version and cni requirements.
1763 Fills vnfr.kdur with the selected k8scluster
1764
1765 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
1766 :param rollback: list with the database modifications to rollback if needed
1767 :param vnfr: vnfr to be updated. It is modified with pdu interface info if pdu is found
1768 :param vim_account: vim_account where this vnfr should be deployed
1769 :param vnfr_update: dictionary filled by this method with changes to be done at database vnfr
1770 :param vnfr_update_rollback: dictionary filled by this method with original content of vnfr in case a rollback
1771 of the changed vnfr is needed
1772
1773 :return: List of KDU interfaces that are connected to an existing VIM network. Each item contains:
1774 "vim-network-name": used at VIM
1775 "name": interface name
1776 "vnf-vld-id": internal VNFD vld where this interface is connected, or
1777 "ns-vld-id": NSD vld where this interface is connected.
1778 NOTE: One, and only one between 'vnf-vld-id' and 'ns-vld-id' contains a value. The other will be None
1779 """
1780
1781 ifaces_forcing_vim_network = []
tiernoc67b0e92019-11-05 12:45:29 +00001782 if not vnfr.get("kdur"):
1783 return ifaces_forcing_vim_network
tierno9cb7d672019-10-30 12:13:48 +00001784
tiernoc67b0e92019-11-05 12:45:29 +00001785 kdu_filter = self._get_project_filter(session)
1786 kdu_filter["vim_account"] = vim_account
1787 # TODO kdu_filter["_admin.operationalState"] = "ENABLED"
1788 available_k8sclusters = self.db.get_list("k8sclusters", kdu_filter)
1789
1790 k8s_requirements = {} # just for logging
1791 for k8scluster in available_k8sclusters:
1792 if not vnfr.get("k8s-cluster"):
tierno9cb7d672019-10-30 12:13:48 +00001793 break
tiernoc67b0e92019-11-05 12:45:29 +00001794 # restrict by cni
1795 if vnfr["k8s-cluster"].get("cni"):
1796 k8s_requirements["cni"] = vnfr["k8s-cluster"]["cni"]
garciadeblas4568a372021-03-24 09:19:48 +01001797 if not set(vnfr["k8s-cluster"]["cni"]).intersection(
1798 k8scluster.get("cni", ())
1799 ):
tiernoc67b0e92019-11-05 12:45:29 +00001800 continue
1801 # restrict by version
1802 if vnfr["k8s-cluster"].get("version"):
1803 k8s_requirements["version"] = vnfr["k8s-cluster"]["version"]
1804 if k8scluster.get("k8s_version") not in vnfr["k8s-cluster"]["version"]:
1805 continue
1806 # restrict by number of networks
1807 if vnfr["k8s-cluster"].get("nets"):
1808 k8s_requirements["networks"] = len(vnfr["k8s-cluster"]["nets"])
garciadeblas4568a372021-03-24 09:19:48 +01001809 if not k8scluster.get("nets") or len(k8scluster["nets"]) < len(
1810 vnfr["k8s-cluster"]["nets"]
1811 ):
tiernoc67b0e92019-11-05 12:45:29 +00001812 continue
1813 break
1814 else:
garciadeblas4568a372021-03-24 09:19:48 +01001815 raise EngineException(
1816 "No k8scluster with requirements='{}' at vim_account={} found for member_vnf_index={}".format(
1817 k8s_requirements, vim_account, vnfr["member-vnf-index-ref"]
1818 )
1819 )
tierno9cb7d672019-10-30 12:13:48 +00001820
tiernoc67b0e92019-11-05 12:45:29 +00001821 for kdur_index, kdur in enumerate(get_iterable(vnfr.get("kdur"))):
tierno9cb7d672019-10-30 12:13:48 +00001822 # step 3. Fill vnfr info by filling kdur
1823 kdu_text = "kdur.{}.".format(kdur_index)
1824 vnfr_update_rollback[kdu_text + "k8s-cluster.id"] = None
1825 vnfr_update[kdu_text + "k8s-cluster.id"] = k8scluster["_id"]
1826
tiernoc67b0e92019-11-05 12:45:29 +00001827 # step 4. Check VIM networks that forces the selected k8s_cluster
1828 if vnfr.get("k8s-cluster") and vnfr["k8s-cluster"].get("nets"):
1829 k8scluster_net_list = list(k8scluster.get("nets").keys())
1830 for net_index, kdur_net in enumerate(vnfr["k8s-cluster"]["nets"]):
1831 # get a network from k8s_cluster nets. If name matches use this, if not use other
1832 if kdur_net["id"] in k8scluster_net_list: # name matches
1833 vim_net = k8scluster["nets"][kdur_net["id"]]
1834 k8scluster_net_list.remove(kdur_net["id"])
1835 else:
1836 vim_net = k8scluster["nets"][k8scluster_net_list[0]]
1837 k8scluster_net_list.pop(0)
garciadeblas4568a372021-03-24 09:19:48 +01001838 vnfr_update_rollback[
1839 "k8s-cluster.nets.{}.vim_net".format(net_index)
1840 ] = None
tiernoc67b0e92019-11-05 12:45:29 +00001841 vnfr_update["k8s-cluster.nets.{}.vim_net".format(net_index)] = vim_net
garciadeblas4568a372021-03-24 09:19:48 +01001842 if vim_net and (
1843 kdur_net.get("vnf-vld-id") or kdur_net.get("ns-vld-id")
1844 ):
1845 ifaces_forcing_vim_network.append(
1846 {
1847 "name": kdur_net.get("vnf-vld-id")
1848 or kdur_net.get("ns-vld-id"),
1849 "vnf-vld-id": kdur_net.get("vnf-vld-id"),
1850 "ns-vld-id": kdur_net.get("ns-vld-id"),
1851 "vim-network-name": vim_net, # TODO can it be vim-network-id ???
1852 }
1853 )
tiernoc67b0e92019-11-05 12:45:29 +00001854 # TODO check that this forcing is not incompatible with other forcing
tierno9cb7d672019-10-30 12:13:48 +00001855 return ifaces_forcing_vim_network
1856
Gulsum Aticie395aa42021-11-10 20:59:06 +03001857 def _update_vnfrs_from_nsd(self, nsr):
1858 try:
1859 nsr_id = nsr["_id"]
1860 nsd = nsr["nsd"]
1861
1862 step = "Getting vnf_profiles from nsd"
1863 vnf_profiles = nsd.get("df", [{}])[0].get("vnf-profile", ())
1864 vld_fixed_ip_connection_point_data = {}
1865
1866 step = "Getting ip-address info from vnf_profile if it exists"
1867 for vnfp in vnf_profiles:
1868 # Checking ip-address info from nsd.vnf_profile and storing
1869 for vlc in vnfp.get("virtual-link-connectivity", ()):
1870 for cpd in vlc.get("constituent-cpd-id", ()):
1871 if cpd.get("ip-address"):
1872 step = "Storing ip-address info"
1873 vld_fixed_ip_connection_point_data.update({vlc.get("virtual-link-profile-id") + '.' + cpd.get("constituent-base-element-id"): {
1874 "vnfd-connection-point-ref": cpd.get(
1875 "constituent-cpd-id"),
1876 "ip-address": cpd.get(
1877 "ip-address")}})
1878
1879 # Inserting ip address to vnfr
1880 if len(vld_fixed_ip_connection_point_data) > 0:
1881 step = "Getting vnfrs"
1882 vnfrs = self.db.get_list("vnfrs", {"nsr-id-ref": nsr_id})
1883 for item in vld_fixed_ip_connection_point_data.keys():
1884 step = "Filtering vnfrs"
1885 vnfr = next(filter(lambda vnfr: vnfr["member-vnf-index-ref"] == item.split('.')[1], vnfrs), None)
1886 if vnfr:
1887 vnfr_update = {}
1888 for vdur_index, vdur in enumerate(vnfr["vdur"]):
1889 for iface_index, iface in enumerate(vdur["interfaces"]):
1890 step = "Looking for matched interface"
1891 if (
1892 iface.get("external-connection-point-ref")
1893 == vld_fixed_ip_connection_point_data[item].get("vnfd-connection-point-ref") and
1894 iface.get("ns-vld-id") == item.split('.')[0]
1895
1896 ):
1897 vnfr_update_text = "vdur.{}.interfaces.{}".format(
1898 vdur_index, iface_index
1899 )
1900 step = "Storing info in order to update vnfr"
1901 vnfr_update[
1902 vnfr_update_text + ".ip-address"
1903 ] = increment_ip_mac(
1904 vld_fixed_ip_connection_point_data[item].get("ip-address"),
1905 vdur.get("count-index", 0), )
1906 vnfr_update[vnfr_update_text + ".fixed-ip"] = True
1907
1908 step = "updating vnfr at database"
1909 self.db.set_one("vnfrs", {"_id": vnfr["_id"]}, vnfr_update)
1910 except (
1911 ValidationError,
1912 EngineException,
1913 DbException,
1914 MsgException,
1915 FsException,
1916 ) as e:
1917 raise type(e)("{} while '{}'".format(e, step), http_code=e.http_code)
1918
tiernocc103432018-10-19 14:10:35 +02001919 def _update_vnfrs(self, session, rollback, nsr, indata):
tiernocc103432018-10-19 14:10:35 +02001920 # get vnfr
1921 nsr_id = nsr["_id"]
1922 vnfrs = self.db.get_list("vnfrs", {"nsr-id-ref": nsr_id})
1923
1924 for vnfr in vnfrs:
1925 vnfr_update = {}
1926 vnfr_update_rollback = {}
1927 member_vnf_index = vnfr["member-vnf-index-ref"]
1928 # update vim-account-id
1929
1930 vim_account = indata["vimAccountId"]
David Garcia98de2982021-10-13 17:14:01 +02001931 vca_id = self._get_vim_account(vim_account, session).get("vca")
tiernocc103432018-10-19 14:10:35 +02001932 # check instantiate parameters
1933 for vnf_inst_params in get_iterable(indata.get("vnf")):
1934 if vnf_inst_params["member-vnf-index"] != member_vnf_index:
1935 continue
1936 if vnf_inst_params.get("vimAccountId"):
1937 vim_account = vnf_inst_params.get("vimAccountId")
David Garcia98de2982021-10-13 17:14:01 +02001938 vca_id = self._get_vim_account(vim_account, session).get("vca")
tiernocc103432018-10-19 14:10:35 +02001939
tiernocddb07d2020-10-06 08:28:00 +00001940 # get vnf.vdu.interface instantiation params to update vnfr.vdur.interfaces ip, mac
1941 for vdu_inst_param in get_iterable(vnf_inst_params.get("vdu")):
1942 for vdur_index, vdur in enumerate(vnfr["vdur"]):
1943 if vdu_inst_param["id"] != vdur["vdu-id-ref"]:
1944 continue
garciadeblas4568a372021-03-24 09:19:48 +01001945 for iface_inst_param in get_iterable(
1946 vdu_inst_param.get("interface")
1947 ):
1948 iface_index, _ = next(
1949 i
1950 for i in enumerate(vdur["interfaces"])
1951 if i[1]["name"] == iface_inst_param["name"]
1952 )
1953 vnfr_update_text = "vdur.{}.interfaces.{}".format(
1954 vdur_index, iface_index
1955 )
tiernocddb07d2020-10-06 08:28:00 +00001956 if iface_inst_param.get("ip-address"):
garciadeblas4568a372021-03-24 09:19:48 +01001957 vnfr_update[
1958 vnfr_update_text + ".ip-address"
1959 ] = increment_ip_mac(
1960 iface_inst_param.get("ip-address"),
1961 vdur.get("count-index", 0),
1962 )
tierno1bd9d952020-11-13 15:56:51 +00001963 vnfr_update[vnfr_update_text + ".fixed-ip"] = True
tiernocddb07d2020-10-06 08:28:00 +00001964 if iface_inst_param.get("mac-address"):
garciadeblas4568a372021-03-24 09:19:48 +01001965 vnfr_update[
1966 vnfr_update_text + ".mac-address"
1967 ] = increment_ip_mac(
1968 iface_inst_param.get("mac-address"),
1969 vdur.get("count-index", 0),
1970 )
tierno1bd9d952020-11-13 15:56:51 +00001971 vnfr_update[vnfr_update_text + ".fixed-mac"] = True
bravofe4254fd2021-02-03 15:22:06 -03001972 if iface_inst_param.get("floating-ip-required"):
garciadeblas4568a372021-03-24 09:19:48 +01001973 vnfr_update[
1974 vnfr_update_text + ".floating-ip-required"
1975 ] = True
tiernocddb07d2020-10-06 08:28:00 +00001976 # get vnf.internal-vld.internal-conection-point instantiation params to update vnfr.vdur.interfaces
1977 # TODO update vld with the ip-profile
garciadeblas4568a372021-03-24 09:19:48 +01001978 for ivld_inst_param in get_iterable(
1979 vnf_inst_params.get("internal-vld")
1980 ):
1981 for icp_inst_param in get_iterable(
1982 ivld_inst_param.get("internal-connection-point")
1983 ):
tiernocddb07d2020-10-06 08:28:00 +00001984 # look for iface
1985 for vdur_index, vdur in enumerate(vnfr["vdur"]):
1986 for iface_index, iface in enumerate(vdur["interfaces"]):
garciadeblas4568a372021-03-24 09:19:48 +01001987 if (
1988 iface.get("internal-connection-point-ref")
1989 == icp_inst_param["id-ref"]
1990 ):
1991 vnfr_update_text = "vdur.{}.interfaces.{}".format(
1992 vdur_index, iface_index
1993 )
tiernocddb07d2020-10-06 08:28:00 +00001994 if icp_inst_param.get("ip-address"):
garciadeblas4568a372021-03-24 09:19:48 +01001995 vnfr_update[
1996 vnfr_update_text + ".ip-address"
1997 ] = increment_ip_mac(
1998 icp_inst_param.get("ip-address"),
1999 vdur.get("count-index", 0),
2000 )
2001 vnfr_update[
2002 vnfr_update_text + ".fixed-ip"
2003 ] = True
tiernocddb07d2020-10-06 08:28:00 +00002004 if icp_inst_param.get("mac-address"):
garciadeblas4568a372021-03-24 09:19:48 +01002005 vnfr_update[
2006 vnfr_update_text + ".mac-address"
2007 ] = increment_ip_mac(
2008 icp_inst_param.get("mac-address"),
2009 vdur.get("count-index", 0),
2010 )
2011 vnfr_update[
2012 vnfr_update_text + ".fixed-mac"
2013 ] = True
tiernocddb07d2020-10-06 08:28:00 +00002014 break
2015 # get ip address from instantiation parameters.vld.vnfd-connection-point-ref
2016 for vld_inst_param in get_iterable(indata.get("vld")):
garciadeblas4568a372021-03-24 09:19:48 +01002017 for vnfcp_inst_param in get_iterable(
2018 vld_inst_param.get("vnfd-connection-point-ref")
2019 ):
tiernocddb07d2020-10-06 08:28:00 +00002020 if vnfcp_inst_param["member-vnf-index-ref"] != member_vnf_index:
2021 continue
2022 # look for iface
2023 for vdur_index, vdur in enumerate(vnfr["vdur"]):
2024 for iface_index, iface in enumerate(vdur["interfaces"]):
garciadeblas4568a372021-03-24 09:19:48 +01002025 if (
2026 iface.get("external-connection-point-ref")
2027 == vnfcp_inst_param["vnfd-connection-point-ref"]
2028 ):
2029 vnfr_update_text = "vdur.{}.interfaces.{}".format(
2030 vdur_index, iface_index
2031 )
tiernocddb07d2020-10-06 08:28:00 +00002032 if vnfcp_inst_param.get("ip-address"):
garciadeblas4568a372021-03-24 09:19:48 +01002033 vnfr_update[
2034 vnfr_update_text + ".ip-address"
2035 ] = increment_ip_mac(
2036 vnfcp_inst_param.get("ip-address"),
2037 vdur.get("count-index", 0),
2038 )
tierno1bd9d952020-11-13 15:56:51 +00002039 vnfr_update[vnfr_update_text + ".fixed-ip"] = True
tiernocddb07d2020-10-06 08:28:00 +00002040 if vnfcp_inst_param.get("mac-address"):
garciadeblas4568a372021-03-24 09:19:48 +01002041 vnfr_update[
2042 vnfr_update_text + ".mac-address"
2043 ] = increment_ip_mac(
2044 vnfcp_inst_param.get("mac-address"),
2045 vdur.get("count-index", 0),
2046 )
tierno1bd9d952020-11-13 15:56:51 +00002047 vnfr_update[vnfr_update_text + ".fixed-mac"] = True
tiernocddb07d2020-10-06 08:28:00 +00002048 break
2049
tiernocc103432018-10-19 14:10:35 +02002050 vnfr_update["vim-account-id"] = vim_account
2051 vnfr_update_rollback["vim-account-id"] = vnfr.get("vim-account-id")
2052
David Garciaecb41322021-03-31 19:10:46 +02002053 if vca_id:
2054 vnfr_update["vca-id"] = vca_id
2055 vnfr_update_rollback["vca-id"] = vnfr.get("vca-id")
2056
tiernocc103432018-10-19 14:10:35 +02002057 # get pdu
garciadeblas4568a372021-03-24 09:19:48 +01002058 ifaces_forcing_vim_network = self._look_for_pdu(
2059 session, rollback, vnfr, vim_account, vnfr_update, vnfr_update_rollback
2060 )
tiernocc103432018-10-19 14:10:35 +02002061
tierno9cb7d672019-10-30 12:13:48 +00002062 # get kdus
garciadeblas4568a372021-03-24 09:19:48 +01002063 ifaces_forcing_vim_network += self._look_for_k8scluster(
2064 session, rollback, vnfr, vim_account, vnfr_update, vnfr_update_rollback
2065 )
tierno9cb7d672019-10-30 12:13:48 +00002066 # update database vnfr
tierno36ec8602018-11-02 17:27:11 +01002067 self.db.set_one("vnfrs", {"_id": vnfr["_id"]}, vnfr_update)
garciadeblas4568a372021-03-24 09:19:48 +01002068 rollback.append(
2069 {
2070 "topic": "vnfrs",
2071 "_id": vnfr["_id"],
2072 "operation": "set",
2073 "content": vnfr_update_rollback,
2074 }
2075 )
tierno36ec8602018-11-02 17:27:11 +01002076
2077 # Update indada in case pdu forces to use a concrete vim-network-name
2078 # TODO check if user has already insert a vim-network-name and raises an error
2079 if not ifaces_forcing_vim_network:
2080 continue
2081 for iface_info in ifaces_forcing_vim_network:
2082 if iface_info.get("ns-vld-id"):
2083 if "vld" not in indata:
2084 indata["vld"] = []
garciadeblas4568a372021-03-24 09:19:48 +01002085 indata["vld"].append(
2086 {
2087 key: iface_info[key]
2088 for key in ("name", "vim-network-name", "vim-network-id")
2089 if iface_info.get(key)
2090 }
2091 )
tierno36ec8602018-11-02 17:27:11 +01002092
2093 elif iface_info.get("vnf-vld-id"):
2094 if "vnf" not in indata:
2095 indata["vnf"] = []
garciadeblas4568a372021-03-24 09:19:48 +01002096 indata["vnf"].append(
2097 {
2098 "member-vnf-index": member_vnf_index,
2099 "internal-vld": [
2100 {
2101 key: iface_info[key]
2102 for key in (
2103 "name",
2104 "vim-network-name",
2105 "vim-network-id",
2106 )
2107 if iface_info.get(key)
2108 }
2109 ],
2110 }
2111 )
tierno36ec8602018-11-02 17:27:11 +01002112
2113 @staticmethod
2114 def _create_nslcmop(nsr_id, operation, params):
2115 """
2116 Creates a ns-lcm-opp content to be stored at database.
2117 :param nsr_id: internal id of the instance
aticig544a2ae2022-04-05 09:00:17 +03002118 :param operation: instantiate, terminate, scale, action, update ...
tierno36ec8602018-11-02 17:27:11 +01002119 :param params: user parameters for the operation
2120 :return: dictionary following SOL005 format
2121 """
tiernob24258a2018-10-04 18:39:49 +02002122 now = time()
2123 _id = str(uuid4())
2124 nslcmop = {
2125 "id": _id,
2126 "_id": _id,
2127 "operationState": "PROCESSING", # COMPLETED,PARTIALLY_COMPLETED,FAILED_TEMP,FAILED,ROLLING_BACK,ROLLED_BACK
tiernoecf94bd2020-01-09 12:40:45 +00002128 "queuePosition": None,
2129 "stage": None,
2130 "errorMessage": None,
2131 "detailedStatus": None,
tiernob24258a2018-10-04 18:39:49 +02002132 "statusEnteredTime": now,
tierno36ec8602018-11-02 17:27:11 +01002133 "nsInstanceId": nsr_id,
tiernob24258a2018-10-04 18:39:49 +02002134 "lcmOperationType": operation,
2135 "startTime": now,
2136 "isAutomaticInvocation": False,
2137 "operationParams": params,
2138 "isCancelPending": False,
2139 "links": {
2140 "self": "/osm/nslcm/v1/ns_lcm_op_occs/" + _id,
tierno36ec8602018-11-02 17:27:11 +01002141 "nsInstance": "/osm/nslcm/v1/ns_instances/" + nsr_id,
garciadeblas4568a372021-03-24 09:19:48 +01002142 },
tiernob24258a2018-10-04 18:39:49 +02002143 }
2144 return nslcmop
2145
magnussonlf318b302020-01-20 18:38:18 +01002146 def _get_enabled_vims(self, session):
2147 """
2148 Retrieve and return VIM accounts that are accessible by current user and has state ENABLE
2149 :param session: current session with user information
2150 """
2151 db_filter = self._get_project_filter(session)
2152 db_filter["_admin.operationalState"] = "ENABLED"
2153 vims = self.db.get_list("vim_accounts", db_filter)
2154 vimAccounts = []
2155 for vim in vims:
garciadeblas4568a372021-03-24 09:19:48 +01002156 vimAccounts.append(vim["_id"])
magnussonlf318b302020-01-20 18:38:18 +01002157 return vimAccounts
2158
garciadeblas4568a372021-03-24 09:19:48 +01002159 def new(
2160 self,
2161 rollback,
2162 session,
2163 indata=None,
2164 kwargs=None,
2165 headers=None,
2166 slice_object=False,
2167 ):
tiernob24258a2018-10-04 18:39:49 +02002168 """
2169 Performs a new operation over a ns
2170 :param rollback: list to append created items at database in case a rollback must to be done
tierno65ca36d2019-02-12 19:27:52 +01002171 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
tiernob24258a2018-10-04 18:39:49 +02002172 :param indata: descriptor with the parameters of the operation. It must contains among others
2173 nsInstanceId: _id of the nsr to perform the operation
aticig544a2ae2022-04-05 09:00:17 +03002174 operation: it can be: instantiate, terminate, action, update TODO: heal
tiernob24258a2018-10-04 18:39:49 +02002175 :param kwargs: used to override the indata descriptor
2176 :param headers: http request headers
tiernob24258a2018-10-04 18:39:49 +02002177 :return: id of the nslcmops
2178 """
garciadeblas4568a372021-03-24 09:19:48 +01002179
Felipe Vicens90fbc9c2019-06-06 01:03:00 +02002180 def check_if_nsr_is_not_slice_member(session, nsr_id):
2181 nsis = None
2182 db_filter = self._get_project_filter(session)
2183 db_filter["_admin.nsrs-detailed-list.ANYINDEX.nsrId"] = nsr_id
garciadeblas4568a372021-03-24 09:19:48 +01002184 nsis = self.db.get_one(
2185 "nsis", db_filter, fail_on_empty=False, fail_on_more=False
2186 )
Felipe Vicens90fbc9c2019-06-06 01:03:00 +02002187 if nsis:
garciadeblas4568a372021-03-24 09:19:48 +01002188 raise EngineException(
2189 "The NS instance {} cannot be terminated because is used by the slice {}".format(
2190 nsr_id, nsis["_id"]
2191 ),
2192 http_code=HTTPStatus.CONFLICT,
2193 )
Felipe Vicens90fbc9c2019-06-06 01:03:00 +02002194
tiernob24258a2018-10-04 18:39:49 +02002195 try:
2196 # Override descriptor with query string kwargs
tierno1c38f2f2020-03-24 11:51:39 +00002197 self._update_input_with_kwargs(indata, kwargs, yaml_format=True)
tiernob24258a2018-10-04 18:39:49 +02002198 operation = indata["lcmOperationType"]
2199 nsInstanceId = indata["nsInstanceId"]
2200
2201 validate_input(indata, self.operation_schema[operation])
2202 # get ns from nsr_id
tierno65ca36d2019-02-12 19:27:52 +01002203 _filter = BaseTopic._get_project_filter(session)
tiernob24258a2018-10-04 18:39:49 +02002204 _filter["_id"] = nsInstanceId
2205 nsr = self.db.get_one("nsrs", _filter)
2206
2207 # initial checking
Felipe Vicens90fbc9c2019-06-06 01:03:00 +02002208 if operation == "terminate" and slice_object is False:
2209 check_if_nsr_is_not_slice_member(session, nsr["_id"])
garciadeblas4568a372021-03-24 09:19:48 +01002210 if (
2211 not nsr["_admin"].get("nsState")
2212 or nsr["_admin"]["nsState"] == "NOT_INSTANTIATED"
2213 ):
tiernob24258a2018-10-04 18:39:49 +02002214 if operation == "terminate" and indata.get("autoremove"):
2215 # NSR must be deleted
garciadeblas4568a372021-03-24 09:19:48 +01002216 return (
2217 None,
2218 None,
2219 ) # a none in this case is used to indicate not instantiated. It can be removed
tiernob24258a2018-10-04 18:39:49 +02002220 if operation != "instantiate":
garciadeblas4568a372021-03-24 09:19:48 +01002221 raise EngineException(
2222 "ns_instance '{}' cannot be '{}' because it is not instantiated".format(
2223 nsInstanceId, operation
2224 ),
2225 HTTPStatus.CONFLICT,
2226 )
tiernob24258a2018-10-04 18:39:49 +02002227 else:
tierno65ca36d2019-02-12 19:27:52 +01002228 if operation == "instantiate" and not session["force"]:
garciadeblas4568a372021-03-24 09:19:48 +01002229 raise EngineException(
2230 "ns_instance '{}' cannot be '{}' because it is already instantiated".format(
2231 nsInstanceId, operation
2232 ),
2233 HTTPStatus.CONFLICT,
2234 )
tiernob24258a2018-10-04 18:39:49 +02002235 self._check_ns_operation(session, nsr, operation, indata)
Guillermo Calvino7fcbd4f2022-01-26 17:37:56 +01002236 if (indata.get("primitive_params")):
2237 indata["primitive_params"] = json.dumps(indata["primitive_params"])
2238 elif (indata.get("additionalParamsForVnf")):
2239 indata["additionalParamsForVnf"] = json.dumps(indata["additionalParamsForVnf"])
tierno36ec8602018-11-02 17:27:11 +01002240
tiernocc103432018-10-19 14:10:35 +02002241 if operation == "instantiate":
Gulsum Aticie395aa42021-11-10 20:59:06 +03002242 self._update_vnfrs_from_nsd(nsr)
tiernocc103432018-10-19 14:10:35 +02002243 self._update_vnfrs(session, rollback, nsr, indata)
elumalai6c5ea6b2022-04-25 22:27:59 +05302244 if (operation == "update") and (indata["updateType"] == "CHANGE_VNFPKG"):
2245 nsr_update = {}
2246 vnfd_id = indata["changeVnfPackageData"]["vnfdId"]
2247 vnfd = self.db.get_one("vnfds", {"_id": vnfd_id})
2248 nsd = self.db.get_one("nsds", {"_id": nsr["nsd-id"]})
2249 ns_request = nsr["instantiate_params"]
2250 vnfr = self.db.get_one("vnfrs", {"_id": indata["changeVnfPackageData"]["vnfInstanceId"]})
elumalai8bf978e2022-05-26 15:32:06 +05302251 latest_vnfd_revision = vnfd["_admin"].get("revision", 1)
2252 vnfr_vnfd_revision = vnfr.get("revision", 1)
2253 if latest_vnfd_revision != vnfr_vnfd_revision:
2254 old_vnfd_id = vnfd_id + ":" + str(vnfr_vnfd_revision)
2255 old_db_vnfd = self.db.get_one("vnfds_revisions", {"_id": old_vnfd_id})
2256 old_sw_version = old_db_vnfd.get("software-version", "1.0")
2257 new_sw_version = vnfd.get("software-version", "1.0")
2258 if new_sw_version != old_sw_version:
2259 vnf_index = vnfr["member-vnf-index-ref"]
2260 self.logger.info("nsr {}".format(nsr))
2261 for vdu in vnfd["vdu"]:
2262 self.nsrtopic._add_flavor_to_nsr(vdu, vnfd, nsr)
2263 sw_image_id = vdu.get("sw-image-desc")
2264 if sw_image_id:
2265 image_data = self.nsrtopic._get_image_data_from_vnfd(vnfd, sw_image_id)
2266 self.nsrtopic._add_image_to_nsr(nsr, image_data)
2267 for alt_image in vdu.get("alternative-sw-image-desc", ()):
2268 image_data = self.nsrtopic._get_image_data_from_vnfd(vnfd, alt_image)
2269 self.nsrtopic._add_image_to_nsr(nsr, image_data)
2270 nsr_update["image"] = nsr["image"]
2271 nsr_update["flavor"] = nsr["flavor"]
2272 self.db.set_one("nsrs", {"_id": nsr["_id"]}, nsr_update)
2273 ns_k8s_namespace = self.nsrtopic._get_ns_k8s_namespace(nsd, ns_request, session)
2274 vnfr_descriptor = self.nsrtopic._create_vnfr_descriptor_from_vnfd(
2275 nsd,
2276 vnfd,
2277 vnfd_id,
2278 vnf_index,
2279 nsr,
2280 ns_request,
2281 ns_k8s_namespace,
2282 )
2283 indata["newVdur"] = vnfr_descriptor["vdur"]
tierno36ec8602018-11-02 17:27:11 +01002284 nslcmop_desc = self._create_nslcmop(nsInstanceId, operation, indata)
tierno1bfe4e22019-09-02 16:03:25 +00002285 _id = nslcmop_desc["_id"]
garciadeblas4568a372021-03-24 09:19:48 +01002286 self.format_on_new(
2287 nslcmop_desc, session["project_id"], make_public=session["public"]
2288 )
magnussonlf318b302020-01-20 18:38:18 +01002289 if indata.get("placement-engine"):
2290 # Save valid vim accounts in lcm operation descriptor
garciadeblas4568a372021-03-24 09:19:48 +01002291 nslcmop_desc["operationParams"][
2292 "validVimAccounts"
2293 ] = self._get_enabled_vims(session)
tierno1bfe4e22019-09-02 16:03:25 +00002294 self.db.create("nslcmops", nslcmop_desc)
tiernob24258a2018-10-04 18:39:49 +02002295 rollback.append({"topic": "nslcmops", "_id": _id})
Felipe Vicens07f31722018-10-29 15:16:44 +01002296 if not slice_object:
2297 self.msg.write("ns", operation, nslcmop_desc)
tiernobdebce92019-07-01 15:36:49 +00002298 return _id, None
2299 except ValidationError as e: # TODO remove try Except, it is captured at nbi.py
tiernob24258a2018-10-04 18:39:49 +02002300 raise EngineException(e, HTTPStatus.UNPROCESSABLE_ENTITY)
2301 # except DbException as e:
2302 # raise EngineException("Cannot get ns_instance '{}': {}".format(e), HTTPStatus.NOT_FOUND)
2303
tiernobee3bad2019-12-05 12:26:01 +00002304 def delete(self, session, _id, dry_run=False, not_send_msg=None):
garciadeblas4568a372021-03-24 09:19:48 +01002305 raise EngineException(
2306 "Method delete called directly", HTTPStatus.INTERNAL_SERVER_ERROR
2307 )
tiernob24258a2018-10-04 18:39:49 +02002308
tierno65ca36d2019-02-12 19:27:52 +01002309 def edit(self, session, _id, indata=None, kwargs=None, content=None):
garciadeblas4568a372021-03-24 09:19:48 +01002310 raise EngineException(
2311 "Method edit called directly", HTTPStatus.INTERNAL_SERVER_ERROR
2312 )
Felipe Vicensb57758d2018-10-16 16:00:20 +02002313
2314
2315class NsiTopic(BaseTopic):
2316 topic = "nsis"
2317 topic_msg = "nsi"
tierno6b02b052020-06-02 10:07:41 +00002318 quota_name = "slice_instances"
Felipe Vicensb57758d2018-10-16 16:00:20 +02002319
delacruzramo32bab472019-09-13 12:24:22 +02002320 def __init__(self, db, fs, msg, auth):
2321 BaseTopic.__init__(self, db, fs, msg, auth)
2322 self.nsrTopic = NsrTopic(db, fs, msg, auth)
Felipe Vicensb57758d2018-10-16 16:00:20 +02002323
Felipe Vicensc37b3842019-01-12 12:24:42 +01002324 @staticmethod
2325 def _format_ns_request(ns_request):
2326 formated_request = copy(ns_request)
2327 # TODO: Add request params
2328 return formated_request
2329
2330 @staticmethod
tiernofd160572019-01-21 10:41:37 +00002331 def _format_addional_params(slice_request):
Felipe Vicensc37b3842019-01-12 12:24:42 +01002332 """
2333 Get and format user additional params for NS or VNF
tiernofd160572019-01-21 10:41:37 +00002334 :param slice_request: User instantiation additional parameters
2335 :return: a formatted copy of additional params or None if not supplied
Felipe Vicensc37b3842019-01-12 12:24:42 +01002336 """
tiernofd160572019-01-21 10:41:37 +00002337 additional_params = copy(slice_request.get("additionalParamsForNsi"))
2338 if additional_params:
2339 for k, v in additional_params.items():
2340 if not isinstance(k, str):
garciadeblas4568a372021-03-24 09:19:48 +01002341 raise EngineException(
2342 "Invalid param at additionalParamsForNsi:{}. Only string keys are allowed".format(
2343 k
2344 )
2345 )
tiernofd160572019-01-21 10:41:37 +00002346 if "." in k or "$" in k:
garciadeblas4568a372021-03-24 09:19:48 +01002347 raise EngineException(
2348 "Invalid param at additionalParamsForNsi:{}. Keys must not contain dots or $".format(
2349 k
2350 )
2351 )
tiernofd160572019-01-21 10:41:37 +00002352 if isinstance(v, (dict, tuple, list)):
2353 additional_params[k] = "!!yaml " + safe_dump(v)
Felipe Vicensc37b3842019-01-12 12:24:42 +01002354 return additional_params
2355
Felipe Vicensb57758d2018-10-16 16:00:20 +02002356 def _check_descriptor_dependencies(self, session, descriptor):
2357 """
2358 Check that the dependent descriptors exist on a new descriptor or edition
tierno65ca36d2019-02-12 19:27:52 +01002359 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
Felipe Vicensb57758d2018-10-16 16:00:20 +02002360 :param descriptor: descriptor to be inserted or edit
2361 :return: None or raises exception
2362 """
Felipe Vicens07f31722018-10-29 15:16:44 +01002363 if not descriptor.get("nst-ref"):
Felipe Vicensb57758d2018-10-16 16:00:20 +02002364 return
Felipe Vicens07f31722018-10-29 15:16:44 +01002365 nstd_id = descriptor["nst-ref"]
Felipe Vicensb57758d2018-10-16 16:00:20 +02002366 if not self.get_item_list(session, "nsts", {"id": nstd_id}):
garciadeblas4568a372021-03-24 09:19:48 +01002367 raise EngineException(
2368 "Descriptor error at nst-ref='{}' references a non exist nstd".format(
2369 nstd_id
2370 ),
2371 http_code=HTTPStatus.CONFLICT,
2372 )
Felipe Vicensb57758d2018-10-16 16:00:20 +02002373
tiernob4844ab2019-05-23 08:42:12 +00002374 def check_conflict_on_del(self, session, _id, db_content):
2375 """
2376 Check that NSI is not instantiated
2377 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
2378 :param _id: nsi internal id
2379 :param db_content: The database content of the _id
2380 :return: None or raises EngineException with the conflict
2381 """
tierno65ca36d2019-02-12 19:27:52 +01002382 if session["force"]:
Felipe Vicensb57758d2018-10-16 16:00:20 +02002383 return
tiernob4844ab2019-05-23 08:42:12 +00002384 nsi = db_content
Felipe Vicensb57758d2018-10-16 16:00:20 +02002385 if nsi["_admin"].get("nsiState") == "INSTANTIATED":
garciadeblas4568a372021-03-24 09:19:48 +01002386 raise EngineException(
2387 "nsi '{}' cannot be deleted because it is in 'INSTANTIATED' state. "
2388 "Launch 'terminate' operation first; or force deletion".format(_id),
2389 http_code=HTTPStatus.CONFLICT,
2390 )
Felipe Vicensb57758d2018-10-16 16:00:20 +02002391
tiernobee3bad2019-12-05 12:26:01 +00002392 def delete_extra(self, session, _id, db_content, not_send_msg=None):
Felipe Vicensb57758d2018-10-16 16:00:20 +02002393 """
tiernob4844ab2019-05-23 08:42:12 +00002394 Deletes associated nsilcmops from database. Deletes associated filesystem.
2395 Set usageState of nst
tierno65ca36d2019-02-12 19:27:52 +01002396 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
Felipe Vicensb57758d2018-10-16 16:00:20 +02002397 :param _id: server internal id
tiernob4844ab2019-05-23 08:42:12 +00002398 :param db_content: The database content of the descriptor
tiernobee3bad2019-12-05 12:26:01 +00002399 :param not_send_msg: To not send message (False) or store content (list) instead
tiernob4844ab2019-05-23 08:42:12 +00002400 :return: None if ok or raises EngineException with the problem
Felipe Vicensb57758d2018-10-16 16:00:20 +02002401 """
Felipe Vicens07f31722018-10-29 15:16:44 +01002402
Felipe Vicens09e65422019-01-22 15:06:46 +01002403 # Deleting the nsrs belonging to nsir
tiernob4844ab2019-05-23 08:42:12 +00002404 nsir = db_content
Felipe Vicens09e65422019-01-22 15:06:46 +01002405 for nsrs_detailed_item in nsir["_admin"]["nsrs-detailed-list"]:
2406 nsr_id = nsrs_detailed_item["nsrId"]
2407 if nsrs_detailed_item.get("shared"):
garciadeblas4568a372021-03-24 09:19:48 +01002408 _filter = {
2409 "_admin.nsrs-detailed-list.ANYINDEX.shared": True,
2410 "_admin.nsrs-detailed-list.ANYINDEX.nsrId": nsr_id,
2411 "_id.ne": nsir["_id"],
2412 }
2413 nsi = self.db.get_one(
2414 "nsis", _filter, fail_on_empty=False, fail_on_more=False
2415 )
Felipe Vicens09e65422019-01-22 15:06:46 +01002416 if nsi: # last one using nsr
2417 continue
2418 try:
garciadeblas4568a372021-03-24 09:19:48 +01002419 self.nsrTopic.delete(
2420 session, nsr_id, dry_run=False, not_send_msg=not_send_msg
2421 )
Felipe Vicens09e65422019-01-22 15:06:46 +01002422 except (DbException, EngineException) as e:
2423 if e.http_code == HTTPStatus.NOT_FOUND:
2424 pass
2425 else:
2426 raise
Felipe Vicens07f31722018-10-29 15:16:44 +01002427
tiernob4844ab2019-05-23 08:42:12 +00002428 # delete related nsilcmops database entries
2429 self.db.del_list("nsilcmops", {"netsliceInstanceId": _id})
Felipe Vicens07f31722018-10-29 15:16:44 +01002430
tiernob4844ab2019-05-23 08:42:12 +00002431 # Check and set used NST usage state
Felipe Vicens09e65422019-01-22 15:06:46 +01002432 nsir_admin = nsir.get("_admin")
tiernob4844ab2019-05-23 08:42:12 +00002433 if nsir_admin and nsir_admin.get("nst-id"):
2434 # check if used by another NSI
garciadeblas4568a372021-03-24 09:19:48 +01002435 nsis_list = self.db.get_one(
2436 "nsis",
2437 {"nst-id": nsir_admin["nst-id"]},
2438 fail_on_empty=False,
2439 fail_on_more=False,
2440 )
tiernob4844ab2019-05-23 08:42:12 +00002441 if not nsis_list:
garciadeblas4568a372021-03-24 09:19:48 +01002442 self.db.set_one(
2443 "nsts",
2444 {"_id": nsir_admin["nst-id"]},
2445 {"_admin.usageState": "NOT_IN_USE"},
2446 )
tiernob4844ab2019-05-23 08:42:12 +00002447
tierno65ca36d2019-02-12 19:27:52 +01002448 def new(self, rollback, session, indata=None, kwargs=None, headers=None):
Felipe Vicensb57758d2018-10-16 16:00:20 +02002449 """
Felipe Vicens07f31722018-10-29 15:16:44 +01002450 Creates a new netslice instance record into database. It also creates needed nsrs and vnfrs
Felipe Vicensb57758d2018-10-16 16:00:20 +02002451 :param rollback: list to append the created items at database in case a rollback must be done
tierno65ca36d2019-02-12 19:27:52 +01002452 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
Felipe Vicensb57758d2018-10-16 16:00:20 +02002453 :param indata: params to be used for the nsir
2454 :param kwargs: used to override the indata descriptor
2455 :param headers: http request headers
Felipe Vicensb57758d2018-10-16 16:00:20 +02002456 :return: the _id of nsi descriptor created at database
2457 """
2458
2459 try:
delacruzramo32bab472019-09-13 12:24:22 +02002460 step = "checking quotas"
2461 self.check_quota(session)
2462
tierno99d4b172019-07-02 09:28:40 +00002463 step = ""
Felipe Vicensb57758d2018-10-16 16:00:20 +02002464 slice_request = self._remove_envelop(indata)
2465 # Override descriptor with query string kwargs
2466 self._update_input_with_kwargs(slice_request, kwargs)
bravofb995ea22021-02-10 10:57:52 -03002467 slice_request = self._validate_input_new(slice_request, session["force"])
Felipe Vicensb57758d2018-10-16 16:00:20 +02002468
Felipe Vicensb57758d2018-10-16 16:00:20 +02002469 # look for nstd
garciadeblas4568a372021-03-24 09:19:48 +01002470 step = "getting nstd id='{}' from database".format(
2471 slice_request.get("nstId")
2472 )
tiernob4844ab2019-05-23 08:42:12 +00002473 _filter = self._get_project_filter(session)
2474 _filter["_id"] = slice_request["nstId"]
Felipe Vicensb57758d2018-10-16 16:00:20 +02002475 nstd = self.db.get_one("nsts", _filter)
tierno40f742b2020-06-23 15:25:26 +00002476 # check NST is not disabled
2477 step = "checking NST operationalState"
2478 if nstd["_admin"]["operationalState"] == "DISABLED":
garciadeblas4568a372021-03-24 09:19:48 +01002479 raise EngineException(
2480 "nst with id '{}' is DISABLED, and thus cannot be used to create a netslice "
2481 "instance".format(slice_request["nstId"]),
2482 http_code=HTTPStatus.CONFLICT,
2483 )
tiernob4844ab2019-05-23 08:42:12 +00002484 del _filter["_id"]
2485
Frank Brydenb5a2ead2020-07-28 12:50:23 +00002486 # check NSD is not disabled
2487 step = "checking operationalState"
2488 if nstd["_admin"]["operationalState"] == "DISABLED":
garciadeblas4568a372021-03-24 09:19:48 +01002489 raise EngineException(
2490 "nst with id '{}' is DISABLED, and thus cannot be used to create "
2491 "a network slice".format(slice_request["nstId"]),
2492 http_code=HTTPStatus.CONFLICT,
2493 )
Frank Brydenb5a2ead2020-07-28 12:50:23 +00002494
Felipe Vicens07f31722018-10-29 15:16:44 +01002495 nstd.pop("_admin", None)
Felipe Vicens09e65422019-01-22 15:06:46 +01002496 nstd_id = nstd.pop("_id", None)
Felipe Vicensb57758d2018-10-16 16:00:20 +02002497 nsi_id = str(uuid4())
Felipe Vicensb57758d2018-10-16 16:00:20 +02002498 step = "filling nsi_descriptor with input data"
Felipe Vicens07f31722018-10-29 15:16:44 +01002499
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01002500 # Creating the NSIR
Felipe Vicensb57758d2018-10-16 16:00:20 +02002501 nsi_descriptor = {
2502 "id": nsi_id,
garciadeblasc54d4202018-11-29 23:41:37 +01002503 "name": slice_request["nsiName"],
2504 "description": slice_request.get("nsiDescription", ""),
2505 "datacenter": slice_request["vimAccountId"],
Felipe Vicensb57758d2018-10-16 16:00:20 +02002506 "nst-ref": nstd["id"],
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01002507 "instantiation_parameters": slice_request,
Felipe Vicensb57758d2018-10-16 16:00:20 +02002508 "network-slice-template": nstd,
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01002509 "nsr-ref-list": [],
2510 "vlr-list": [],
Felipe Vicensb57758d2018-10-16 16:00:20 +02002511 "_id": nsi_id,
garciadeblas4568a372021-03-24 09:19:48 +01002512 "additionalParamsForNsi": self._format_addional_params(slice_request),
Felipe Vicensb57758d2018-10-16 16:00:20 +02002513 }
Felipe Vicensb57758d2018-10-16 16:00:20 +02002514
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01002515 step = "creating nsi at database"
garciadeblas4568a372021-03-24 09:19:48 +01002516 self.format_on_new(
2517 nsi_descriptor, session["project_id"], make_public=session["public"]
2518 )
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01002519 nsi_descriptor["_admin"]["nsiState"] = "NOT_INSTANTIATED"
2520 nsi_descriptor["_admin"]["netslice-subnet"] = None
Felipe Vicens09e65422019-01-22 15:06:46 +01002521 nsi_descriptor["_admin"]["deployed"] = {}
2522 nsi_descriptor["_admin"]["deployed"]["RO"] = []
2523 nsi_descriptor["_admin"]["nst-id"] = nstd_id
2524
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01002525 # Creating netslice-vld for the RO.
2526 step = "creating netslice-vld at database"
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01002527
2528 # Building the vlds list to be deployed
2529 # From netslice descriptors, creating the initial list
Felipe Vicens09e65422019-01-22 15:06:46 +01002530 nsi_vlds = []
2531
2532 for netslice_vlds in get_iterable(nstd.get("netslice-vld")):
2533 # Getting template Instantiation parameters from NST
2534 nsi_vld = deepcopy(netslice_vlds)
2535 nsi_vld["shared-nsrs-list"] = []
2536 nsi_vld["vimAccountId"] = slice_request["vimAccountId"]
2537 nsi_vlds.append(nsi_vld)
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01002538
2539 nsi_descriptor["_admin"]["netslice-vld"] = nsi_vlds
tierno3ffc7a42019-12-03 09:39:40 +00002540 # Creating netslice-subnet_record.
Felipe Vicensb57758d2018-10-16 16:00:20 +02002541 needed_nsds = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01002542 services = []
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01002543
Felipe Vicens09e65422019-01-22 15:06:46 +01002544 # Updating the nstd with the nsd["_id"] associated to the nss -> services list
Felipe Vicensb57758d2018-10-16 16:00:20 +02002545 for member_ns in nstd["netslice-subnet"]:
2546 nsd_id = member_ns["nsd-ref"]
2547 step = "getting nstd id='{}' constituent-nsd='{}' from database".format(
garciadeblas4568a372021-03-24 09:19:48 +01002548 member_ns["nsd-ref"], member_ns["id"]
2549 )
Felipe Vicensb57758d2018-10-16 16:00:20 +02002550 if nsd_id not in needed_nsds:
2551 # Obtain nsd
tiernob4844ab2019-05-23 08:42:12 +00002552 _filter["id"] = nsd_id
garciadeblas4568a372021-03-24 09:19:48 +01002553 nsd = self.db.get_one(
2554 "nsds", _filter, fail_on_empty=True, fail_on_more=True
2555 )
tiernob4844ab2019-05-23 08:42:12 +00002556 del _filter["id"]
Felipe Vicensb57758d2018-10-16 16:00:20 +02002557 nsd.pop("_admin")
2558 needed_nsds[nsd_id] = nsd
2559 else:
2560 nsd = needed_nsds[nsd_id]
Felipe Vicens09e65422019-01-22 15:06:46 +01002561 member_ns["_id"] = needed_nsds[nsd_id].get("_id")
2562 services.append(member_ns)
Felipe Vicens07f31722018-10-29 15:16:44 +01002563
Felipe Vicensb57758d2018-10-16 16:00:20 +02002564 step = "filling nsir nsd-id='{}' constituent-nsd='{}' from database".format(
garciadeblas4568a372021-03-24 09:19:48 +01002565 member_ns["nsd-ref"], member_ns["id"]
2566 )
Felipe Vicensb57758d2018-10-16 16:00:20 +02002567
Felipe Vicens07f31722018-10-29 15:16:44 +01002568 # creates Network Services records (NSRs)
2569 step = "creating nsrs at database using NsrTopic.new()"
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01002570 ns_params = slice_request.get("netslice-subnet")
Felipe Vicens07f31722018-10-29 15:16:44 +01002571 nsrs_list = []
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01002572 nsi_netslice_subnet = []
Felipe Vicens07f31722018-10-29 15:16:44 +01002573 for service in services:
Felipe Vicens09e65422019-01-22 15:06:46 +01002574 # Check if the netslice-subnet is shared and if it is share if the nss exists
2575 _id_nsr = None
Felipe Vicens07f31722018-10-29 15:16:44 +01002576 indata_ns = {}
Felipe Vicens09e65422019-01-22 15:06:46 +01002577 # Is the nss shared and instantiated?
tiernob4844ab2019-05-23 08:42:12 +00002578 _filter["_admin.nsrs-detailed-list.ANYINDEX.shared"] = True
garciadeblas4568a372021-03-24 09:19:48 +01002579 _filter["_admin.nsrs-detailed-list.ANYINDEX.nsd-id"] = service[
2580 "nsd-ref"
2581 ]
Felipe Vicens08ddb142019-08-09 15:52:40 +02002582 _filter["_admin.nsrs-detailed-list.ANYINDEX.nss-id"] = service["id"]
garciadeblas4568a372021-03-24 09:19:48 +01002583 nsi = self.db.get_one(
2584 "nsis", _filter, fail_on_empty=False, fail_on_more=False
2585 )
Felipe Vicens09e65422019-01-22 15:06:46 +01002586 if nsi and service.get("is-shared-nss"):
2587 nsrs_detailed_list = nsi["_admin"]["nsrs-detailed-list"]
2588 for nsrs_detailed_item in nsrs_detailed_list:
2589 if nsrs_detailed_item["nsd-id"] == service["nsd-ref"]:
Felipe Vicens08ddb142019-08-09 15:52:40 +02002590 if nsrs_detailed_item["nss-id"] == service["id"]:
2591 _id_nsr = nsrs_detailed_item["nsrId"]
2592 break
Felipe Vicens09e65422019-01-22 15:06:46 +01002593 for netslice_subnet in nsi["_admin"]["netslice-subnet"]:
2594 if netslice_subnet["nss-id"] == service["id"]:
2595 indata_ns = netslice_subnet
2596 break
2597 else:
2598 indata_ns = {}
2599 if service.get("instantiation-parameters"):
2600 indata_ns = deepcopy(service["instantiation-parameters"])
2601 # del service["instantiation-parameters"]
garciadeblas4568a372021-03-24 09:19:48 +01002602
Felipe Vicens09e65422019-01-22 15:06:46 +01002603 indata_ns["nsdId"] = service["_id"]
garciadeblas4568a372021-03-24 09:19:48 +01002604 indata_ns["nsName"] = (
2605 slice_request.get("nsiName") + "." + service["id"]
2606 )
Felipe Vicens09e65422019-01-22 15:06:46 +01002607 indata_ns["vimAccountId"] = slice_request.get("vimAccountId")
2608 indata_ns["nsDescription"] = service["description"]
tierno99d4b172019-07-02 09:28:40 +00002609 if slice_request.get("ssh_keys"):
2610 indata_ns["ssh_keys"] = slice_request.get("ssh_keys")
Felipe Vicensc37b3842019-01-12 12:24:42 +01002611
Felipe Vicens09e65422019-01-22 15:06:46 +01002612 if ns_params:
2613 for ns_param in ns_params:
2614 if ns_param.get("id") == service["id"]:
2615 copy_ns_param = deepcopy(ns_param)
2616 del copy_ns_param["id"]
2617 indata_ns.update(copy_ns_param)
garciadeblas4568a372021-03-24 09:19:48 +01002618 break
Felipe Vicens09e65422019-01-22 15:06:46 +01002619
2620 # Creates Nsr objects
garciadeblas4568a372021-03-24 09:19:48 +01002621 _id_nsr, _ = self.nsrTopic.new(
2622 rollback, session, indata_ns, kwargs, headers
2623 )
2624 nsrs_item = {
2625 "nsrId": _id_nsr,
2626 "shared": service.get("is-shared-nss"),
2627 "nsd-id": service["nsd-ref"],
2628 "nss-id": service["id"],
2629 "nslcmop_instantiate": None,
2630 }
Felipe Vicens09e65422019-01-22 15:06:46 +01002631 indata_ns["nss-id"] = service["id"]
Felipe Vicens07f31722018-10-29 15:16:44 +01002632 nsrs_list.append(nsrs_item)
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01002633 nsi_netslice_subnet.append(indata_ns)
2634 nsr_ref = {"nsr-ref": _id_nsr}
2635 nsi_descriptor["nsr-ref-list"].append(nsr_ref)
Felipe Vicens07f31722018-10-29 15:16:44 +01002636
2637 # Adding the nsrs list to the nsi
2638 nsi_descriptor["_admin"]["nsrs-detailed-list"] = nsrs_list
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01002639 nsi_descriptor["_admin"]["netslice-subnet"] = nsi_netslice_subnet
garciadeblas4568a372021-03-24 09:19:48 +01002640 self.db.set_one(
2641 "nsts", {"_id": slice_request["nstId"]}, {"_admin.usageState": "IN_USE"}
2642 )
Felipe Vicens09e65422019-01-22 15:06:46 +01002643
Felipe Vicens07f31722018-10-29 15:16:44 +01002644 # Creating the entry in the database
Felipe Vicensb57758d2018-10-16 16:00:20 +02002645 self.db.create("nsis", nsi_descriptor)
2646 rollback.append({"topic": "nsis", "_id": nsi_id})
tiernobdebce92019-07-01 15:36:49 +00002647 return nsi_id, None
garciadeblas4568a372021-03-24 09:19:48 +01002648 except Exception as e: # TODO remove try Except, it is captured at nbi.py
2649 self.logger.exception(
2650 "Exception {} at NsiTopic.new()".format(e), exc_info=True
2651 )
Felipe Vicensb57758d2018-10-16 16:00:20 +02002652 raise EngineException("Error {}: {}".format(step, e))
2653 except ValidationError as e:
2654 raise EngineException(e, HTTPStatus.UNPROCESSABLE_ENTITY)
2655
tierno65ca36d2019-02-12 19:27:52 +01002656 def edit(self, session, _id, indata=None, kwargs=None, content=None):
garciadeblas4568a372021-03-24 09:19:48 +01002657 raise EngineException(
2658 "Method edit called directly", HTTPStatus.INTERNAL_SERVER_ERROR
2659 )
Felipe Vicens07f31722018-10-29 15:16:44 +01002660
2661
2662class NsiLcmOpTopic(BaseTopic):
2663 topic = "nsilcmops"
2664 topic_msg = "nsi"
2665 operation_schema = { # mapping between operation and jsonschema to validate
2666 "instantiate": nsi_instantiate,
garciadeblas4568a372021-03-24 09:19:48 +01002667 "terminate": None,
Felipe Vicens07f31722018-10-29 15:16:44 +01002668 }
garciadeblas4568a372021-03-24 09:19:48 +01002669
delacruzramo32bab472019-09-13 12:24:22 +02002670 def __init__(self, db, fs, msg, auth):
2671 BaseTopic.__init__(self, db, fs, msg, auth)
2672 self.nsi_NsLcmOpTopic = NsLcmOpTopic(self.db, self.fs, self.msg, self.auth)
Felipe Vicens07f31722018-10-29 15:16:44 +01002673
2674 def _check_nsi_operation(self, session, nsir, operation, indata):
2675 """
2676 Check that user has enter right parameters for the operation
tierno65ca36d2019-02-12 19:27:52 +01002677 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
Felipe Vicens07f31722018-10-29 15:16:44 +01002678 :param operation: it can be: instantiate, terminate, action, TODO: update, heal
2679 :param indata: descriptor with the parameters of the operation
2680 :return: None
2681 """
2682 nsds = {}
2683 nstd = nsir["network-slice-template"]
2684
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01002685 def check_valid_netslice_subnet_id(nstId):
Felipe Vicens07f31722018-10-29 15:16:44 +01002686 # TODO change to vnfR (??)
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01002687 for netslice_subnet in nstd["netslice-subnet"]:
2688 if nstId == netslice_subnet["id"]:
2689 nsd_id = netslice_subnet["nsd-ref"]
Felipe Vicens07f31722018-10-29 15:16:44 +01002690 if nsd_id not in nsds:
Felipe Vicens5403f542020-05-22 16:37:39 +02002691 _filter = self._get_project_filter(session)
2692 _filter["id"] = nsd_id
2693 nsds[nsd_id] = self.db.get_one("nsds", _filter)
Felipe Vicens07f31722018-10-29 15:16:44 +01002694 return nsds[nsd_id]
2695 else:
garciadeblas4568a372021-03-24 09:19:48 +01002696 raise EngineException(
2697 "Invalid parameter nstId='{}' is not one of the "
2698 "nst:netslice-subnet".format(nstId)
2699 )
2700
Felipe Vicens07f31722018-10-29 15:16:44 +01002701 if operation == "instantiate":
2702 # check the existance of netslice-subnet items
garciadeblas4568a372021-03-24 09:19:48 +01002703 for in_nst in get_iterable(indata.get("netslice-subnet")):
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01002704 check_valid_netslice_subnet_id(in_nst["id"])
Felipe Vicens07f31722018-10-29 15:16:44 +01002705
2706 def _create_nsilcmop(self, session, netsliceInstanceId, operation, params):
2707 now = time()
2708 _id = str(uuid4())
2709 nsilcmop = {
2710 "id": _id,
2711 "_id": _id,
2712 "operationState": "PROCESSING", # COMPLETED,PARTIALLY_COMPLETED,FAILED_TEMP,FAILED,ROLLING_BACK,ROLLED_BACK
2713 "statusEnteredTime": now,
2714 "netsliceInstanceId": netsliceInstanceId,
2715 "lcmOperationType": operation,
2716 "startTime": now,
2717 "isAutomaticInvocation": False,
2718 "operationParams": params,
2719 "isCancelPending": False,
2720 "links": {
2721 "self": "/osm/nsilcm/v1/nsi_lcm_op_occs/" + _id,
garciadeblas4568a372021-03-24 09:19:48 +01002722 "netsliceInstanceId": "/osm/nsilcm/v1/netslice_instances/"
2723 + netsliceInstanceId,
2724 },
Felipe Vicens07f31722018-10-29 15:16:44 +01002725 }
2726 return nsilcmop
2727
Felipe Vicens09e65422019-01-22 15:06:46 +01002728 def add_shared_nsr_2vld(self, nsir, nsr_item):
2729 for nst_sb_item in nsir["network-slice-template"].get("netslice-subnet"):
2730 if nst_sb_item.get("is-shared-nss"):
2731 for admin_subnet_item in nsir["_admin"].get("netslice-subnet"):
2732 if admin_subnet_item["nss-id"] == nst_sb_item["id"]:
2733 for admin_vld_item in nsir["_admin"].get("netslice-vld"):
garciadeblas4568a372021-03-24 09:19:48 +01002734 for admin_vld_nss_cp_ref_item in admin_vld_item[
2735 "nss-connection-point-ref"
2736 ]:
2737 if (
2738 admin_subnet_item["nss-id"]
2739 == admin_vld_nss_cp_ref_item["nss-ref"]
2740 ):
2741 if (
2742 not nsr_item["nsrId"]
2743 in admin_vld_item["shared-nsrs-list"]
2744 ):
2745 admin_vld_item["shared-nsrs-list"].append(
2746 nsr_item["nsrId"]
2747 )
Felipe Vicens09e65422019-01-22 15:06:46 +01002748 break
2749 # self.db.set_one("nsis", {"_id": nsir["_id"]}, nsir)
garciadeblas4568a372021-03-24 09:19:48 +01002750 self.db.set_one(
2751 "nsis",
2752 {"_id": nsir["_id"]},
2753 {"_admin.netslice-vld": nsir["_admin"].get("netslice-vld")},
2754 )
Felipe Vicens09e65422019-01-22 15:06:46 +01002755
tierno65ca36d2019-02-12 19:27:52 +01002756 def new(self, rollback, session, indata=None, kwargs=None, headers=None):
Felipe Vicens07f31722018-10-29 15:16:44 +01002757 """
2758 Performs a new operation over a ns
2759 :param rollback: list to append created items at database in case a rollback must to be done
tierno65ca36d2019-02-12 19:27:52 +01002760 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
Felipe Vicens07f31722018-10-29 15:16:44 +01002761 :param indata: descriptor with the parameters of the operation. It must contains among others
Felipe Vicens126af572019-06-05 19:13:04 +02002762 netsliceInstanceId: _id of the nsir to perform the operation
Felipe Vicens07f31722018-10-29 15:16:44 +01002763 operation: it can be: instantiate, terminate, action, TODO: update, heal
2764 :param kwargs: used to override the indata descriptor
2765 :param headers: http request headers
Felipe Vicens07f31722018-10-29 15:16:44 +01002766 :return: id of the nslcmops
2767 """
2768 try:
2769 # Override descriptor with query string kwargs
2770 self._update_input_with_kwargs(indata, kwargs)
2771 operation = indata["lcmOperationType"]
Felipe Vicens126af572019-06-05 19:13:04 +02002772 netsliceInstanceId = indata["netsliceInstanceId"]
Felipe Vicens07f31722018-10-29 15:16:44 +01002773 validate_input(indata, self.operation_schema[operation])
2774
Felipe Vicens126af572019-06-05 19:13:04 +02002775 # get nsi from netsliceInstanceId
tiernob4844ab2019-05-23 08:42:12 +00002776 _filter = self._get_project_filter(session)
Felipe Vicens126af572019-06-05 19:13:04 +02002777 _filter["_id"] = netsliceInstanceId
Felipe Vicens07f31722018-10-29 15:16:44 +01002778 nsir = self.db.get_one("nsis", _filter)
tierno40f742b2020-06-23 15:25:26 +00002779 logging_prefix = "nsi={} {} ".format(netsliceInstanceId, operation)
tiernob4844ab2019-05-23 08:42:12 +00002780 del _filter["_id"]
Felipe Vicens07f31722018-10-29 15:16:44 +01002781
2782 # initial checking
garciadeblas4568a372021-03-24 09:19:48 +01002783 if (
2784 not nsir["_admin"].get("nsiState")
2785 or nsir["_admin"]["nsiState"] == "NOT_INSTANTIATED"
2786 ):
Felipe Vicens07f31722018-10-29 15:16:44 +01002787 if operation == "terminate" and indata.get("autoremove"):
2788 # NSIR must be deleted
garciadeblas4568a372021-03-24 09:19:48 +01002789 return (
2790 None,
2791 None,
2792 ) # a none in this case is used to indicate not instantiated. It can be removed
Felipe Vicens07f31722018-10-29 15:16:44 +01002793 if operation != "instantiate":
garciadeblas4568a372021-03-24 09:19:48 +01002794 raise EngineException(
2795 "netslice_instance '{}' cannot be '{}' because it is not instantiated".format(
2796 netsliceInstanceId, operation
2797 ),
2798 HTTPStatus.CONFLICT,
2799 )
Felipe Vicens07f31722018-10-29 15:16:44 +01002800 else:
tierno65ca36d2019-02-12 19:27:52 +01002801 if operation == "instantiate" and not session["force"]:
garciadeblas4568a372021-03-24 09:19:48 +01002802 raise EngineException(
2803 "netslice_instance '{}' cannot be '{}' because it is already instantiated".format(
2804 netsliceInstanceId, operation
2805 ),
2806 HTTPStatus.CONFLICT,
2807 )
2808
Felipe Vicens07f31722018-10-29 15:16:44 +01002809 # Creating all the NS_operation (nslcmop)
2810 # Get service list from db
2811 nsrs_list = nsir["_admin"]["nsrs-detailed-list"]
2812 nslcmops = []
Felipe Vicens09e65422019-01-22 15:06:46 +01002813 # nslcmops_item = None
2814 for index, nsr_item in enumerate(nsrs_list):
tierno40f742b2020-06-23 15:25:26 +00002815 nsr_id = nsr_item["nsrId"]
Felipe Vicens09e65422019-01-22 15:06:46 +01002816 if nsr_item.get("shared"):
Felipe Vicens58e2d2f2019-05-30 13:01:20 +02002817 _filter["_admin.nsrs-detailed-list.ANYINDEX.shared"] = True
tierno40f742b2020-06-23 15:25:26 +00002818 _filter["_admin.nsrs-detailed-list.ANYINDEX.nsrId"] = nsr_id
garciadeblas4568a372021-03-24 09:19:48 +01002819 _filter[
2820 "_admin.nsrs-detailed-list.ANYINDEX.nslcmop_instantiate.ne"
2821 ] = None
Felipe Vicens126af572019-06-05 19:13:04 +02002822 _filter["_id.ne"] = netsliceInstanceId
garciadeblas4568a372021-03-24 09:19:48 +01002823 nsi = self.db.get_one(
2824 "nsis", _filter, fail_on_empty=False, fail_on_more=False
2825 )
Felipe Vicens58e2d2f2019-05-30 13:01:20 +02002826 if operation == "terminate":
garciadeblas4568a372021-03-24 09:19:48 +01002827 _update = {
2828 "_admin.nsrs-detailed-list.{}.nslcmop_instantiate".format(
2829 index
2830 ): None
2831 }
Felipe Vicens58e2d2f2019-05-30 13:01:20 +02002832 self.db.set_one("nsis", {"_id": nsir["_id"]}, _update)
garciadeblas4568a372021-03-24 09:19:48 +01002833 if (
2834 nsi
2835 ): # other nsi is using this nsr and it needs this nsr instantiated
tierno40f742b2020-06-23 15:25:26 +00002836 continue # do not create nsilcmop
2837 else: # instantiate
2838 # looks the first nsi fulfilling the conditions but not being the current NSIR
2839 if nsi:
garciadeblas4568a372021-03-24 09:19:48 +01002840 nsi_nsr_item = next(
2841 n
2842 for n in nsi["_admin"]["nsrs-detailed-list"]
2843 if n["nsrId"] == nsr_id
2844 and n["shared"]
2845 and n["nslcmop_instantiate"]
2846 )
tierno40f742b2020-06-23 15:25:26 +00002847 self.add_shared_nsr_2vld(nsir, nsr_item)
2848 nslcmops.append(nsi_nsr_item["nslcmop_instantiate"])
garciadeblas4568a372021-03-24 09:19:48 +01002849 _update = {
2850 "_admin.nsrs-detailed-list.{}".format(
2851 index
2852 ): nsi_nsr_item
2853 }
tierno40f742b2020-06-23 15:25:26 +00002854 self.db.set_one("nsis", {"_id": nsir["_id"]}, _update)
2855 # continue to not create nslcmop since nsrs is shared and nsrs was created
2856 continue
2857 else:
2858 self.add_shared_nsr_2vld(nsir, nsr_item)
Felipe Vicens09e65422019-01-22 15:06:46 +01002859
tierno40f742b2020-06-23 15:25:26 +00002860 # create operation
Felipe Vicens09e65422019-01-22 15:06:46 +01002861 try:
tierno0b8752f2020-05-12 09:42:02 +00002862 indata_ns = {
2863 "lcmOperationType": operation,
tierno40f742b2020-06-23 15:25:26 +00002864 "nsInstanceId": nsr_id,
tierno0b8752f2020-05-12 09:42:02 +00002865 # Including netslice_id in the ns instantiate Operation
2866 "netsliceInstanceId": netsliceInstanceId,
2867 }
2868 if operation == "instantiate":
tierno40f742b2020-06-23 15:25:26 +00002869 service = self.db.get_one("nsrs", {"_id": nsr_id})
tierno0b8752f2020-05-12 09:42:02 +00002870 indata_ns.update(service["instantiate_params"])
2871
tierno99d4b172019-07-02 09:28:40 +00002872 # Creating NS_LCM_OP with the flag slice_object=True to not trigger the service instantiation
Felipe Vicens09e65422019-01-22 15:06:46 +01002873 # message via kafka bus
garciadeblas4568a372021-03-24 09:19:48 +01002874 nslcmop, _ = self.nsi_NsLcmOpTopic.new(
2875 rollback, session, indata_ns, None, headers, slice_object=True
2876 )
Felipe Vicens09e65422019-01-22 15:06:46 +01002877 nslcmops.append(nslcmop)
tierno40f742b2020-06-23 15:25:26 +00002878 if operation == "instantiate":
garciadeblas4568a372021-03-24 09:19:48 +01002879 _update = {
2880 "_admin.nsrs-detailed-list.{}.nslcmop_instantiate".format(
2881 index
2882 ): nslcmop
2883 }
tierno40f742b2020-06-23 15:25:26 +00002884 self.db.set_one("nsis", {"_id": nsir["_id"]}, _update)
Felipe Vicens09e65422019-01-22 15:06:46 +01002885 except (DbException, EngineException) as e:
2886 if e.http_code == HTTPStatus.NOT_FOUND:
garciadeblas4568a372021-03-24 09:19:48 +01002887 self.logger.info(
2888 logging_prefix
2889 + "skipping NS={} because not found".format(nsr_id)
2890 )
Felipe Vicens09e65422019-01-22 15:06:46 +01002891 pass
2892 else:
2893 raise
Felipe Vicens07f31722018-10-29 15:16:44 +01002894
2895 # Creates nsilcmop
2896 indata["nslcmops_ids"] = nslcmops
2897 self._check_nsi_operation(session, nsir, operation, indata)
Felipe Vicens09e65422019-01-22 15:06:46 +01002898
garciadeblas4568a372021-03-24 09:19:48 +01002899 nsilcmop_desc = self._create_nsilcmop(
2900 session, netsliceInstanceId, operation, indata
2901 )
2902 self.format_on_new(
2903 nsilcmop_desc, session["project_id"], make_public=session["public"]
2904 )
Felipe Vicens07f31722018-10-29 15:16:44 +01002905 _id = self.db.create("nsilcmops", nsilcmop_desc)
2906 rollback.append({"topic": "nsilcmops", "_id": _id})
2907 self.msg.write("nsi", operation, nsilcmop_desc)
tiernobdebce92019-07-01 15:36:49 +00002908 return _id, None
Felipe Vicens07f31722018-10-29 15:16:44 +01002909 except ValidationError as e:
2910 raise EngineException(e, HTTPStatus.UNPROCESSABLE_ENTITY)
Felipe Vicens07f31722018-10-29 15:16:44 +01002911
tiernobee3bad2019-12-05 12:26:01 +00002912 def delete(self, session, _id, dry_run=False, not_send_msg=None):
garciadeblas4568a372021-03-24 09:19:48 +01002913 raise EngineException(
2914 "Method delete called directly", HTTPStatus.INTERNAL_SERVER_ERROR
2915 )
Felipe Vicens07f31722018-10-29 15:16:44 +01002916
tierno65ca36d2019-02-12 19:27:52 +01002917 def edit(self, session, _id, indata=None, kwargs=None, content=None):
garciadeblas4568a372021-03-24 09:19:48 +01002918 raise EngineException(
2919 "Method edit called directly", HTTPStatus.INTERNAL_SERVER_ERROR
2920 )