blob: 1b464ee88ba30c3e81abf53ff31dfe2c3f3c32b0 [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
17from uuid import uuid4
18from http import HTTPStatus
19from time import time
tiernocc103432018-10-19 14:10:35 +020020from copy import copy, deepcopy
tierno23acf402019-08-28 13:36:34 +000021from osm_nbi.validation import validate_input, ValidationError, ns_instantiate, ns_action, ns_scale, nsi_instantiate
22from osm_nbi.base_topic import BaseTopic, EngineException, get_iterable
tiernob4844ab2019-05-23 08:42:12 +000023# from descriptor_topics import DescriptorTopic
tiernobee085c2018-12-12 17:03:04 +000024from yaml import safe_dump
Felipe Vicens09e65422019-01-22 15:06:46 +010025from osm_common.dbbase import DbException
tierno1bfe4e22019-09-02 16:03:25 +000026from osm_common.msgbase import MsgException
27from osm_common.fsbase import FsException
delacruzramo36ffe552019-05-03 14:52:37 +020028from re import match # For checking that additional parameter names are valid Jinja2 identifiers
tiernob24258a2018-10-04 18:39:49 +020029
30__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
31
32
33class NsrTopic(BaseTopic):
34 topic = "nsrs"
35 topic_msg = "ns"
tiernod77ba6f2019-06-27 14:31:10 +000036 schema_new = ns_instantiate
tiernob24258a2018-10-04 18:39:49 +020037
delacruzramo32bab472019-09-13 12:24:22 +020038 def __init__(self, db, fs, msg, auth):
39 BaseTopic.__init__(self, db, fs, msg, auth)
tiernob24258a2018-10-04 18:39:49 +020040
41 def _check_descriptor_dependencies(self, session, descriptor):
42 """
43 Check that the dependent descriptors exist on a new descriptor or edition
44 :param session: client session information
45 :param descriptor: descriptor to be inserted or edit
46 :return: None or raises exception
47 """
48 if not descriptor.get("nsdId"):
49 return
50 nsd_id = descriptor["nsdId"]
51 if not self.get_item_list(session, "nsds", {"id": nsd_id}):
52 raise EngineException("Descriptor error at nsdId='{}' references a non exist nsd".format(nsd_id),
53 http_code=HTTPStatus.CONFLICT)
54
55 @staticmethod
56 def format_on_new(content, project_id=None, make_public=False):
57 BaseTopic.format_on_new(content, project_id=project_id, make_public=make_public)
58 content["_admin"]["nsState"] = "NOT_INSTANTIATED"
tiernobdebce92019-07-01 15:36:49 +000059 return None
tiernob24258a2018-10-04 18:39:49 +020060
tiernob4844ab2019-05-23 08:42:12 +000061 def check_conflict_on_del(self, session, _id, db_content):
62 """
63 Check that NSR is not instantiated
64 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
65 :param _id: nsr internal id
66 :param db_content: The database content of the nsr
67 :return: None or raises EngineException with the conflict
68 """
tierno65ca36d2019-02-12 19:27:52 +010069 if session["force"]:
tiernob24258a2018-10-04 18:39:49 +020070 return
tiernob4844ab2019-05-23 08:42:12 +000071 nsr = db_content
tiernob24258a2018-10-04 18:39:49 +020072 if nsr["_admin"].get("nsState") == "INSTANTIATED":
73 raise EngineException("nsr '{}' cannot be deleted because it is in 'INSTANTIATED' state. "
74 "Launch 'terminate' operation first; or force deletion".format(_id),
75 http_code=HTTPStatus.CONFLICT)
76
tiernob4844ab2019-05-23 08:42:12 +000077 def delete_extra(self, session, _id, db_content):
78 """
79 Deletes associated nslcmops and vnfrs from database. Deletes associated filesystem.
80 Set usageState of pdu, vnfd, nsd
81 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
82 :param _id: server internal id
83 :param db_content: The database content of the descriptor
84 :return: None if ok or raises EngineException with the problem
85 """
tiernobee085c2018-12-12 17:03:04 +000086 self.fs.file_delete(_id, ignore_non_exist=True)
tiernob24258a2018-10-04 18:39:49 +020087 self.db.del_list("nslcmops", {"nsInstanceId": _id})
88 self.db.del_list("vnfrs", {"nsr-id-ref": _id})
tiernob4844ab2019-05-23 08:42:12 +000089
tiernob24258a2018-10-04 18:39:49 +020090 # set all used pdus as free
91 self.db.set_list("pdus", {"_admin.usage.nsr_id": _id},
tierno36ec8602018-11-02 17:27:11 +010092 {"_admin.usageState": "NOT_IN_USE", "_admin.usage": None})
tiernob24258a2018-10-04 18:39:49 +020093
tiernob4844ab2019-05-23 08:42:12 +000094 # Set NSD usageState
95 nsr = db_content
96 used_nsd_id = nsr.get("nsd-id")
97 if used_nsd_id:
98 # check if used by another NSR
99 nsrs_list = self.db.get_one("nsrs", {"nsd-id": used_nsd_id},
100 fail_on_empty=False, fail_on_more=False)
101 if not nsrs_list:
102 self.db.set_one("nsds", {"_id": used_nsd_id}, {"_admin.usageState": "NOT_IN_USE"})
103
104 # Set VNFD usageState
105 used_vnfd_id_list = nsr.get("vnfd-id")
106 if used_vnfd_id_list:
107 for used_vnfd_id in used_vnfd_id_list:
108 # check if used by another NSR
109 nsrs_list = self.db.get_one("nsrs", {"vnfd-id": used_vnfd_id},
110 fail_on_empty=False, fail_on_more=False)
111 if not nsrs_list:
112 self.db.set_one("vnfds", {"_id": used_vnfd_id}, {"_admin.usageState": "NOT_IN_USE"})
113
tiernobee085c2018-12-12 17:03:04 +0000114 @staticmethod
115 def _format_ns_request(ns_request):
116 formated_request = copy(ns_request)
117 formated_request.pop("additionalParamsForNs", None)
118 formated_request.pop("additionalParamsForVnf", None)
119 return formated_request
120
121 @staticmethod
122 def _format_addional_params(ns_request, member_vnf_index=None, descriptor=None):
123 """
124 Get and format user additional params for NS or VNF
125 :param ns_request: User instantiation additional parameters
126 :param member_vnf_index: None for extract NS params, or member_vnf_index to extract VNF params
127 :param descriptor: If not None it check that needed parameters of descriptor are supplied
128 :return: a formated copy of additional params or None if not supplied
129 """
130 additional_params = None
131 if not member_vnf_index:
132 additional_params = copy(ns_request.get("additionalParamsForNs"))
133 where_ = "additionalParamsForNs"
134 elif ns_request.get("additionalParamsForVnf"):
135 for additionalParamsForVnf in get_iterable(ns_request.get("additionalParamsForVnf")):
136 if additionalParamsForVnf["member-vnf-index"] == member_vnf_index:
137 additional_params = copy(additionalParamsForVnf.get("additionalParams"))
138 where_ = "additionalParamsForVnf[member-vnf-index={}]".format(
139 additionalParamsForVnf["member-vnf-index"])
140 break
141 if additional_params:
142 for k, v in additional_params.items():
delacruzramo36ffe552019-05-03 14:52:37 +0200143 # BEGIN Check that additional parameter names are valid Jinja2 identifiers
144 if not match('^[a-zA-Z_][a-zA-Z0-9_]*$', k):
145 raise EngineException("Invalid param name at {}:{}. Must contain only alphanumeric characters "
146 "and underscores, and cannot start with a digit"
147 .format(where_, k))
148 # END Check that additional parameter names are valid Jinja2 identifiers
tiernobee085c2018-12-12 17:03:04 +0000149 if not isinstance(k, str):
150 raise EngineException("Invalid param at {}:{}. Only string keys are allowed".format(where_, k))
151 if "." in k or "$" in k:
152 raise EngineException("Invalid param at {}:{}. Keys must not contain dots or $".format(where_, k))
153 if isinstance(v, (dict, tuple, list)):
154 additional_params[k] = "!!yaml " + safe_dump(v)
155
156 if descriptor:
157 # check that enough parameters are supplied for the initial-config-primitive
158 # TODO: check for cloud-init
159 if member_vnf_index:
160 if descriptor.get("vnf-configuration"):
161 for initial_primitive in get_iterable(
162 descriptor["vnf-configuration"].get("initial-config-primitive")):
163 for param in get_iterable(initial_primitive.get("parameter")):
164 if param["value"].startswith("<") and param["value"].endswith(">"):
165 if param["value"] in ("<rw_mgmt_ip>", "<VDU_SCALE_INFO>"):
166 continue
167 if not additional_params or param["value"][1:-1] not in additional_params:
168 raise EngineException("Parameter '{}' needed for vnfd[id={}]:vnf-configuration:"
169 "initial-config-primitive[name={}] not supplied".
170 format(param["value"], descriptor["id"],
171 initial_primitive["name"]))
172
173 return additional_params
174
tierno65ca36d2019-02-12 19:27:52 +0100175 def new(self, rollback, session, indata=None, kwargs=None, headers=None):
tiernob24258a2018-10-04 18:39:49 +0200176 """
177 Creates a new nsr into database. It also creates needed vnfrs
178 :param rollback: list to append the created items at database in case a rollback must be done
tierno65ca36d2019-02-12 19:27:52 +0100179 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
tiernob24258a2018-10-04 18:39:49 +0200180 :param indata: params to be used for the nsr
181 :param kwargs: used to override the indata descriptor
182 :param headers: http request headers
tierno1bfe4e22019-09-02 16:03:25 +0000183 :return: the _id of nsr descriptor created at database. Or an exception of type
184 EngineException, ValidationError, DbException, FsException, MsgException.
185 Note: Exceptions are not captured on purpose. They should be captured at called
tiernob24258a2018-10-04 18:39:49 +0200186 """
187
188 try:
delacruzramo32bab472019-09-13 12:24:22 +0200189 step = "checking quotas"
190 self.check_quota(session)
191
tierno99d4b172019-07-02 09:28:40 +0000192 step = "validating input parameters"
tiernob24258a2018-10-04 18:39:49 +0200193 ns_request = self._remove_envelop(indata)
194 # Override descriptor with query string kwargs
195 self._update_input_with_kwargs(ns_request, kwargs)
tierno65ca36d2019-02-12 19:27:52 +0100196 self._validate_input_new(ns_request, session["force"])
tiernob24258a2018-10-04 18:39:49 +0200197
tiernob24258a2018-10-04 18:39:49 +0200198 # look for nsr
199 step = "getting nsd id='{}' from database".format(ns_request.get("nsdId"))
tiernob4844ab2019-05-23 08:42:12 +0000200 _filter = self._get_project_filter(session)
201 _filter["_id"] = ns_request["nsdId"]
tiernob24258a2018-10-04 18:39:49 +0200202 nsd = self.db.get_one("nsds", _filter)
tiernob4844ab2019-05-23 08:42:12 +0000203 del _filter["_id"]
tiernob24258a2018-10-04 18:39:49 +0200204
205 nsr_id = str(uuid4())
tiernobee085c2018-12-12 17:03:04 +0000206
tiernob24258a2018-10-04 18:39:49 +0200207 now = time()
208 step = "filling nsr from input data"
209 nsr_descriptor = {
210 "name": ns_request["nsName"],
211 "name-ref": ns_request["nsName"],
212 "short-name": ns_request["nsName"],
213 "admin-status": "ENABLED",
214 "nsd": nsd,
215 "datacenter": ns_request["vimAccountId"],
216 "resource-orchestrator": "osmopenmano",
217 "description": ns_request.get("nsDescription", ""),
218 "constituent-vnfr-ref": [],
219
220 "operational-status": "init", # typedef ns-operational-
221 "config-status": "init", # typedef config-states
222 "detailed-status": "scheduled",
223
224 "orchestration-progress": {},
225 # {"networks": {"active": 0, "total": 0}, "vms": {"active": 0, "total": 0}},
226
tierno65ca36d2019-02-12 19:27:52 +0100227 "create-time": now,
tiernob24258a2018-10-04 18:39:49 +0200228 "nsd-name-ref": nsd["name"],
229 "operational-events": [], # "id", "timestamp", "description", "event",
230 "nsd-ref": nsd["id"],
tiernof0637052019-03-07 16:26:47 +0000231 "nsd-id": nsd["_id"],
tiernob4844ab2019-05-23 08:42:12 +0000232 "vnfd-id": [],
tiernobee085c2018-12-12 17:03:04 +0000233 "instantiate_params": self._format_ns_request(ns_request),
234 "additionalParamsForNs": self._format_addional_params(ns_request),
tiernob24258a2018-10-04 18:39:49 +0200235 "ns-instance-config-ref": nsr_id,
236 "id": nsr_id,
237 "_id": nsr_id,
238 # "input-parameter": xpath, value,
tierno99d4b172019-07-02 09:28:40 +0000239 "ssh-authorized-key": ns_request.get("ssh_keys"), # TODO remove
tiernob24258a2018-10-04 18:39:49 +0200240 }
241 ns_request["nsr_id"] = nsr_id
tierno36ec8602018-11-02 17:27:11 +0100242 # Create vld
243 if nsd.get("vld"):
244 nsr_descriptor["vld"] = []
245 for nsd_vld in nsd.get("vld"):
246 nsr_descriptor["vld"].append(
gcalvino17d5b732018-12-17 16:26:21 +0100247 {key: nsd_vld[key] for key in ("id", "vim-network-name", "vim-network-id") if key in nsd_vld})
tiernob24258a2018-10-04 18:39:49 +0200248
249 # Create VNFR
250 needed_vnfds = {}
gcalvino4f269dd2018-11-06 13:18:31 +0100251 for member_vnf in nsd.get("constituent-vnfd", ()):
tiernob24258a2018-10-04 18:39:49 +0200252 vnfd_id = member_vnf["vnfd-id-ref"]
253 step = "getting vnfd id='{}' constituent-vnfd='{}' from database".format(
254 member_vnf["vnfd-id-ref"], member_vnf["member-vnf-index"])
255 if vnfd_id not in needed_vnfds:
256 # Obtain vnfd
tiernob4844ab2019-05-23 08:42:12 +0000257 _filter["id"] = vnfd_id
258 vnfd = self.db.get_one("vnfds", _filter, fail_on_empty=True, fail_on_more=True)
259 del _filter["id"]
tiernob24258a2018-10-04 18:39:49 +0200260 vnfd.pop("_admin")
261 needed_vnfds[vnfd_id] = vnfd
tiernob4844ab2019-05-23 08:42:12 +0000262 nsr_descriptor["vnfd-id"].append(vnfd["_id"])
tiernob24258a2018-10-04 18:39:49 +0200263 else:
264 vnfd = needed_vnfds[vnfd_id]
265 step = "filling vnfr vnfd-id='{}' constituent-vnfd='{}'".format(
266 member_vnf["vnfd-id-ref"], member_vnf["member-vnf-index"])
267 vnfr_id = str(uuid4())
268 vnfr_descriptor = {
269 "id": vnfr_id,
270 "_id": vnfr_id,
271 "nsr-id-ref": nsr_id,
272 "member-vnf-index-ref": member_vnf["member-vnf-index"],
tiernobee085c2018-12-12 17:03:04 +0000273 "additionalParamsForVnf": self._format_addional_params(ns_request, member_vnf["member-vnf-index"],
274 vnfd),
tiernob24258a2018-10-04 18:39:49 +0200275 "created-time": now,
276 # "vnfd": vnfd, # at OSM model.but removed to avoid data duplication TODO: revise
277 "vnfd-ref": vnfd_id,
278 "vnfd-id": vnfd["_id"], # not at OSM model, but useful
279 "vim-account-id": None,
280 "vdur": [],
281 "connection-point": [],
282 "ip-address": None, # mgmt-interface filled by LCM
283 }
tierno36ec8602018-11-02 17:27:11 +0100284
285 # Create vld
286 if vnfd.get("internal-vld"):
287 vnfr_descriptor["vld"] = []
288 for vnfd_vld in vnfd.get("internal-vld"):
289 vnfr_descriptor["vld"].append(
gcalvino17d5b732018-12-17 16:26:21 +0100290 {key: vnfd_vld[key] for key in ("id", "vim-network-name", "vim-network-id") if key in
291 vnfd_vld})
tierno36ec8602018-11-02 17:27:11 +0100292
293 vnfd_mgmt_cp = vnfd["mgmt-interface"].get("cp")
tiernob24258a2018-10-04 18:39:49 +0200294 for cp in vnfd.get("connection-point", ()):
295 vnf_cp = {
296 "name": cp["name"],
297 "connection-point-id": cp.get("id"),
298 "id": cp.get("id"),
299 # "ip-address", "mac-address" # filled by LCM
300 # vim-id # TODO it would be nice having a vim port id
301 }
302 vnfr_descriptor["connection-point"].append(vnf_cp)
tierno9cb7d672019-10-30 12:13:48 +0000303
tiernoc67b0e92019-11-05 12:45:29 +0000304 # Create k8s-cluster information
305 if vnfd.get("k8s-cluster"):
306 vnfr_descriptor["k8s-cluster"] = vnfd["k8s-cluster"]
307 for net in get_iterable(vnfr_descriptor["k8s-cluster"].get("nets")):
308 if net.get("external-connection-point-ref"):
309 for nsd_vld in get_iterable(nsd.get("vld")):
310 for nsd_vld_cp in get_iterable(nsd_vld.get("vnfd-connection-point-ref")):
311 if nsd_vld_cp.get("vnfd-connection-point-ref") == \
312 net["external-connection-point-ref"] and \
313 nsd_vld_cp.get("member-vnf-index-ref") == member_vnf["member-vnf-index"]:
314 net["ns-vld-id"] = nsd_vld["id"]
315 break
316 else:
317 continue
318 break
319 elif net.get("internal-connection-point-ref"):
320 for vnfd_ivld in get_iterable(vnfd.get("internal-vld")):
321 for vnfd_ivld_icp in get_iterable(vnfd_ivld.get("internal-connection-point")):
322 if vnfd_ivld_icp.get("id-ref") == net["internal-connection-point-ref"]:
323 net["vnf-vld-id"] = vnfd_ivld["id"]
324 break
325 else:
326 continue
327 break
tierno9cb7d672019-10-30 12:13:48 +0000328 # update kdus
329 for kdu in get_iterable(vnfd.get("kdu")):
330 kdur = {
331 "kdu-name": kdu["name"],
332 # TODO "name": "" Name of the VDU in the VIM
333 "ip-address": None, # mgmt-interface filled by LCM
tiernoc67b0e92019-11-05 12:45:29 +0000334 "k8s-cluster": {}
tierno9cb7d672019-10-30 12:13:48 +0000335 }
336 if not vnfr_descriptor.get("kdur"):
337 vnfr_descriptor["kdur"] = []
338 vnfr_descriptor["kdur"].append(kdur)
339
gcalvinoe45aded2018-11-13 17:17:28 +0100340 for vdu in vnfd.get("vdu", ()):
tiernob24258a2018-10-04 18:39:49 +0200341 vdur = {
tiernob24258a2018-10-04 18:39:49 +0200342 "vdu-id-ref": vdu["id"],
343 # TODO "name": "" Name of the VDU in the VIM
344 "ip-address": None, # mgmt-interface filled by LCM
345 # "vim-id", "flavor-id", "image-id", "management-ip" # filled by LCM
346 "internal-connection-point": [],
347 "interfaces": [],
348 }
tiernocc103432018-10-19 14:10:35 +0200349 if vdu.get("pdu-type"):
350 vdur["pdu-type"] = vdu["pdu-type"]
tiernob24258a2018-10-04 18:39:49 +0200351 # TODO volumes: name, volume-id
352 for icp in vdu.get("internal-connection-point", ()):
353 vdu_icp = {
354 "id": icp["id"],
355 "connection-point-id": icp["id"],
356 "name": icp.get("name"),
357 # "ip-address", "mac-address" # filled by LCM
358 # vim-id # TODO it would be nice having a vim port id
359 }
360 vdur["internal-connection-point"].append(vdu_icp)
361 for iface in vdu.get("interface", ()):
362 vdu_iface = {
363 "name": iface.get("name"),
364 # "ip-address", "mac-address" # filled by LCM
365 # vim-id # TODO it would be nice having a vim port id
366 }
tierno36ec8602018-11-02 17:27:11 +0100367 if vnfd_mgmt_cp and iface.get("external-connection-point-ref") == vnfd_mgmt_cp:
368 vdu_iface["mgmt-vnf"] = True
tiernocc103432018-10-19 14:10:35 +0200369 if iface.get("mgmt-interface"):
tierno36ec8602018-11-02 17:27:11 +0100370 vdu_iface["mgmt-interface"] = True # TODO change to mgmt-vdu
371
372 # look for network where this interface is connected
373 if iface.get("external-connection-point-ref"):
374 for nsd_vld in get_iterable(nsd.get("vld")):
375 for nsd_vld_cp in get_iterable(nsd_vld.get("vnfd-connection-point-ref")):
376 if nsd_vld_cp.get("vnfd-connection-point-ref") == \
377 iface["external-connection-point-ref"] and \
378 nsd_vld_cp.get("member-vnf-index-ref") == member_vnf["member-vnf-index"]:
379 vdu_iface["ns-vld-id"] = nsd_vld["id"]
380 break
381 else:
382 continue
383 break
384 elif iface.get("internal-connection-point-ref"):
385 for vnfd_ivld in get_iterable(vnfd.get("internal-vld")):
386 for vnfd_ivld_icp in get_iterable(vnfd_ivld.get("internal-connection-point")):
387 if vnfd_ivld_icp.get("id-ref") == iface["internal-connection-point-ref"]:
388 vdu_iface["vnf-vld-id"] = vnfd_ivld["id"]
389 break
390 else:
391 continue
392 break
tiernocc103432018-10-19 14:10:35 +0200393
tiernob24258a2018-10-04 18:39:49 +0200394 vdur["interfaces"].append(vdu_iface)
tiernocc103432018-10-19 14:10:35 +0200395 count = vdu.get("count", 1)
396 if count is None:
397 count = 1
398 count = int(count) # TODO remove when descriptor serialized with payngbind
399 for index in range(0, count):
400 if index:
401 vdur = deepcopy(vdur)
402 vdur["_id"] = str(uuid4())
403 vdur["count-index"] = index
404 vnfr_descriptor["vdur"].append(vdur)
tiernob24258a2018-10-04 18:39:49 +0200405
406 step = "creating vnfr vnfd-id='{}' constituent-vnfd='{}' at database".format(
407 member_vnf["vnfd-id-ref"], member_vnf["member-vnf-index"])
408
409 # add at database
tiernobdebce92019-07-01 15:36:49 +0000410 self.format_on_new(vnfr_descriptor, session["project_id"], make_public=session["public"])
tiernob24258a2018-10-04 18:39:49 +0200411 self.db.create("vnfrs", vnfr_descriptor)
412 rollback.append({"topic": "vnfrs", "_id": vnfr_id})
413 nsr_descriptor["constituent-vnfr-ref"].append(vnfr_id)
414
415 step = "creating nsr at database"
tierno65ca36d2019-02-12 19:27:52 +0100416 self.format_on_new(nsr_descriptor, session["project_id"], make_public=session["public"])
tiernob24258a2018-10-04 18:39:49 +0200417 self.db.create("nsrs", nsr_descriptor)
418 rollback.append({"topic": "nsrs", "_id": nsr_id})
tiernobee085c2018-12-12 17:03:04 +0000419
420 step = "creating nsr temporal folder"
421 self.fs.mkdir(nsr_id)
422
tiernobdebce92019-07-01 15:36:49 +0000423 return nsr_id, None
tierno1bfe4e22019-09-02 16:03:25 +0000424 except (ValidationError, EngineException, DbException, MsgException, FsException) as e:
425 raise type(e)("{} while '{}".format(e, step), http_code=e.http_code)
tiernob24258a2018-10-04 18:39:49 +0200426
tierno65ca36d2019-02-12 19:27:52 +0100427 def edit(self, session, _id, indata=None, kwargs=None, content=None):
tiernob24258a2018-10-04 18:39:49 +0200428 raise EngineException("Method edit called directly", HTTPStatus.INTERNAL_SERVER_ERROR)
429
430
431class VnfrTopic(BaseTopic):
432 topic = "vnfrs"
433 topic_msg = None
434
delacruzramo32bab472019-09-13 12:24:22 +0200435 def __init__(self, db, fs, msg, auth):
436 BaseTopic.__init__(self, db, fs, msg, auth)
tiernob24258a2018-10-04 18:39:49 +0200437
tierno65ca36d2019-02-12 19:27:52 +0100438 def delete(self, session, _id, dry_run=False):
tiernob24258a2018-10-04 18:39:49 +0200439 raise EngineException("Method delete called directly", HTTPStatus.INTERNAL_SERVER_ERROR)
440
tierno65ca36d2019-02-12 19:27:52 +0100441 def edit(self, session, _id, indata=None, kwargs=None, content=None):
tiernob24258a2018-10-04 18:39:49 +0200442 raise EngineException("Method edit called directly", HTTPStatus.INTERNAL_SERVER_ERROR)
443
tierno65ca36d2019-02-12 19:27:52 +0100444 def new(self, rollback, session, indata=None, kwargs=None, headers=None):
tiernob24258a2018-10-04 18:39:49 +0200445 # Not used because vnfrs are created and deleted by NsrTopic class directly
446 raise EngineException("Method new called directly", HTTPStatus.INTERNAL_SERVER_ERROR)
447
448
449class NsLcmOpTopic(BaseTopic):
450 topic = "nslcmops"
451 topic_msg = "ns"
452 operation_schema = { # mapping between operation and jsonschema to validate
453 "instantiate": ns_instantiate,
454 "action": ns_action,
455 "scale": ns_scale,
456 "terminate": None,
457 }
458
delacruzramo32bab472019-09-13 12:24:22 +0200459 def __init__(self, db, fs, msg, auth):
460 BaseTopic.__init__(self, db, fs, msg, auth)
tiernob24258a2018-10-04 18:39:49 +0200461
tiernob24258a2018-10-04 18:39:49 +0200462 def _check_ns_operation(self, session, nsr, operation, indata):
463 """
464 Check that user has enter right parameters for the operation
tierno65ca36d2019-02-12 19:27:52 +0100465 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
tiernob24258a2018-10-04 18:39:49 +0200466 :param operation: it can be: instantiate, terminate, action, TODO: update, heal
467 :param indata: descriptor with the parameters of the operation
468 :return: None
469 """
tierno982da4e2019-09-03 11:51:55 +0000470 vnf_member_index_to_vnfd = {} # map between vnf_member_index to vnf descriptor.
tiernob24258a2018-10-04 18:39:49 +0200471 vim_accounts = []
tierno4f9d4ae2019-03-20 17:24:11 +0000472 wim_accounts = []
tiernob24258a2018-10-04 18:39:49 +0200473 nsd = nsr["nsd"]
474
475 def check_valid_vnf_member_index(member_vnf_index):
tierno982da4e2019-09-03 11:51:55 +0000476 # Obtain vnf descriptor. The vnfr is used to get the vnfd._id used for this member_vnf_index
477 if vnf_member_index_to_vnfd.get(member_vnf_index):
478 return vnf_member_index_to_vnfd[member_vnf_index]
479 vnfr = self.db.get_one("vnfrs",
480 {"nsr-id-ref": nsr["_id"], "member-vnf-index-ref": member_vnf_index},
481 fail_on_empty=False)
482 if not vnfr:
tiernob24258a2018-10-04 18:39:49 +0200483 raise EngineException("Invalid parameter member_vnf_index='{}' is not one of the "
484 "nsd:constituent-vnfd".format(member_vnf_index))
tierno982da4e2019-09-03 11:51:55 +0000485 vnfd = self.db.get_one("vnfds", {"_id": vnfr["vnfd-id"]}, fail_on_empty=False)
486 if not vnfd:
487 raise EngineException("vnfd id={} has been deleted!. Operation cannot be performed".
488 format(vnfr["vnfd-id"]))
489 vnf_member_index_to_vnfd[member_vnf_index] = vnfd # add to cache, avoiding a later look for
490 return vnfd
tiernob24258a2018-10-04 18:39:49 +0200491
tierno260dd6f2019-09-02 10:48:56 +0000492 def check_valid_vdu(vnfd, vdu_id):
493 for vdud in get_iterable(vnfd.get("vdu")):
494 if vdud["id"] == vdu_id:
495 return vdud
496 else:
497 raise EngineException("Invalid parameter vdu_id='{}' not present at vnfd:vdu:id".format(vdu_id))
498
tierno9cb7d672019-10-30 12:13:48 +0000499 def check_valid_kdu(vnfd, kdu_name):
500 for kdud in get_iterable(vnfd.get("kdu")):
501 if kdud["name"] == kdu_name:
502 return kdud
503 else:
504 raise EngineException("Invalid parameter kdu_name='{}' not present at vnfd:kdu:name".format(kdu_name))
505
gcalvino5e72d152018-10-23 11:46:57 +0200506 def _check_vnf_instantiation_params(in_vnfd, vnfd):
507
tierno40fbcad2018-10-26 10:58:15 +0200508 for in_vdu in get_iterable(in_vnfd.get("vdu")):
509 for vdu in get_iterable(vnfd.get("vdu")):
510 if in_vdu["id"] == vdu["id"]:
511 for volume in get_iterable(in_vdu.get("volume")):
512 for volumed in get_iterable(vdu.get("volumes")):
513 if volumed["name"] == volume["name"]:
514 break
515 else:
516 raise EngineException("Invalid parameter vnf[member-vnf-index='{}']:vdu[id='{}']:"
517 "volume:name='{}' is not present at vnfd:vdu:volumes list".
518 format(in_vnf["member-vnf-index"], in_vdu["id"],
519 volume["name"]))
520 for in_iface in get_iterable(in_vdu["interface"]):
521 for iface in get_iterable(vdu.get("interface")):
522 if in_iface["name"] == iface["name"]:
523 break
524 else:
525 raise EngineException("Invalid parameter vnf[member-vnf-index='{}']:vdu[id='{}']:"
526 "interface[name='{}'] is not present at vnfd:vdu:interface"
527 .format(in_vnf["member-vnf-index"], in_vdu["id"],
528 in_iface["name"]))
529 break
gcalvino5e72d152018-10-23 11:46:57 +0200530 else:
tierno40fbcad2018-10-26 10:58:15 +0200531 raise EngineException("Invalid parameter vnf[member-vnf-index='{}']:vdu[id='{}'] is is not present "
532 "at vnfd:vdu".format(in_vnf["member-vnf-index"], in_vdu["id"]))
gcalvino5e72d152018-10-23 11:46:57 +0200533
534 for in_ivld in get_iterable(in_vnfd.get("internal-vld")):
535 for ivld in get_iterable(vnfd.get("internal-vld")):
536 if in_ivld["name"] == ivld["name"] or in_ivld["name"] == ivld["id"]:
tierno1bfe4e22019-09-02 16:03:25 +0000537 for in_icp in get_iterable(in_ivld.get("internal-connection-point")):
gcalvino5e72d152018-10-23 11:46:57 +0200538 for icp in ivld["internal-connection-point"]:
539 if in_icp["id-ref"] == icp["id-ref"]:
540 break
541 else:
tierno40fbcad2018-10-26 10:58:15 +0200542 raise EngineException("Invalid parameter vnf[member-vnf-index='{}']:internal-vld[name"
543 "='{}']:internal-connection-point[id-ref:'{}'] is not present at "
544 "vnfd:internal-vld:name/id:internal-connection-point"
545 .format(in_vnf["member-vnf-index"], in_ivld["name"],
546 in_icp["id-ref"], vnfd["id"]))
gcalvino5e72d152018-10-23 11:46:57 +0200547 break
548 else:
549 raise EngineException("Invalid parameter vnf[member-vnf-index='{}']:internal-vld:name='{}'"
550 " is not present at vnfd '{}'".format(in_vnf["member-vnf-index"],
551 in_ivld["name"], vnfd["id"]))
552
tiernob24258a2018-10-04 18:39:49 +0200553 def check_valid_vim_account(vim_account):
554 if vim_account in vim_accounts:
555 return
556 try:
tierno65ca36d2019-02-12 19:27:52 +0100557 db_filter = self._get_project_filter(session)
tiernocc103432018-10-19 14:10:35 +0200558 db_filter["_id"] = vim_account
559 self.db.get_one("vim_accounts", db_filter)
tiernob24258a2018-10-04 18:39:49 +0200560 except Exception:
tiernocc103432018-10-19 14:10:35 +0200561 raise EngineException("Invalid vimAccountId='{}' not present for the project".format(vim_account))
tiernob24258a2018-10-04 18:39:49 +0200562 vim_accounts.append(vim_account)
563
tierno4f9d4ae2019-03-20 17:24:11 +0000564 def check_valid_wim_account(wim_account):
565 if not isinstance(wim_account, str):
566 return
567 elif wim_account in wim_accounts:
568 return
569 try:
570 db_filter = self._get_project_filter(session, write=False, show_all=True)
571 db_filter["_id"] = wim_account
572 self.db.get_one("wim_accounts", db_filter)
573 except Exception:
574 raise EngineException("Invalid wimAccountId='{}' not present for the project".format(wim_account))
575 wim_accounts.append(wim_account)
576
tiernob24258a2018-10-04 18:39:49 +0200577 if operation == "action":
578 # check vnf_member_index
579 if indata.get("vnf_member_index"):
580 indata["member_vnf_index"] = indata.pop("vnf_member_index") # for backward compatibility
tierno1ac7f462019-06-03 17:22:12 +0000581 if indata.get("member_vnf_index"):
582 vnfd = check_valid_vnf_member_index(indata["member_vnf_index"])
tierno260dd6f2019-09-02 10:48:56 +0000583 if indata.get("vdu_id"):
584 vdud = check_valid_vdu(vnfd, indata["vdu_id"])
585 descriptor_configuration = vdud.get("vdu-configuration", {}).get("config-primitive")
tierno9cb7d672019-10-30 12:13:48 +0000586 elif indata.get("kdu_name"):
tiernoc67b0e92019-11-05 12:45:29 +0000587 kdud = check_valid_kdu(vnfd, indata["kdu_name"])
tierno9cb7d672019-10-30 12:13:48 +0000588 descriptor_configuration = kdud.get("kdu-configuration", {}).get("config-primitive")
tierno260dd6f2019-09-02 10:48:56 +0000589 else:
590 descriptor_configuration = vnfd.get("vnf-configuration", {}).get("config-primitive")
tierno1ac7f462019-06-03 17:22:12 +0000591 else: # use a NSD
592 descriptor_configuration = nsd.get("ns-configuration", {}).get("config-primitive")
tierno9cb7d672019-10-30 12:13:48 +0000593
594 # For k8s allows default primitives without validating the parameters
delacruzramo6ddff2e2019-11-28 11:24:09 +0100595 if indata.get("kdu_name") and indata["primitive"] in ("upgrade", "rollback", "status", "inspect", "readme"):
tierno9cb7d672019-10-30 12:13:48 +0000596 # TODO should be checked that rollback only can contains revsision_numbe????
delacruzramo6ddff2e2019-11-28 11:24:09 +0100597 if not indata.get("member_vnf_index"):
598 raise EngineException("Missing action parameter 'member_vnf_index' for default KDU primitive '{}'"
599 .format(indata["primitive"]))
tierno9cb7d672019-10-30 12:13:48 +0000600 return
601 # if not, check primitive
tierno1ac7f462019-06-03 17:22:12 +0000602 for config_primitive in get_iterable(descriptor_configuration):
tiernob24258a2018-10-04 18:39:49 +0200603 if indata["primitive"] == config_primitive["name"]:
604 # check needed primitive_params are provided
605 if indata.get("primitive_params"):
606 in_primitive_params_copy = copy(indata["primitive_params"])
607 else:
608 in_primitive_params_copy = {}
609 for paramd in get_iterable(config_primitive.get("parameter")):
610 if paramd["name"] in in_primitive_params_copy:
611 del in_primitive_params_copy[paramd["name"]]
612 elif not paramd.get("default-value"):
613 raise EngineException("Needed parameter {} not provided for primitive '{}'".format(
614 paramd["name"], indata["primitive"]))
615 # check no extra primitive params are provided
616 if in_primitive_params_copy:
tierno1ac7f462019-06-03 17:22:12 +0000617 raise EngineException("parameter/s '{}' not present at vnfd /nsd for primitive '{}'".format(
tiernob24258a2018-10-04 18:39:49 +0200618 list(in_primitive_params_copy.keys()), indata["primitive"]))
619 break
620 else:
tierno1ac7f462019-06-03 17:22:12 +0000621 raise EngineException("Invalid primitive '{}' is not present at vnfd/nsd".format(indata["primitive"]))
tiernob24258a2018-10-04 18:39:49 +0200622 if operation == "scale":
623 vnfd = check_valid_vnf_member_index(indata["scaleVnfData"]["scaleByStepData"]["member-vnf-index"])
624 for scaling_group in get_iterable(vnfd.get("scaling-group-descriptor")):
625 if indata["scaleVnfData"]["scaleByStepData"]["scaling-group-descriptor"] == scaling_group["name"]:
626 break
627 else:
628 raise EngineException("Invalid scaleVnfData:scaleByStepData:scaling-group-descriptor '{}' is not "
629 "present at vnfd:scaling-group-descriptor".format(
630 indata["scaleVnfData"]["scaleByStepData"]["scaling-group-descriptor"]))
631 if operation == "instantiate":
632 # check vim_account
633 check_valid_vim_account(indata["vimAccountId"])
tierno4f9d4ae2019-03-20 17:24:11 +0000634 check_valid_wim_account(indata.get("wimAccountId"))
tiernob24258a2018-10-04 18:39:49 +0200635 for in_vnf in get_iterable(indata.get("vnf")):
636 vnfd = check_valid_vnf_member_index(in_vnf["member-vnf-index"])
gcalvino5e72d152018-10-23 11:46:57 +0200637 _check_vnf_instantiation_params(in_vnf, vnfd)
tiernob24258a2018-10-04 18:39:49 +0200638 if in_vnf.get("vimAccountId"):
639 check_valid_vim_account(in_vnf["vimAccountId"])
tiernob24258a2018-10-04 18:39:49 +0200640
tiernob24258a2018-10-04 18:39:49 +0200641 for in_vld in get_iterable(indata.get("vld")):
tierno4f9d4ae2019-03-20 17:24:11 +0000642 check_valid_wim_account(in_vld.get("wimAccountId"))
tiernob24258a2018-10-04 18:39:49 +0200643 for vldd in get_iterable(nsd.get("vld")):
644 if in_vld["name"] == vldd["name"] or in_vld["name"] == vldd["id"]:
645 break
646 else:
647 raise EngineException("Invalid parameter vld:name='{}' is not present at nsd:vld".format(
648 in_vld["name"]))
649
tierno36ec8602018-11-02 17:27:11 +0100650 def _look_for_pdu(self, session, rollback, vnfr, vim_account, vnfr_update, vnfr_update_rollback):
tiernocc103432018-10-19 14:10:35 +0200651 """
tierno36ec8602018-11-02 17:27:11 +0100652 Look for a free PDU in the catalog matching vdur type and interfaces. Fills vnfr.vdur with the interface
653 (ip_address, ...) information.
654 Modifies PDU _admin.usageState to 'IN_USE'
655
tierno65ca36d2019-02-12 19:27:52 +0100656 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
tierno36ec8602018-11-02 17:27:11 +0100657 :param rollback: list with the database modifications to rollback if needed
658 :param vnfr: vnfr to be updated. It is modified with pdu interface info if pdu is found
659 :param vim_account: vim_account where this vnfr should be deployed
660 :param vnfr_update: dictionary filled by this method with changes to be done at database vnfr
661 :param vnfr_update_rollback: dictionary filled by this method with original content of vnfr in case a rollback
662 of the changed vnfr is needed
663
664 :return: List of PDU interfaces that are connected to an existing VIM network. Each item contains:
665 "vim-network-name": used at VIM
666 "name": interface name
667 "vnf-vld-id": internal VNFD vld where this interface is connected, or
668 "ns-vld-id": NSD vld where this interface is connected.
669 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 +0200670 """
tierno36ec8602018-11-02 17:27:11 +0100671
672 ifaces_forcing_vim_network = []
tiernocc103432018-10-19 14:10:35 +0200673 for vdur_index, vdur in enumerate(get_iterable(vnfr.get("vdur"))):
674 if not vdur.get("pdu-type"):
675 continue
676 pdu_type = vdur.get("pdu-type")
tierno65ca36d2019-02-12 19:27:52 +0100677 pdu_filter = self._get_project_filter(session)
tierno36ec8602018-11-02 17:27:11 +0100678 pdu_filter["vim_accounts"] = vim_account
tiernocc103432018-10-19 14:10:35 +0200679 pdu_filter["type"] = pdu_type
680 pdu_filter["_admin.operationalState"] = "ENABLED"
tierno36ec8602018-11-02 17:27:11 +0100681 pdu_filter["_admin.usageState"] = "NOT_IN_USE"
tiernocc103432018-10-19 14:10:35 +0200682 # TODO feature 1417: "shared": True,
683
684 available_pdus = self.db.get_list("pdus", pdu_filter)
685 for pdu in available_pdus:
686 # step 1 check if this pdu contains needed interfaces:
687 match_interfaces = True
688 for vdur_interface in vdur["interfaces"]:
689 for pdu_interface in pdu["interfaces"]:
690 if pdu_interface["name"] == vdur_interface["name"]:
691 # TODO feature 1417: match per mgmt type
692 break
693 else: # no interface found for name
694 match_interfaces = False
695 break
696 if match_interfaces:
697 break
698 else:
699 raise EngineException(
tierno36ec8602018-11-02 17:27:11 +0100700 "No PDU of type={} at vim_account={} found for member_vnf_index={}, vdu={} matching interface "
701 "names".format(pdu_type, vim_account, vnfr["member-vnf-index-ref"], vdur["vdu-id-ref"]))
tiernocc103432018-10-19 14:10:35 +0200702
703 # step 2. Update pdu
704 rollback_pdu = {
705 "_admin.usageState": pdu["_admin"]["usageState"],
706 "_admin.usage.vnfr_id": None,
707 "_admin.usage.nsr_id": None,
708 "_admin.usage.vdur": None,
709 }
710 self.db.set_one("pdus", {"_id": pdu["_id"]},
tierno36ec8602018-11-02 17:27:11 +0100711 {"_admin.usageState": "IN_USE",
tiernoe8631782018-12-21 13:31:52 +0000712 "_admin.usage": {"vnfr_id": vnfr["_id"],
713 "nsr_id": vnfr["nsr-id-ref"],
714 "vdur": vdur["vdu-id-ref"]}
715 })
tiernocc103432018-10-19 14:10:35 +0200716 rollback.append({"topic": "pdus", "_id": pdu["_id"], "operation": "set", "content": rollback_pdu})
717
718 # step 3. Fill vnfr info by filling vdur
719 vdu_text = "vdur.{}".format(vdur_index)
tierno36ec8602018-11-02 17:27:11 +0100720 vnfr_update_rollback[vdu_text + ".pdu-id"] = None
tiernocc103432018-10-19 14:10:35 +0200721 vnfr_update[vdu_text + ".pdu-id"] = pdu["_id"]
722 for iface_index, vdur_interface in enumerate(vdur["interfaces"]):
723 for pdu_interface in pdu["interfaces"]:
724 if pdu_interface["name"] == vdur_interface["name"]:
725 iface_text = vdu_text + ".interfaces.{}".format(iface_index)
726 for k, v in pdu_interface.items():
tierno36ec8602018-11-02 17:27:11 +0100727 if k in ("ip-address", "mac-address"): # TODO: switch-xxxxx must be inserted
728 vnfr_update[iface_text + ".{}".format(k)] = v
729 vnfr_update_rollback[iface_text + ".{}".format(k)] = vdur_interface.get(v)
730 if pdu_interface.get("ip-address"):
731 if vdur_interface.get("mgmt-interface"):
732 vnfr_update_rollback[vdu_text + ".ip-address"] = vdur.get("ip-address")
733 vnfr_update[vdu_text + ".ip-address"] = pdu_interface["ip-address"]
734 if vdur_interface.get("mgmt-vnf"):
735 vnfr_update_rollback["ip-address"] = vnfr.get("ip-address")
736 vnfr_update["ip-address"] = pdu_interface["ip-address"]
gcalvino17d5b732018-12-17 16:26:21 +0100737 if pdu_interface.get("vim-network-name") or pdu_interface.get("vim-network-id"):
tierno36ec8602018-11-02 17:27:11 +0100738 ifaces_forcing_vim_network.append({
tierno36ec8602018-11-02 17:27:11 +0100739 "name": vdur_interface.get("vnf-vld-id") or vdur_interface.get("ns-vld-id"),
740 "vnf-vld-id": vdur_interface.get("vnf-vld-id"),
741 "ns-vld-id": vdur_interface.get("ns-vld-id")})
gcalvino17d5b732018-12-17 16:26:21 +0100742 if pdu_interface.get("vim-network-id"):
tiernoc67b0e92019-11-05 12:45:29 +0000743 ifaces_forcing_vim_network[-1]["vim-network-id"] = pdu_interface["vim-network-id"]
gcalvino17d5b732018-12-17 16:26:21 +0100744 if pdu_interface.get("vim-network-name"):
tiernoc67b0e92019-11-05 12:45:29 +0000745 ifaces_forcing_vim_network[-1]["vim-network-name"] = pdu_interface["vim-network-name"]
tiernocc103432018-10-19 14:10:35 +0200746 break
747
tierno36ec8602018-11-02 17:27:11 +0100748 return ifaces_forcing_vim_network
tiernocc103432018-10-19 14:10:35 +0200749
tierno9cb7d672019-10-30 12:13:48 +0000750 def _look_for_k8scluster(self, session, rollback, vnfr, vim_account, vnfr_update, vnfr_update_rollback):
751 """
752 Look for an available k8scluster for all the kuds in the vnfd matching version and cni requirements.
753 Fills vnfr.kdur with the selected k8scluster
754
755 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
756 :param rollback: list with the database modifications to rollback if needed
757 :param vnfr: vnfr to be updated. It is modified with pdu interface info if pdu is found
758 :param vim_account: vim_account where this vnfr should be deployed
759 :param vnfr_update: dictionary filled by this method with changes to be done at database vnfr
760 :param vnfr_update_rollback: dictionary filled by this method with original content of vnfr in case a rollback
761 of the changed vnfr is needed
762
763 :return: List of KDU interfaces that are connected to an existing VIM network. Each item contains:
764 "vim-network-name": used at VIM
765 "name": interface name
766 "vnf-vld-id": internal VNFD vld where this interface is connected, or
767 "ns-vld-id": NSD vld where this interface is connected.
768 NOTE: One, and only one between 'vnf-vld-id' and 'ns-vld-id' contains a value. The other will be None
769 """
770
771 ifaces_forcing_vim_network = []
tiernoc67b0e92019-11-05 12:45:29 +0000772 if not vnfr.get("kdur"):
773 return ifaces_forcing_vim_network
tierno9cb7d672019-10-30 12:13:48 +0000774
tiernoc67b0e92019-11-05 12:45:29 +0000775 kdu_filter = self._get_project_filter(session)
776 kdu_filter["vim_account"] = vim_account
777 # TODO kdu_filter["_admin.operationalState"] = "ENABLED"
778 available_k8sclusters = self.db.get_list("k8sclusters", kdu_filter)
779
780 k8s_requirements = {} # just for logging
781 for k8scluster in available_k8sclusters:
782 if not vnfr.get("k8s-cluster"):
tierno9cb7d672019-10-30 12:13:48 +0000783 break
tiernoc67b0e92019-11-05 12:45:29 +0000784 # restrict by cni
785 if vnfr["k8s-cluster"].get("cni"):
786 k8s_requirements["cni"] = vnfr["k8s-cluster"]["cni"]
787 if not set(vnfr["k8s-cluster"]["cni"]).intersection(k8scluster.get("cni", ())):
788 continue
789 # restrict by version
790 if vnfr["k8s-cluster"].get("version"):
791 k8s_requirements["version"] = vnfr["k8s-cluster"]["version"]
792 if k8scluster.get("k8s_version") not in vnfr["k8s-cluster"]["version"]:
793 continue
794 # restrict by number of networks
795 if vnfr["k8s-cluster"].get("nets"):
796 k8s_requirements["networks"] = len(vnfr["k8s-cluster"]["nets"])
797 if not k8scluster.get("nets") or len(k8scluster["nets"]) < len(vnfr["k8s-cluster"]["nets"]):
798 continue
799 break
800 else:
801 raise EngineException("No k8scluster with requirements='{}' at vim_account={} found for member_vnf_index={}"
802 .format(k8s_requirements, vim_account, vnfr["member-vnf-index-ref"]))
tierno9cb7d672019-10-30 12:13:48 +0000803
tiernoc67b0e92019-11-05 12:45:29 +0000804 for kdur_index, kdur in enumerate(get_iterable(vnfr.get("kdur"))):
tierno9cb7d672019-10-30 12:13:48 +0000805 # step 3. Fill vnfr info by filling kdur
806 kdu_text = "kdur.{}.".format(kdur_index)
807 vnfr_update_rollback[kdu_text + "k8s-cluster.id"] = None
808 vnfr_update[kdu_text + "k8s-cluster.id"] = k8scluster["_id"]
809
tiernoc67b0e92019-11-05 12:45:29 +0000810 # step 4. Check VIM networks that forces the selected k8s_cluster
811 if vnfr.get("k8s-cluster") and vnfr["k8s-cluster"].get("nets"):
812 k8scluster_net_list = list(k8scluster.get("nets").keys())
813 for net_index, kdur_net in enumerate(vnfr["k8s-cluster"]["nets"]):
814 # get a network from k8s_cluster nets. If name matches use this, if not use other
815 if kdur_net["id"] in k8scluster_net_list: # name matches
816 vim_net = k8scluster["nets"][kdur_net["id"]]
817 k8scluster_net_list.remove(kdur_net["id"])
818 else:
819 vim_net = k8scluster["nets"][k8scluster_net_list[0]]
820 k8scluster_net_list.pop(0)
821 vnfr_update_rollback["k8s-cluster.nets.{}.vim_net".format(net_index)] = None
822 vnfr_update["k8s-cluster.nets.{}.vim_net".format(net_index)] = vim_net
823 if vim_net and (kdur_net.get("vnf-vld-id") or kdur_net.get("ns-vld-id")):
824 ifaces_forcing_vim_network.append({
825 "name": kdur_net.get("vnf-vld-id") or kdur_net.get("ns-vld-id"),
826 "vnf-vld-id": kdur_net.get("vnf-vld-id"),
827 "ns-vld-id": kdur_net.get("ns-vld-id"),
828 "vim-network-name": vim_net, # TODO can it be vim-network-id ???
829 })
830 # TODO check that this forcing is not incompatible with other forcing
tierno9cb7d672019-10-30 12:13:48 +0000831 return ifaces_forcing_vim_network
832
tiernocc103432018-10-19 14:10:35 +0200833 def _update_vnfrs(self, session, rollback, nsr, indata):
tiernocc103432018-10-19 14:10:35 +0200834 # get vnfr
835 nsr_id = nsr["_id"]
836 vnfrs = self.db.get_list("vnfrs", {"nsr-id-ref": nsr_id})
837
838 for vnfr in vnfrs:
839 vnfr_update = {}
840 vnfr_update_rollback = {}
841 member_vnf_index = vnfr["member-vnf-index-ref"]
842 # update vim-account-id
843
844 vim_account = indata["vimAccountId"]
845 # check instantiate parameters
846 for vnf_inst_params in get_iterable(indata.get("vnf")):
847 if vnf_inst_params["member-vnf-index"] != member_vnf_index:
848 continue
849 if vnf_inst_params.get("vimAccountId"):
850 vim_account = vnf_inst_params.get("vimAccountId")
851
852 vnfr_update["vim-account-id"] = vim_account
853 vnfr_update_rollback["vim-account-id"] = vnfr.get("vim-account-id")
854
855 # get pdu
tierno36ec8602018-11-02 17:27:11 +0100856 ifaces_forcing_vim_network = self._look_for_pdu(session, rollback, vnfr, vim_account, vnfr_update,
857 vnfr_update_rollback)
tiernocc103432018-10-19 14:10:35 +0200858
tierno9cb7d672019-10-30 12:13:48 +0000859 # get kdus
860 ifaces_forcing_vim_network += self._look_for_k8scluster(session, rollback, vnfr, vim_account, vnfr_update,
861 vnfr_update_rollback)
862 # update database vnfr
tierno36ec8602018-11-02 17:27:11 +0100863 self.db.set_one("vnfrs", {"_id": vnfr["_id"]}, vnfr_update)
864 rollback.append({"topic": "vnfrs", "_id": vnfr["_id"], "operation": "set", "content": vnfr_update_rollback})
865
866 # Update indada in case pdu forces to use a concrete vim-network-name
867 # TODO check if user has already insert a vim-network-name and raises an error
868 if not ifaces_forcing_vim_network:
869 continue
870 for iface_info in ifaces_forcing_vim_network:
871 if iface_info.get("ns-vld-id"):
872 if "vld" not in indata:
873 indata["vld"] = []
874 indata["vld"].append({key: iface_info[key] for key in
875 ("name", "vim-network-name", "vim-network-id") if iface_info.get(key)})
876
877 elif iface_info.get("vnf-vld-id"):
878 if "vnf" not in indata:
879 indata["vnf"] = []
880 indata["vnf"].append({
881 "member-vnf-index": member_vnf_index,
882 "internal-vld": [{key: iface_info[key] for key in
883 ("name", "vim-network-name", "vim-network-id") if iface_info.get(key)}]
884 })
885
886 @staticmethod
887 def _create_nslcmop(nsr_id, operation, params):
888 """
889 Creates a ns-lcm-opp content to be stored at database.
890 :param nsr_id: internal id of the instance
891 :param operation: instantiate, terminate, scale, action, ...
892 :param params: user parameters for the operation
893 :return: dictionary following SOL005 format
894 """
tiernob24258a2018-10-04 18:39:49 +0200895 now = time()
896 _id = str(uuid4())
897 nslcmop = {
898 "id": _id,
899 "_id": _id,
900 "operationState": "PROCESSING", # COMPLETED,PARTIALLY_COMPLETED,FAILED_TEMP,FAILED,ROLLING_BACK,ROLLED_BACK
901 "statusEnteredTime": now,
tierno36ec8602018-11-02 17:27:11 +0100902 "nsInstanceId": nsr_id,
tiernob24258a2018-10-04 18:39:49 +0200903 "lcmOperationType": operation,
904 "startTime": now,
905 "isAutomaticInvocation": False,
906 "operationParams": params,
907 "isCancelPending": False,
908 "links": {
909 "self": "/osm/nslcm/v1/ns_lcm_op_occs/" + _id,
tierno36ec8602018-11-02 17:27:11 +0100910 "nsInstance": "/osm/nslcm/v1/ns_instances/" + nsr_id,
tiernob24258a2018-10-04 18:39:49 +0200911 }
912 }
913 return nslcmop
914
tierno65ca36d2019-02-12 19:27:52 +0100915 def new(self, rollback, session, indata=None, kwargs=None, headers=None, slice_object=False):
tiernob24258a2018-10-04 18:39:49 +0200916 """
917 Performs a new operation over a ns
918 :param rollback: list to append created items at database in case a rollback must to be done
tierno65ca36d2019-02-12 19:27:52 +0100919 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
tiernob24258a2018-10-04 18:39:49 +0200920 :param indata: descriptor with the parameters of the operation. It must contains among others
921 nsInstanceId: _id of the nsr to perform the operation
922 operation: it can be: instantiate, terminate, action, TODO: update, heal
923 :param kwargs: used to override the indata descriptor
924 :param headers: http request headers
tiernob24258a2018-10-04 18:39:49 +0200925 :return: id of the nslcmops
926 """
Felipe Vicens90fbc9c2019-06-06 01:03:00 +0200927 def check_if_nsr_is_not_slice_member(session, nsr_id):
928 nsis = None
929 db_filter = self._get_project_filter(session)
930 db_filter["_admin.nsrs-detailed-list.ANYINDEX.nsrId"] = nsr_id
931 nsis = self.db.get_one("nsis", db_filter, fail_on_empty=False, fail_on_more=False)
932 if nsis:
933 raise EngineException("The NS instance {} cannot be terminate because is used by the slice {}".format(
934 nsr_id, nsis["_id"]), http_code=HTTPStatus.CONFLICT)
935
tiernob24258a2018-10-04 18:39:49 +0200936 try:
937 # Override descriptor with query string kwargs
938 self._update_input_with_kwargs(indata, kwargs)
939 operation = indata["lcmOperationType"]
940 nsInstanceId = indata["nsInstanceId"]
941
942 validate_input(indata, self.operation_schema[operation])
943 # get ns from nsr_id
tierno65ca36d2019-02-12 19:27:52 +0100944 _filter = BaseTopic._get_project_filter(session)
tiernob24258a2018-10-04 18:39:49 +0200945 _filter["_id"] = nsInstanceId
946 nsr = self.db.get_one("nsrs", _filter)
947
948 # initial checking
Felipe Vicens90fbc9c2019-06-06 01:03:00 +0200949 if operation == "terminate" and slice_object is False:
950 check_if_nsr_is_not_slice_member(session, nsr["_id"])
tiernob24258a2018-10-04 18:39:49 +0200951 if not nsr["_admin"].get("nsState") or nsr["_admin"]["nsState"] == "NOT_INSTANTIATED":
952 if operation == "terminate" and indata.get("autoremove"):
953 # NSR must be deleted
tierno586ae812019-10-17 13:56:53 +0000954 return None, None # a none in this case is used to indicate not instantiated. It can be removed
tiernob24258a2018-10-04 18:39:49 +0200955 if operation != "instantiate":
956 raise EngineException("ns_instance '{}' cannot be '{}' because it is not instantiated".format(
957 nsInstanceId, operation), HTTPStatus.CONFLICT)
958 else:
tierno65ca36d2019-02-12 19:27:52 +0100959 if operation == "instantiate" and not session["force"]:
tiernob24258a2018-10-04 18:39:49 +0200960 raise EngineException("ns_instance '{}' cannot be '{}' because it is already instantiated".format(
961 nsInstanceId, operation), HTTPStatus.CONFLICT)
962 self._check_ns_operation(session, nsr, operation, indata)
tierno36ec8602018-11-02 17:27:11 +0100963
tiernocc103432018-10-19 14:10:35 +0200964 if operation == "instantiate":
965 self._update_vnfrs(session, rollback, nsr, indata)
tierno36ec8602018-11-02 17:27:11 +0100966
967 nslcmop_desc = self._create_nslcmop(nsInstanceId, operation, indata)
tierno1bfe4e22019-09-02 16:03:25 +0000968 _id = nslcmop_desc["_id"]
tierno65ca36d2019-02-12 19:27:52 +0100969 self.format_on_new(nslcmop_desc, session["project_id"], make_public=session["public"])
tierno1bfe4e22019-09-02 16:03:25 +0000970 self.db.create("nslcmops", nslcmop_desc)
tiernob24258a2018-10-04 18:39:49 +0200971 rollback.append({"topic": "nslcmops", "_id": _id})
Felipe Vicens07f31722018-10-29 15:16:44 +0100972 if not slice_object:
973 self.msg.write("ns", operation, nslcmop_desc)
tiernobdebce92019-07-01 15:36:49 +0000974 return _id, None
975 except ValidationError as e: # TODO remove try Except, it is captured at nbi.py
tiernob24258a2018-10-04 18:39:49 +0200976 raise EngineException(e, HTTPStatus.UNPROCESSABLE_ENTITY)
977 # except DbException as e:
978 # raise EngineException("Cannot get ns_instance '{}': {}".format(e), HTTPStatus.NOT_FOUND)
979
tierno65ca36d2019-02-12 19:27:52 +0100980 def delete(self, session, _id, dry_run=False):
tiernob24258a2018-10-04 18:39:49 +0200981 raise EngineException("Method delete called directly", HTTPStatus.INTERNAL_SERVER_ERROR)
982
tierno65ca36d2019-02-12 19:27:52 +0100983 def edit(self, session, _id, indata=None, kwargs=None, content=None):
tiernob24258a2018-10-04 18:39:49 +0200984 raise EngineException("Method edit called directly", HTTPStatus.INTERNAL_SERVER_ERROR)
Felipe Vicensb57758d2018-10-16 16:00:20 +0200985
986
987class NsiTopic(BaseTopic):
988 topic = "nsis"
989 topic_msg = "nsi"
990
delacruzramo32bab472019-09-13 12:24:22 +0200991 def __init__(self, db, fs, msg, auth):
992 BaseTopic.__init__(self, db, fs, msg, auth)
993 self.nsrTopic = NsrTopic(db, fs, msg, auth)
Felipe Vicensb57758d2018-10-16 16:00:20 +0200994
Felipe Vicensc37b3842019-01-12 12:24:42 +0100995 @staticmethod
996 def _format_ns_request(ns_request):
997 formated_request = copy(ns_request)
998 # TODO: Add request params
999 return formated_request
1000
1001 @staticmethod
tiernofd160572019-01-21 10:41:37 +00001002 def _format_addional_params(slice_request):
Felipe Vicensc37b3842019-01-12 12:24:42 +01001003 """
1004 Get and format user additional params for NS or VNF
tiernofd160572019-01-21 10:41:37 +00001005 :param slice_request: User instantiation additional parameters
1006 :return: a formatted copy of additional params or None if not supplied
Felipe Vicensc37b3842019-01-12 12:24:42 +01001007 """
tiernofd160572019-01-21 10:41:37 +00001008 additional_params = copy(slice_request.get("additionalParamsForNsi"))
1009 if additional_params:
1010 for k, v in additional_params.items():
1011 if not isinstance(k, str):
1012 raise EngineException("Invalid param at additionalParamsForNsi:{}. Only string keys are allowed".
1013 format(k))
1014 if "." in k or "$" in k:
1015 raise EngineException("Invalid param at additionalParamsForNsi:{}. Keys must not contain dots or $".
1016 format(k))
1017 if isinstance(v, (dict, tuple, list)):
1018 additional_params[k] = "!!yaml " + safe_dump(v)
Felipe Vicensc37b3842019-01-12 12:24:42 +01001019 return additional_params
1020
Felipe Vicensb57758d2018-10-16 16:00:20 +02001021 def _check_descriptor_dependencies(self, session, descriptor):
1022 """
1023 Check that the dependent descriptors exist on a new descriptor or edition
tierno65ca36d2019-02-12 19:27:52 +01001024 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
Felipe Vicensb57758d2018-10-16 16:00:20 +02001025 :param descriptor: descriptor to be inserted or edit
1026 :return: None or raises exception
1027 """
Felipe Vicens07f31722018-10-29 15:16:44 +01001028 if not descriptor.get("nst-ref"):
Felipe Vicensb57758d2018-10-16 16:00:20 +02001029 return
Felipe Vicens07f31722018-10-29 15:16:44 +01001030 nstd_id = descriptor["nst-ref"]
Felipe Vicensb57758d2018-10-16 16:00:20 +02001031 if not self.get_item_list(session, "nsts", {"id": nstd_id}):
Felipe Vicens07f31722018-10-29 15:16:44 +01001032 raise EngineException("Descriptor error at nst-ref='{}' references a non exist nstd".format(nstd_id),
Felipe Vicensb57758d2018-10-16 16:00:20 +02001033 http_code=HTTPStatus.CONFLICT)
1034
tiernob4844ab2019-05-23 08:42:12 +00001035 def check_conflict_on_del(self, session, _id, db_content):
1036 """
1037 Check that NSI is not instantiated
1038 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
1039 :param _id: nsi internal id
1040 :param db_content: The database content of the _id
1041 :return: None or raises EngineException with the conflict
1042 """
tierno65ca36d2019-02-12 19:27:52 +01001043 if session["force"]:
Felipe Vicensb57758d2018-10-16 16:00:20 +02001044 return
tiernob4844ab2019-05-23 08:42:12 +00001045 nsi = db_content
Felipe Vicensb57758d2018-10-16 16:00:20 +02001046 if nsi["_admin"].get("nsiState") == "INSTANTIATED":
1047 raise EngineException("nsi '{}' cannot be deleted because it is in 'INSTANTIATED' state. "
1048 "Launch 'terminate' operation first; or force deletion".format(_id),
1049 http_code=HTTPStatus.CONFLICT)
1050
tiernob4844ab2019-05-23 08:42:12 +00001051 def delete_extra(self, session, _id, db_content):
Felipe Vicensb57758d2018-10-16 16:00:20 +02001052 """
tiernob4844ab2019-05-23 08:42:12 +00001053 Deletes associated nsilcmops from database. Deletes associated filesystem.
1054 Set usageState of nst
tierno65ca36d2019-02-12 19:27:52 +01001055 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
Felipe Vicensb57758d2018-10-16 16:00:20 +02001056 :param _id: server internal id
tiernob4844ab2019-05-23 08:42:12 +00001057 :param db_content: The database content of the descriptor
1058 :return: None if ok or raises EngineException with the problem
Felipe Vicensb57758d2018-10-16 16:00:20 +02001059 """
Felipe Vicens07f31722018-10-29 15:16:44 +01001060
Felipe Vicens09e65422019-01-22 15:06:46 +01001061 # Deleting the nsrs belonging to nsir
tiernob4844ab2019-05-23 08:42:12 +00001062 nsir = db_content
Felipe Vicens09e65422019-01-22 15:06:46 +01001063 for nsrs_detailed_item in nsir["_admin"]["nsrs-detailed-list"]:
1064 nsr_id = nsrs_detailed_item["nsrId"]
1065 if nsrs_detailed_item.get("shared"):
1066 _filter = {"_admin.nsrs-detailed-list.ANYINDEX.shared": True,
1067 "_admin.nsrs-detailed-list.ANYINDEX.nsrId": nsr_id,
1068 "_id.ne": nsir["_id"]}
1069 nsi = self.db.get_one("nsis", _filter, fail_on_empty=False, fail_on_more=False)
1070 if nsi: # last one using nsr
1071 continue
1072 try:
tierno65ca36d2019-02-12 19:27:52 +01001073 self.nsrTopic.delete(session, nsr_id, dry_run=False)
Felipe Vicens09e65422019-01-22 15:06:46 +01001074 except (DbException, EngineException) as e:
1075 if e.http_code == HTTPStatus.NOT_FOUND:
1076 pass
1077 else:
1078 raise
Felipe Vicens07f31722018-10-29 15:16:44 +01001079
tiernob4844ab2019-05-23 08:42:12 +00001080 # delete related nsilcmops database entries
1081 self.db.del_list("nsilcmops", {"netsliceInstanceId": _id})
Felipe Vicens07f31722018-10-29 15:16:44 +01001082
tiernob4844ab2019-05-23 08:42:12 +00001083 # Check and set used NST usage state
Felipe Vicens09e65422019-01-22 15:06:46 +01001084 nsir_admin = nsir.get("_admin")
tiernob4844ab2019-05-23 08:42:12 +00001085 if nsir_admin and nsir_admin.get("nst-id"):
1086 # check if used by another NSI
1087 nsis_list = self.db.get_one("nsis", {"nst-id": nsir_admin["nst-id"]},
1088 fail_on_empty=False, fail_on_more=False)
1089 if not nsis_list:
1090 self.db.set_one("nsts", {"_id": nsir_admin["nst-id"]}, {"_admin.usageState": "NOT_IN_USE"})
1091
1092 # def delete(self, session, _id, dry_run=False):
1093 # """
1094 # Delete item by its internal _id
1095 # :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
1096 # :param _id: server internal id
1097 # :param dry_run: make checking but do not delete
1098 # :return: dictionary with deleted item _id. It raises EngineException on error: not found, conflict, ...
1099 # """
1100 # # TODO add admin to filter, validate rights
1101 # BaseTopic.delete(self, session, _id, dry_run=True)
1102 # if dry_run:
1103 # return
1104 #
1105 # # Deleting the nsrs belonging to nsir
1106 # nsir = self.db.get_one("nsis", {"_id": _id})
1107 # for nsrs_detailed_item in nsir["_admin"]["nsrs-detailed-list"]:
1108 # nsr_id = nsrs_detailed_item["nsrId"]
1109 # if nsrs_detailed_item.get("shared"):
1110 # _filter = {"_admin.nsrs-detailed-list.ANYINDEX.shared": True,
1111 # "_admin.nsrs-detailed-list.ANYINDEX.nsrId": nsr_id,
1112 # "_id.ne": nsir["_id"]}
1113 # nsi = self.db.get_one("nsis", _filter, fail_on_empty=False, fail_on_more=False)
1114 # if nsi: # last one using nsr
1115 # continue
1116 # try:
1117 # self.nsrTopic.delete(session, nsr_id, dry_run=False)
1118 # except (DbException, EngineException) as e:
1119 # if e.http_code == HTTPStatus.NOT_FOUND:
1120 # pass
1121 # else:
1122 # raise
1123 # # deletes NetSlice instance object
1124 # v = self.db.del_one("nsis", {"_id": _id})
1125 #
1126 # # makes a temporal list of nsilcmops objects related to the _id given and deletes them from db
1127 # _filter = {"netsliceInstanceId": _id}
1128 # self.db.del_list("nsilcmops", _filter)
1129 #
1130 # # Search if nst is being used by other nsi
1131 # nsir_admin = nsir.get("_admin")
1132 # if nsir_admin:
1133 # if nsir_admin.get("nst-id"):
1134 # nsis_list = self.db.get_one("nsis", {"nst-id": nsir_admin["nst-id"]},
1135 # fail_on_empty=False, fail_on_more=False)
1136 # if not nsis_list:
1137 # self.db.set_one("nsts", {"_id": nsir_admin["nst-id"]}, {"_admin.usageState": "NOT_IN_USE"})
1138 # return v
Felipe Vicensb57758d2018-10-16 16:00:20 +02001139
tierno65ca36d2019-02-12 19:27:52 +01001140 def new(self, rollback, session, indata=None, kwargs=None, headers=None):
Felipe Vicensb57758d2018-10-16 16:00:20 +02001141 """
Felipe Vicens07f31722018-10-29 15:16:44 +01001142 Creates a new netslice instance record into database. It also creates needed nsrs and vnfrs
Felipe Vicensb57758d2018-10-16 16:00:20 +02001143 :param rollback: list to append the created items at database in case a rollback must be done
tierno65ca36d2019-02-12 19:27:52 +01001144 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
Felipe Vicensb57758d2018-10-16 16:00:20 +02001145 :param indata: params to be used for the nsir
1146 :param kwargs: used to override the indata descriptor
1147 :param headers: http request headers
Felipe Vicensb57758d2018-10-16 16:00:20 +02001148 :return: the _id of nsi descriptor created at database
1149 """
1150
1151 try:
delacruzramo32bab472019-09-13 12:24:22 +02001152 step = "checking quotas"
1153 self.check_quota(session)
1154
tierno99d4b172019-07-02 09:28:40 +00001155 step = ""
Felipe Vicensb57758d2018-10-16 16:00:20 +02001156 slice_request = self._remove_envelop(indata)
1157 # Override descriptor with query string kwargs
1158 self._update_input_with_kwargs(slice_request, kwargs)
tierno65ca36d2019-02-12 19:27:52 +01001159 self._validate_input_new(slice_request, session["force"])
Felipe Vicensb57758d2018-10-16 16:00:20 +02001160
Felipe Vicensb57758d2018-10-16 16:00:20 +02001161 # look for nstd
tierno9e5eea32018-11-29 09:42:09 +00001162 step = "getting nstd id='{}' from database".format(slice_request.get("nstId"))
tiernob4844ab2019-05-23 08:42:12 +00001163 _filter = self._get_project_filter(session)
1164 _filter["_id"] = slice_request["nstId"]
Felipe Vicensb57758d2018-10-16 16:00:20 +02001165 nstd = self.db.get_one("nsts", _filter)
tiernob4844ab2019-05-23 08:42:12 +00001166 del _filter["_id"]
1167
Felipe Vicens07f31722018-10-29 15:16:44 +01001168 nstd.pop("_admin", None)
Felipe Vicens09e65422019-01-22 15:06:46 +01001169 nstd_id = nstd.pop("_id", None)
Felipe Vicensb57758d2018-10-16 16:00:20 +02001170 nsi_id = str(uuid4())
Felipe Vicensb57758d2018-10-16 16:00:20 +02001171 step = "filling nsi_descriptor with input data"
Felipe Vicens07f31722018-10-29 15:16:44 +01001172
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001173 # Creating the NSIR
Felipe Vicensb57758d2018-10-16 16:00:20 +02001174 nsi_descriptor = {
1175 "id": nsi_id,
garciadeblasc54d4202018-11-29 23:41:37 +01001176 "name": slice_request["nsiName"],
1177 "description": slice_request.get("nsiDescription", ""),
1178 "datacenter": slice_request["vimAccountId"],
Felipe Vicensb57758d2018-10-16 16:00:20 +02001179 "nst-ref": nstd["id"],
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001180 "instantiation_parameters": slice_request,
Felipe Vicensb57758d2018-10-16 16:00:20 +02001181 "network-slice-template": nstd,
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001182 "nsr-ref-list": [],
1183 "vlr-list": [],
Felipe Vicensb57758d2018-10-16 16:00:20 +02001184 "_id": nsi_id,
tiernofd160572019-01-21 10:41:37 +00001185 "additionalParamsForNsi": self._format_addional_params(slice_request)
Felipe Vicensb57758d2018-10-16 16:00:20 +02001186 }
Felipe Vicensb57758d2018-10-16 16:00:20 +02001187
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001188 step = "creating nsi at database"
tierno65ca36d2019-02-12 19:27:52 +01001189 self.format_on_new(nsi_descriptor, session["project_id"], make_public=session["public"])
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001190 nsi_descriptor["_admin"]["nsiState"] = "NOT_INSTANTIATED"
1191 nsi_descriptor["_admin"]["netslice-subnet"] = None
Felipe Vicens09e65422019-01-22 15:06:46 +01001192 nsi_descriptor["_admin"]["deployed"] = {}
1193 nsi_descriptor["_admin"]["deployed"]["RO"] = []
1194 nsi_descriptor["_admin"]["nst-id"] = nstd_id
1195
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001196 # Creating netslice-vld for the RO.
1197 step = "creating netslice-vld at database"
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001198
1199 # Building the vlds list to be deployed
1200 # From netslice descriptors, creating the initial list
Felipe Vicens09e65422019-01-22 15:06:46 +01001201 nsi_vlds = []
1202
1203 for netslice_vlds in get_iterable(nstd.get("netslice-vld")):
1204 # Getting template Instantiation parameters from NST
1205 nsi_vld = deepcopy(netslice_vlds)
1206 nsi_vld["shared-nsrs-list"] = []
1207 nsi_vld["vimAccountId"] = slice_request["vimAccountId"]
1208 nsi_vlds.append(nsi_vld)
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001209
1210 nsi_descriptor["_admin"]["netslice-vld"] = nsi_vlds
Felipe Vicens07f31722018-10-29 15:16:44 +01001211 # Creating netslice-subnet_record.
Felipe Vicensb57758d2018-10-16 16:00:20 +02001212 needed_nsds = {}
Felipe Vicens07f31722018-10-29 15:16:44 +01001213 services = []
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001214
Felipe Vicens09e65422019-01-22 15:06:46 +01001215 # Updating the nstd with the nsd["_id"] associated to the nss -> services list
Felipe Vicensb57758d2018-10-16 16:00:20 +02001216 for member_ns in nstd["netslice-subnet"]:
1217 nsd_id = member_ns["nsd-ref"]
1218 step = "getting nstd id='{}' constituent-nsd='{}' from database".format(
1219 member_ns["nsd-ref"], member_ns["id"])
1220 if nsd_id not in needed_nsds:
1221 # Obtain nsd
tiernob4844ab2019-05-23 08:42:12 +00001222 _filter["id"] = nsd_id
1223 nsd = self.db.get_one("nsds", _filter, fail_on_empty=True, fail_on_more=True)
1224 del _filter["id"]
Felipe Vicensb57758d2018-10-16 16:00:20 +02001225 nsd.pop("_admin")
1226 needed_nsds[nsd_id] = nsd
1227 else:
1228 nsd = needed_nsds[nsd_id]
Felipe Vicens09e65422019-01-22 15:06:46 +01001229 member_ns["_id"] = needed_nsds[nsd_id].get("_id")
1230 services.append(member_ns)
Felipe Vicens07f31722018-10-29 15:16:44 +01001231
Felipe Vicensb57758d2018-10-16 16:00:20 +02001232 step = "filling nsir nsd-id='{}' constituent-nsd='{}' from database".format(
1233 member_ns["nsd-ref"], member_ns["id"])
Felipe Vicensb57758d2018-10-16 16:00:20 +02001234
Felipe Vicens07f31722018-10-29 15:16:44 +01001235 # creates Network Services records (NSRs)
1236 step = "creating nsrs at database using NsrTopic.new()"
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001237 ns_params = slice_request.get("netslice-subnet")
Felipe Vicens07f31722018-10-29 15:16:44 +01001238 nsrs_list = []
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001239 nsi_netslice_subnet = []
Felipe Vicens07f31722018-10-29 15:16:44 +01001240 for service in services:
Felipe Vicens09e65422019-01-22 15:06:46 +01001241 # Check if the netslice-subnet is shared and if it is share if the nss exists
1242 _id_nsr = None
Felipe Vicens07f31722018-10-29 15:16:44 +01001243 indata_ns = {}
Felipe Vicens09e65422019-01-22 15:06:46 +01001244 # Is the nss shared and instantiated?
tiernob4844ab2019-05-23 08:42:12 +00001245 _filter["_admin.nsrs-detailed-list.ANYINDEX.shared"] = True
1246 _filter["_admin.nsrs-detailed-list.ANYINDEX.nsd-id"] = service["nsd-ref"]
Felipe Vicens08ddb142019-08-09 15:52:40 +02001247 _filter["_admin.nsrs-detailed-list.ANYINDEX.nss-id"] = service["id"]
Felipe Vicens09e65422019-01-22 15:06:46 +01001248 nsi = self.db.get_one("nsis", _filter, fail_on_empty=False, fail_on_more=False)
Felipe Vicens09e65422019-01-22 15:06:46 +01001249 if nsi and service.get("is-shared-nss"):
1250 nsrs_detailed_list = nsi["_admin"]["nsrs-detailed-list"]
1251 for nsrs_detailed_item in nsrs_detailed_list:
1252 if nsrs_detailed_item["nsd-id"] == service["nsd-ref"]:
Felipe Vicens08ddb142019-08-09 15:52:40 +02001253 if nsrs_detailed_item["nss-id"] == service["id"]:
1254 _id_nsr = nsrs_detailed_item["nsrId"]
1255 break
Felipe Vicens09e65422019-01-22 15:06:46 +01001256 for netslice_subnet in nsi["_admin"]["netslice-subnet"]:
1257 if netslice_subnet["nss-id"] == service["id"]:
1258 indata_ns = netslice_subnet
1259 break
1260 else:
1261 indata_ns = {}
1262 if service.get("instantiation-parameters"):
1263 indata_ns = deepcopy(service["instantiation-parameters"])
1264 # del service["instantiation-parameters"]
1265
1266 indata_ns["nsdId"] = service["_id"]
1267 indata_ns["nsName"] = slice_request.get("nsiName") + "." + service["id"]
1268 indata_ns["vimAccountId"] = slice_request.get("vimAccountId")
1269 indata_ns["nsDescription"] = service["description"]
tierno99d4b172019-07-02 09:28:40 +00001270 if slice_request.get("ssh_keys"):
1271 indata_ns["ssh_keys"] = slice_request.get("ssh_keys")
Felipe Vicensc37b3842019-01-12 12:24:42 +01001272
Felipe Vicens09e65422019-01-22 15:06:46 +01001273 if ns_params:
1274 for ns_param in ns_params:
1275 if ns_param.get("id") == service["id"]:
1276 copy_ns_param = deepcopy(ns_param)
1277 del copy_ns_param["id"]
1278 indata_ns.update(copy_ns_param)
1279 break
1280
1281 # Creates Nsr objects
tiernobdebce92019-07-01 15:36:49 +00001282 _id_nsr, _ = self.nsrTopic.new(rollback, session, indata_ns, kwargs, headers)
Felipe Vicens09e65422019-01-22 15:06:46 +01001283 nsrs_item = {"nsrId": _id_nsr, "shared": service.get("is-shared-nss"), "nsd-id": service["nsd-ref"],
Felipe Vicens08ddb142019-08-09 15:52:40 +02001284 "nss-id": service["id"], "nslcmop_instantiate": None}
Felipe Vicens09e65422019-01-22 15:06:46 +01001285 indata_ns["nss-id"] = service["id"]
Felipe Vicens07f31722018-10-29 15:16:44 +01001286 nsrs_list.append(nsrs_item)
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001287 nsi_netslice_subnet.append(indata_ns)
1288 nsr_ref = {"nsr-ref": _id_nsr}
1289 nsi_descriptor["nsr-ref-list"].append(nsr_ref)
Felipe Vicens07f31722018-10-29 15:16:44 +01001290
1291 # Adding the nsrs list to the nsi
1292 nsi_descriptor["_admin"]["nsrs-detailed-list"] = nsrs_list
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001293 nsi_descriptor["_admin"]["netslice-subnet"] = nsi_netslice_subnet
Felipe Vicens09e65422019-01-22 15:06:46 +01001294 self.db.set_one("nsts", {"_id": slice_request["nstId"]}, {"_admin.usageState": "IN_USE"})
1295
Felipe Vicens07f31722018-10-29 15:16:44 +01001296 # Creating the entry in the database
Felipe Vicensb57758d2018-10-16 16:00:20 +02001297 self.db.create("nsis", nsi_descriptor)
1298 rollback.append({"topic": "nsis", "_id": nsi_id})
tiernobdebce92019-07-01 15:36:49 +00001299 return nsi_id, None
1300 except Exception as e: # TODO remove try Except, it is captured at nbi.py
Felipe Vicensb57758d2018-10-16 16:00:20 +02001301 self.logger.exception("Exception {} at NsiTopic.new()".format(e), exc_info=True)
1302 raise EngineException("Error {}: {}".format(step, e))
1303 except ValidationError as e:
1304 raise EngineException(e, HTTPStatus.UNPROCESSABLE_ENTITY)
1305
tierno65ca36d2019-02-12 19:27:52 +01001306 def edit(self, session, _id, indata=None, kwargs=None, content=None):
Felipe Vicensb57758d2018-10-16 16:00:20 +02001307 raise EngineException("Method edit called directly", HTTPStatus.INTERNAL_SERVER_ERROR)
Felipe Vicens07f31722018-10-29 15:16:44 +01001308
1309
1310class NsiLcmOpTopic(BaseTopic):
1311 topic = "nsilcmops"
1312 topic_msg = "nsi"
1313 operation_schema = { # mapping between operation and jsonschema to validate
1314 "instantiate": nsi_instantiate,
1315 "terminate": None
1316 }
Felipe Vicens09e65422019-01-22 15:06:46 +01001317
delacruzramo32bab472019-09-13 12:24:22 +02001318 def __init__(self, db, fs, msg, auth):
1319 BaseTopic.__init__(self, db, fs, msg, auth)
1320 self.nsi_NsLcmOpTopic = NsLcmOpTopic(self.db, self.fs, self.msg, self.auth)
Felipe Vicens07f31722018-10-29 15:16:44 +01001321
1322 def _check_nsi_operation(self, session, nsir, operation, indata):
1323 """
1324 Check that user has enter right parameters for the operation
tierno65ca36d2019-02-12 19:27:52 +01001325 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
Felipe Vicens07f31722018-10-29 15:16:44 +01001326 :param operation: it can be: instantiate, terminate, action, TODO: update, heal
1327 :param indata: descriptor with the parameters of the operation
1328 :return: None
1329 """
1330 nsds = {}
1331 nstd = nsir["network-slice-template"]
1332
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001333 def check_valid_netslice_subnet_id(nstId):
Felipe Vicens07f31722018-10-29 15:16:44 +01001334 # TODO change to vnfR (??)
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001335 for netslice_subnet in nstd["netslice-subnet"]:
1336 if nstId == netslice_subnet["id"]:
1337 nsd_id = netslice_subnet["nsd-ref"]
Felipe Vicens07f31722018-10-29 15:16:44 +01001338 if nsd_id not in nsds:
1339 nsds[nsd_id] = self.db.get_one("nsds", {"id": nsd_id})
1340 return nsds[nsd_id]
1341 else:
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001342 raise EngineException("Invalid parameter nstId='{}' is not one of the "
1343 "nst:netslice-subnet".format(nstId))
Felipe Vicens07f31722018-10-29 15:16:44 +01001344 if operation == "instantiate":
1345 # check the existance of netslice-subnet items
Felipe Vicensc8bbaaa2018-12-01 04:42:40 +01001346 for in_nst in get_iterable(indata.get("netslice-subnet")):
1347 check_valid_netslice_subnet_id(in_nst["id"])
Felipe Vicens07f31722018-10-29 15:16:44 +01001348
1349 def _create_nsilcmop(self, session, netsliceInstanceId, operation, params):
1350 now = time()
1351 _id = str(uuid4())
1352 nsilcmop = {
1353 "id": _id,
1354 "_id": _id,
1355 "operationState": "PROCESSING", # COMPLETED,PARTIALLY_COMPLETED,FAILED_TEMP,FAILED,ROLLING_BACK,ROLLED_BACK
1356 "statusEnteredTime": now,
1357 "netsliceInstanceId": netsliceInstanceId,
1358 "lcmOperationType": operation,
1359 "startTime": now,
1360 "isAutomaticInvocation": False,
1361 "operationParams": params,
1362 "isCancelPending": False,
1363 "links": {
1364 "self": "/osm/nsilcm/v1/nsi_lcm_op_occs/" + _id,
Felipe Vicens126af572019-06-05 19:13:04 +02001365 "netsliceInstanceId": "/osm/nsilcm/v1/netslice_instances/" + netsliceInstanceId,
Felipe Vicens07f31722018-10-29 15:16:44 +01001366 }
1367 }
1368 return nsilcmop
1369
Felipe Vicens09e65422019-01-22 15:06:46 +01001370 def add_shared_nsr_2vld(self, nsir, nsr_item):
1371 for nst_sb_item in nsir["network-slice-template"].get("netslice-subnet"):
1372 if nst_sb_item.get("is-shared-nss"):
1373 for admin_subnet_item in nsir["_admin"].get("netslice-subnet"):
1374 if admin_subnet_item["nss-id"] == nst_sb_item["id"]:
1375 for admin_vld_item in nsir["_admin"].get("netslice-vld"):
1376 for admin_vld_nss_cp_ref_item in admin_vld_item["nss-connection-point-ref"]:
1377 if admin_subnet_item["nss-id"] == admin_vld_nss_cp_ref_item["nss-ref"]:
1378 if not nsr_item["nsrId"] in admin_vld_item["shared-nsrs-list"]:
1379 admin_vld_item["shared-nsrs-list"].append(nsr_item["nsrId"])
1380 break
1381 # self.db.set_one("nsis", {"_id": nsir["_id"]}, nsir)
1382 self.db.set_one("nsis", {"_id": nsir["_id"]}, {"_admin.netslice-vld": nsir["_admin"].get("netslice-vld")})
1383
tierno65ca36d2019-02-12 19:27:52 +01001384 def new(self, rollback, session, indata=None, kwargs=None, headers=None):
Felipe Vicens07f31722018-10-29 15:16:44 +01001385 """
1386 Performs a new operation over a ns
1387 :param rollback: list to append created items at database in case a rollback must to be done
tierno65ca36d2019-02-12 19:27:52 +01001388 :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
Felipe Vicens07f31722018-10-29 15:16:44 +01001389 :param indata: descriptor with the parameters of the operation. It must contains among others
Felipe Vicens126af572019-06-05 19:13:04 +02001390 netsliceInstanceId: _id of the nsir to perform the operation
Felipe Vicens07f31722018-10-29 15:16:44 +01001391 operation: it can be: instantiate, terminate, action, TODO: update, heal
1392 :param kwargs: used to override the indata descriptor
1393 :param headers: http request headers
Felipe Vicens07f31722018-10-29 15:16:44 +01001394 :return: id of the nslcmops
1395 """
1396 try:
1397 # Override descriptor with query string kwargs
1398 self._update_input_with_kwargs(indata, kwargs)
1399 operation = indata["lcmOperationType"]
Felipe Vicens126af572019-06-05 19:13:04 +02001400 netsliceInstanceId = indata["netsliceInstanceId"]
Felipe Vicens07f31722018-10-29 15:16:44 +01001401 validate_input(indata, self.operation_schema[operation])
1402
Felipe Vicens126af572019-06-05 19:13:04 +02001403 # get nsi from netsliceInstanceId
tiernob4844ab2019-05-23 08:42:12 +00001404 _filter = self._get_project_filter(session)
Felipe Vicens126af572019-06-05 19:13:04 +02001405 _filter["_id"] = netsliceInstanceId
Felipe Vicens07f31722018-10-29 15:16:44 +01001406 nsir = self.db.get_one("nsis", _filter)
tiernob4844ab2019-05-23 08:42:12 +00001407 del _filter["_id"]
Felipe Vicens07f31722018-10-29 15:16:44 +01001408
1409 # initial checking
1410 if not nsir["_admin"].get("nsiState") or nsir["_admin"]["nsiState"] == "NOT_INSTANTIATED":
1411 if operation == "terminate" and indata.get("autoremove"):
1412 # NSIR must be deleted
tierno586ae812019-10-17 13:56:53 +00001413 return None, None # a none in this case is used to indicate not instantiated. It can be removed
Felipe Vicens07f31722018-10-29 15:16:44 +01001414 if operation != "instantiate":
1415 raise EngineException("netslice_instance '{}' cannot be '{}' because it is not instantiated".format(
Felipe Vicens126af572019-06-05 19:13:04 +02001416 netsliceInstanceId, operation), HTTPStatus.CONFLICT)
Felipe Vicens07f31722018-10-29 15:16:44 +01001417 else:
tierno65ca36d2019-02-12 19:27:52 +01001418 if operation == "instantiate" and not session["force"]:
Felipe Vicens07f31722018-10-29 15:16:44 +01001419 raise EngineException("netslice_instance '{}' cannot be '{}' because it is already instantiated".
Felipe Vicens126af572019-06-05 19:13:04 +02001420 format(netsliceInstanceId, operation), HTTPStatus.CONFLICT)
Felipe Vicens07f31722018-10-29 15:16:44 +01001421
1422 # Creating all the NS_operation (nslcmop)
1423 # Get service list from db
1424 nsrs_list = nsir["_admin"]["nsrs-detailed-list"]
1425 nslcmops = []
Felipe Vicens09e65422019-01-22 15:06:46 +01001426 # nslcmops_item = None
1427 for index, nsr_item in enumerate(nsrs_list):
1428 nsi = None
1429 if nsr_item.get("shared"):
Felipe Vicens58e2d2f2019-05-30 13:01:20 +02001430 _filter["_admin.nsrs-detailed-list.ANYINDEX.shared"] = True
tiernob4844ab2019-05-23 08:42:12 +00001431 _filter["_admin.nsrs-detailed-list.ANYINDEX.nsrId"] = nsr_item["nsrId"]
1432 _filter["_admin.nsrs-detailed-list.ANYINDEX.nslcmop_instantiate.ne"] = None
Felipe Vicens126af572019-06-05 19:13:04 +02001433 _filter["_id.ne"] = netsliceInstanceId
Felipe Vicens09e65422019-01-22 15:06:46 +01001434 nsi = self.db.get_one("nsis", _filter, fail_on_empty=False, fail_on_more=False)
Felipe Vicens58e2d2f2019-05-30 13:01:20 +02001435 if operation == "terminate":
1436 _update = {"_admin.nsrs-detailed-list.{}.nslcmop_instantiate".format(index): None}
1437 self.db.set_one("nsis", {"_id": nsir["_id"]}, _update)
1438
Felipe Vicens09e65422019-01-22 15:06:46 +01001439 # looks the first nsi fulfilling the conditions but not being the current NSIR
1440 if nsi:
1441 nsi_admin_shared = nsi["_admin"]["nsrs-detailed-list"]
1442 for nsi_nsr_item in nsi_admin_shared:
1443 if nsi_nsr_item["nsd-id"] == nsr_item["nsd-id"] and nsi_nsr_item["shared"]:
1444 self.add_shared_nsr_2vld(nsir, nsr_item)
1445 nslcmops.append(nsi_nsr_item["nslcmop_instantiate"])
1446 _update = {"_admin.nsrs-detailed-list.{}".format(index): nsi_nsr_item}
1447 self.db.set_one("nsis", {"_id": nsir["_id"]}, _update)
1448 break
1449 # continue to not create nslcmop since nsrs is shared and nsrs was created
1450 continue
1451 else:
1452 self.add_shared_nsr_2vld(nsir, nsr_item)
1453
1454 try:
1455 service = self.db.get_one("nsrs", {"_id": nsr_item["nsrId"]})
1456 indata_ns = {}
1457 indata_ns = service["instantiate_params"]
1458 indata_ns["lcmOperationType"] = operation
1459 indata_ns["nsInstanceId"] = service["_id"]
1460 # Including netslice_id in the ns instantiate Operation
Felipe Vicens126af572019-06-05 19:13:04 +02001461 indata_ns["netsliceInstanceId"] = netsliceInstanceId
tierno99d4b172019-07-02 09:28:40 +00001462 # Creating NS_LCM_OP with the flag slice_object=True to not trigger the service instantiation
Felipe Vicens09e65422019-01-22 15:06:46 +01001463 # message via kafka bus
tiernobdebce92019-07-01 15:36:49 +00001464 nslcmop, _ = self.nsi_NsLcmOpTopic.new(rollback, session, indata_ns, kwargs, headers,
1465 slice_object=True)
Felipe Vicens09e65422019-01-22 15:06:46 +01001466 nslcmops.append(nslcmop)
1467 if operation == "terminate":
1468 nslcmop = None
1469 _update = {"_admin.nsrs-detailed-list.{}.nslcmop_instantiate".format(index): nslcmop}
1470 self.db.set_one("nsis", {"_id": nsir["_id"]}, _update)
1471 except (DbException, EngineException) as e:
1472 if e.http_code == HTTPStatus.NOT_FOUND:
1473 self.logger.info("HTTPStatus.NOT_FOUND")
1474 pass
1475 else:
1476 raise
Felipe Vicens07f31722018-10-29 15:16:44 +01001477
1478 # Creates nsilcmop
1479 indata["nslcmops_ids"] = nslcmops
1480 self._check_nsi_operation(session, nsir, operation, indata)
Felipe Vicens09e65422019-01-22 15:06:46 +01001481
Felipe Vicens126af572019-06-05 19:13:04 +02001482 nsilcmop_desc = self._create_nsilcmop(session, netsliceInstanceId, operation, indata)
tierno65ca36d2019-02-12 19:27:52 +01001483 self.format_on_new(nsilcmop_desc, session["project_id"], make_public=session["public"])
Felipe Vicens07f31722018-10-29 15:16:44 +01001484 _id = self.db.create("nsilcmops", nsilcmop_desc)
1485 rollback.append({"topic": "nsilcmops", "_id": _id})
1486 self.msg.write("nsi", operation, nsilcmop_desc)
tiernobdebce92019-07-01 15:36:49 +00001487 return _id, None
Felipe Vicens07f31722018-10-29 15:16:44 +01001488 except ValidationError as e:
1489 raise EngineException(e, HTTPStatus.UNPROCESSABLE_ENTITY)
Felipe Vicens07f31722018-10-29 15:16:44 +01001490
tierno65ca36d2019-02-12 19:27:52 +01001491 def delete(self, session, _id, dry_run=False):
Felipe Vicens07f31722018-10-29 15:16:44 +01001492 raise EngineException("Method delete called directly", HTTPStatus.INTERNAL_SERVER_ERROR)
1493
tierno65ca36d2019-02-12 19:27:52 +01001494 def edit(self, session, _id, indata=None, kwargs=None, content=None):
Felipe Vicens07f31722018-10-29 15:16:44 +01001495 raise EngineException("Method edit called directly", HTTPStatus.INTERNAL_SERVER_ERROR)