fix error ns_instances_content when not instantiated, rollback problems and pdu usage...
[osm/NBI.git] / osm_nbi / instance_topics.py
1 # -*- coding: utf-8 -*-
2
3 # 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
16 # import logging
17 from uuid import uuid4
18 from http import HTTPStatus
19 from time import time
20 from copy import copy, deepcopy
21 from validation import validate_input, ValidationError, ns_instantiate, ns_action, ns_scale, nsi_instantiate
22 from base_topic import BaseTopic, EngineException, get_iterable
23 from descriptor_topics import DescriptorTopic
24
25 __author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
26
27
28 class NsrTopic(BaseTopic):
29 topic = "nsrs"
30 topic_msg = "ns"
31
32 def __init__(self, db, fs, msg):
33 BaseTopic.__init__(self, db, fs, msg)
34
35 def _check_descriptor_dependencies(self, session, descriptor):
36 """
37 Check that the dependent descriptors exist on a new descriptor or edition
38 :param session: client session information
39 :param descriptor: descriptor to be inserted or edit
40 :return: None or raises exception
41 """
42 if not descriptor.get("nsdId"):
43 return
44 nsd_id = descriptor["nsdId"]
45 if not self.get_item_list(session, "nsds", {"id": nsd_id}):
46 raise EngineException("Descriptor error at nsdId='{}' references a non exist nsd".format(nsd_id),
47 http_code=HTTPStatus.CONFLICT)
48
49 @staticmethod
50 def format_on_new(content, project_id=None, make_public=False):
51 BaseTopic.format_on_new(content, project_id=project_id, make_public=make_public)
52 content["_admin"]["nsState"] = "NOT_INSTANTIATED"
53
54 def check_conflict_on_del(self, session, _id, force=False):
55 if force:
56 return
57 nsr = self.db.get_one("nsrs", {"_id": _id})
58 if nsr["_admin"].get("nsState") == "INSTANTIATED":
59 raise EngineException("nsr '{}' cannot be deleted because it is in 'INSTANTIATED' state. "
60 "Launch 'terminate' operation first; or force deletion".format(_id),
61 http_code=HTTPStatus.CONFLICT)
62
63 def delete(self, session, _id, force=False, dry_run=False):
64 """
65 Delete item by its internal _id
66 :param session: contains the used login username, working project, and admin rights
67 :param _id: server internal id
68 :param force: indicates if deletion must be forced in case of conflict
69 :param dry_run: make checking but do not delete
70 :return: dictionary with deleted item _id. It raises EngineException on error: not found, conflict, ...
71 """
72 # TODO add admin to filter, validate rights
73 BaseTopic.delete(self, session, _id, force, dry_run=True)
74 if dry_run:
75 return
76
77 v = self.db.del_one("nsrs", {"_id": _id})
78 self.db.del_list("nslcmops", {"nsInstanceId": _id})
79 self.db.del_list("vnfrs", {"nsr-id-ref": _id})
80 # set all used pdus as free
81 self.db.set_list("pdus", {"_admin.usage.nsr_id": _id},
82 {"_admin.usageState": "NOT_IN_USE", "_admin.usage": None})
83 self._send_msg("deleted", {"_id": _id})
84 return v
85
86 def new(self, rollback, session, indata=None, kwargs=None, headers=None, force=False, make_public=False):
87 """
88 Creates a new nsr into database. It also creates needed vnfrs
89 :param rollback: list to append the created items at database in case a rollback must be done
90 :param session: contains the used login username and working project
91 :param indata: params to be used for the nsr
92 :param kwargs: used to override the indata descriptor
93 :param headers: http request headers
94 :param force: If True avoid some dependence checks
95 :param make_public: Make the created item public to all projects
96 :return: the _id of nsr descriptor created at database
97 """
98
99 try:
100 ns_request = self._remove_envelop(indata)
101 # Override descriptor with query string kwargs
102 self._update_input_with_kwargs(ns_request, kwargs)
103 self._validate_input_new(ns_request, force)
104
105 step = ""
106 # look for nsr
107 step = "getting nsd id='{}' from database".format(ns_request.get("nsdId"))
108 _filter = {"_id": ns_request["nsdId"]}
109 _filter.update(BaseTopic._get_project_filter(session, write=False, show_all=True))
110 nsd = self.db.get_one("nsds", _filter)
111
112 nsr_id = str(uuid4())
113 now = time()
114 step = "filling nsr from input data"
115 nsr_descriptor = {
116 "name": ns_request["nsName"],
117 "name-ref": ns_request["nsName"],
118 "short-name": ns_request["nsName"],
119 "admin-status": "ENABLED",
120 "nsd": nsd,
121 "datacenter": ns_request["vimAccountId"],
122 "resource-orchestrator": "osmopenmano",
123 "description": ns_request.get("nsDescription", ""),
124 "constituent-vnfr-ref": [],
125
126 "operational-status": "init", # typedef ns-operational-
127 "config-status": "init", # typedef config-states
128 "detailed-status": "scheduled",
129
130 "orchestration-progress": {},
131 # {"networks": {"active": 0, "total": 0}, "vms": {"active": 0, "total": 0}},
132
133 "crete-time": now,
134 "nsd-name-ref": nsd["name"],
135 "operational-events": [], # "id", "timestamp", "description", "event",
136 "nsd-ref": nsd["id"],
137 "instantiate_params": ns_request,
138 "ns-instance-config-ref": nsr_id,
139 "id": nsr_id,
140 "_id": nsr_id,
141 # "input-parameter": xpath, value,
142 "ssh-authorized-key": ns_request.get("key-pair-ref"), # TODO remove
143 }
144 ns_request["nsr_id"] = nsr_id
145 # Create vld
146 if nsd.get("vld"):
147 nsr_descriptor["vld"] = []
148 for nsd_vld in nsd.get("vld"):
149 nsr_descriptor["vld"].append(
150 {key: nsd_vld[key] for key in ("id", "vim-network-name", "vim-network-id") if key in nsd_vld})
151
152 # Create VNFR
153 needed_vnfds = {}
154 for member_vnf in nsd.get("constituent-vnfd", ()):
155 vnfd_id = member_vnf["vnfd-id-ref"]
156 step = "getting vnfd id='{}' constituent-vnfd='{}' from database".format(
157 member_vnf["vnfd-id-ref"], member_vnf["member-vnf-index"])
158 if vnfd_id not in needed_vnfds:
159 # Obtain vnfd
160 vnfd = DescriptorTopic.get_one_by_id(self.db, session, "vnfds", vnfd_id)
161 vnfd.pop("_admin")
162 needed_vnfds[vnfd_id] = vnfd
163 else:
164 vnfd = needed_vnfds[vnfd_id]
165 step = "filling vnfr vnfd-id='{}' constituent-vnfd='{}'".format(
166 member_vnf["vnfd-id-ref"], member_vnf["member-vnf-index"])
167 vnfr_id = str(uuid4())
168 vnfr_descriptor = {
169 "id": vnfr_id,
170 "_id": vnfr_id,
171 "nsr-id-ref": nsr_id,
172 "member-vnf-index-ref": member_vnf["member-vnf-index"],
173 "created-time": now,
174 # "vnfd": vnfd, # at OSM model.but removed to avoid data duplication TODO: revise
175 "vnfd-ref": vnfd_id,
176 "vnfd-id": vnfd["_id"], # not at OSM model, but useful
177 "vim-account-id": None,
178 "vdur": [],
179 "connection-point": [],
180 "ip-address": None, # mgmt-interface filled by LCM
181 }
182
183 # Create vld
184 if vnfd.get("internal-vld"):
185 vnfr_descriptor["vld"] = []
186 for vnfd_vld in vnfd.get("internal-vld"):
187 vnfr_descriptor["vld"].append(
188 {key: vnfd_vld[key] for key in ("id", "vim-network-name", "vim-network-id") if key in
189 vnfd_vld})
190
191 vnfd_mgmt_cp = vnfd["mgmt-interface"].get("cp")
192 for cp in vnfd.get("connection-point", ()):
193 vnf_cp = {
194 "name": cp["name"],
195 "connection-point-id": cp.get("id"),
196 "id": cp.get("id"),
197 # "ip-address", "mac-address" # filled by LCM
198 # vim-id # TODO it would be nice having a vim port id
199 }
200 vnfr_descriptor["connection-point"].append(vnf_cp)
201 for vdu in vnfd.get("vdu", ()):
202 vdur = {
203 "vdu-id-ref": vdu["id"],
204 # TODO "name": "" Name of the VDU in the VIM
205 "ip-address": None, # mgmt-interface filled by LCM
206 # "vim-id", "flavor-id", "image-id", "management-ip" # filled by LCM
207 "internal-connection-point": [],
208 "interfaces": [],
209 }
210 if vdu.get("pdu-type"):
211 vdur["pdu-type"] = vdu["pdu-type"]
212 # TODO volumes: name, volume-id
213 for icp in vdu.get("internal-connection-point", ()):
214 vdu_icp = {
215 "id": icp["id"],
216 "connection-point-id": icp["id"],
217 "name": icp.get("name"),
218 # "ip-address", "mac-address" # filled by LCM
219 # vim-id # TODO it would be nice having a vim port id
220 }
221 vdur["internal-connection-point"].append(vdu_icp)
222 for iface in vdu.get("interface", ()):
223 vdu_iface = {
224 "name": iface.get("name"),
225 # "ip-address", "mac-address" # filled by LCM
226 # vim-id # TODO it would be nice having a vim port id
227 }
228 if vnfd_mgmt_cp and iface.get("external-connection-point-ref") == vnfd_mgmt_cp:
229 vdu_iface["mgmt-vnf"] = True
230 if iface.get("mgmt-interface"):
231 vdu_iface["mgmt-interface"] = True # TODO change to mgmt-vdu
232
233 # look for network where this interface is connected
234 if iface.get("external-connection-point-ref"):
235 for nsd_vld in get_iterable(nsd.get("vld")):
236 for nsd_vld_cp in get_iterable(nsd_vld.get("vnfd-connection-point-ref")):
237 if nsd_vld_cp.get("vnfd-connection-point-ref") == \
238 iface["external-connection-point-ref"] and \
239 nsd_vld_cp.get("member-vnf-index-ref") == member_vnf["member-vnf-index"]:
240 vdu_iface["ns-vld-id"] = nsd_vld["id"]
241 break
242 else:
243 continue
244 break
245 elif iface.get("internal-connection-point-ref"):
246 for vnfd_ivld in get_iterable(vnfd.get("internal-vld")):
247 for vnfd_ivld_icp in get_iterable(vnfd_ivld.get("internal-connection-point")):
248 if vnfd_ivld_icp.get("id-ref") == iface["internal-connection-point-ref"]:
249 vdu_iface["vnf-vld-id"] = vnfd_ivld["id"]
250 break
251 else:
252 continue
253 break
254
255 vdur["interfaces"].append(vdu_iface)
256 count = vdu.get("count", 1)
257 if count is None:
258 count = 1
259 count = int(count) # TODO remove when descriptor serialized with payngbind
260 for index in range(0, count):
261 if index:
262 vdur = deepcopy(vdur)
263 vdur["_id"] = str(uuid4())
264 vdur["count-index"] = index
265 vnfr_descriptor["vdur"].append(vdur)
266
267 step = "creating vnfr vnfd-id='{}' constituent-vnfd='{}' at database".format(
268 member_vnf["vnfd-id-ref"], member_vnf["member-vnf-index"])
269
270 # add at database
271 BaseTopic.format_on_new(vnfr_descriptor, session["project_id"], make_public=make_public)
272 self.db.create("vnfrs", vnfr_descriptor)
273 rollback.append({"topic": "vnfrs", "_id": vnfr_id})
274 nsr_descriptor["constituent-vnfr-ref"].append(vnfr_id)
275
276 step = "creating nsr at database"
277 self.format_on_new(nsr_descriptor, session["project_id"], make_public=make_public)
278 self.db.create("nsrs", nsr_descriptor)
279 rollback.append({"topic": "nsrs", "_id": nsr_id})
280 return nsr_id
281 except Exception as e:
282 self.logger.exception("Exception {} at NsrTopic.new()".format(e), exc_info=True)
283 raise EngineException("Error {}: {}".format(step, e))
284 except ValidationError as e:
285 raise EngineException(e, HTTPStatus.UNPROCESSABLE_ENTITY)
286
287 def edit(self, session, _id, indata=None, kwargs=None, force=False, content=None):
288 raise EngineException("Method edit called directly", HTTPStatus.INTERNAL_SERVER_ERROR)
289
290
291 class VnfrTopic(BaseTopic):
292 topic = "vnfrs"
293 topic_msg = None
294
295 def __init__(self, db, fs, msg):
296 BaseTopic.__init__(self, db, fs, msg)
297
298 def delete(self, session, _id, force=False, dry_run=False):
299 raise EngineException("Method delete called directly", HTTPStatus.INTERNAL_SERVER_ERROR)
300
301 def edit(self, session, _id, indata=None, kwargs=None, force=False, content=None):
302 raise EngineException("Method edit called directly", HTTPStatus.INTERNAL_SERVER_ERROR)
303
304 def new(self, rollback, session, indata=None, kwargs=None, headers=None, force=False, make_public=False):
305 # Not used because vnfrs are created and deleted by NsrTopic class directly
306 raise EngineException("Method new called directly", HTTPStatus.INTERNAL_SERVER_ERROR)
307
308
309 class NsLcmOpTopic(BaseTopic):
310 topic = "nslcmops"
311 topic_msg = "ns"
312 operation_schema = { # mapping between operation and jsonschema to validate
313 "instantiate": ns_instantiate,
314 "action": ns_action,
315 "scale": ns_scale,
316 "terminate": None,
317 }
318
319 def __init__(self, db, fs, msg):
320 BaseTopic.__init__(self, db, fs, msg)
321
322 def _check_ns_operation(self, session, nsr, operation, indata):
323 """
324 Check that user has enter right parameters for the operation
325 :param session:
326 :param operation: it can be: instantiate, terminate, action, TODO: update, heal
327 :param indata: descriptor with the parameters of the operation
328 :return: None
329 """
330 vnfds = {}
331 vim_accounts = []
332 nsd = nsr["nsd"]
333
334 def check_valid_vnf_member_index(member_vnf_index):
335 # TODO change to vnfR
336 for vnf in nsd["constituent-vnfd"]:
337 if member_vnf_index == vnf["member-vnf-index"]:
338 vnfd_id = vnf["vnfd-id-ref"]
339 if vnfd_id not in vnfds:
340 vnfds[vnfd_id] = self.db.get_one("vnfds", {"id": vnfd_id})
341 return vnfds[vnfd_id]
342 else:
343 raise EngineException("Invalid parameter member_vnf_index='{}' is not one of the "
344 "nsd:constituent-vnfd".format(member_vnf_index))
345
346 def _check_vnf_instantiation_params(in_vnfd, vnfd):
347
348 for in_vdu in get_iterable(in_vnfd.get("vdu")):
349 for vdu in get_iterable(vnfd.get("vdu")):
350 if in_vdu["id"] == vdu["id"]:
351 for volume in get_iterable(in_vdu.get("volume")):
352 for volumed in get_iterable(vdu.get("volumes")):
353 if volumed["name"] == volume["name"]:
354 break
355 else:
356 raise EngineException("Invalid parameter vnf[member-vnf-index='{}']:vdu[id='{}']:"
357 "volume:name='{}' is not present at vnfd:vdu:volumes list".
358 format(in_vnf["member-vnf-index"], in_vdu["id"],
359 volume["name"]))
360 for in_iface in get_iterable(in_vdu["interface"]):
361 for iface in get_iterable(vdu.get("interface")):
362 if in_iface["name"] == iface["name"]:
363 break
364 else:
365 raise EngineException("Invalid parameter vnf[member-vnf-index='{}']:vdu[id='{}']:"
366 "interface[name='{}'] is not present at vnfd:vdu:interface"
367 .format(in_vnf["member-vnf-index"], in_vdu["id"],
368 in_iface["name"]))
369 break
370 else:
371 raise EngineException("Invalid parameter vnf[member-vnf-index='{}']:vdu[id='{}'] is is not present "
372 "at vnfd:vdu".format(in_vnf["member-vnf-index"], in_vdu["id"]))
373
374 for in_ivld in get_iterable(in_vnfd.get("internal-vld")):
375 for ivld in get_iterable(vnfd.get("internal-vld")):
376 if in_ivld["name"] == ivld["name"] or in_ivld["name"] == ivld["id"]:
377 for in_icp in get_iterable(in_ivld["internal-connection-point"]):
378 for icp in ivld["internal-connection-point"]:
379 if in_icp["id-ref"] == icp["id-ref"]:
380 break
381 else:
382 raise EngineException("Invalid parameter vnf[member-vnf-index='{}']:internal-vld[name"
383 "='{}']:internal-connection-point[id-ref:'{}'] is not present at "
384 "vnfd:internal-vld:name/id:internal-connection-point"
385 .format(in_vnf["member-vnf-index"], in_ivld["name"],
386 in_icp["id-ref"], vnfd["id"]))
387 break
388 else:
389 raise EngineException("Invalid parameter vnf[member-vnf-index='{}']:internal-vld:name='{}'"
390 " is not present at vnfd '{}'".format(in_vnf["member-vnf-index"],
391 in_ivld["name"], vnfd["id"]))
392
393 def check_valid_vim_account(vim_account):
394 if vim_account in vim_accounts:
395 return
396 try:
397 db_filter = self._get_project_filter(session, write=False, show_all=True)
398 db_filter["_id"] = vim_account
399 self.db.get_one("vim_accounts", db_filter)
400 except Exception:
401 raise EngineException("Invalid vimAccountId='{}' not present for the project".format(vim_account))
402 vim_accounts.append(vim_account)
403
404 if operation == "action":
405 # check vnf_member_index
406 if indata.get("vnf_member_index"):
407 indata["member_vnf_index"] = indata.pop("vnf_member_index") # for backward compatibility
408 if not indata.get("member_vnf_index"):
409 raise EngineException("Missing 'member_vnf_index' parameter")
410 vnfd = check_valid_vnf_member_index(indata["member_vnf_index"])
411 # check primitive
412 for config_primitive in get_iterable(vnfd.get("vnf-configuration", {}).get("config-primitive")):
413 if indata["primitive"] == config_primitive["name"]:
414 # check needed primitive_params are provided
415 if indata.get("primitive_params"):
416 in_primitive_params_copy = copy(indata["primitive_params"])
417 else:
418 in_primitive_params_copy = {}
419 for paramd in get_iterable(config_primitive.get("parameter")):
420 if paramd["name"] in in_primitive_params_copy:
421 del in_primitive_params_copy[paramd["name"]]
422 elif not paramd.get("default-value"):
423 raise EngineException("Needed parameter {} not provided for primitive '{}'".format(
424 paramd["name"], indata["primitive"]))
425 # check no extra primitive params are provided
426 if in_primitive_params_copy:
427 raise EngineException("parameter/s '{}' not present at vnfd for primitive '{}'".format(
428 list(in_primitive_params_copy.keys()), indata["primitive"]))
429 break
430 else:
431 raise EngineException("Invalid primitive '{}' is not present at vnfd".format(indata["primitive"]))
432 if operation == "scale":
433 vnfd = check_valid_vnf_member_index(indata["scaleVnfData"]["scaleByStepData"]["member-vnf-index"])
434 for scaling_group in get_iterable(vnfd.get("scaling-group-descriptor")):
435 if indata["scaleVnfData"]["scaleByStepData"]["scaling-group-descriptor"] == scaling_group["name"]:
436 break
437 else:
438 raise EngineException("Invalid scaleVnfData:scaleByStepData:scaling-group-descriptor '{}' is not "
439 "present at vnfd:scaling-group-descriptor".format(
440 indata["scaleVnfData"]["scaleByStepData"]["scaling-group-descriptor"]))
441 if operation == "instantiate":
442 # check vim_account
443 check_valid_vim_account(indata["vimAccountId"])
444 for in_vnf in get_iterable(indata.get("vnf")):
445 vnfd = check_valid_vnf_member_index(in_vnf["member-vnf-index"])
446 _check_vnf_instantiation_params(in_vnf, vnfd)
447 if in_vnf.get("vimAccountId"):
448 check_valid_vim_account(in_vnf["vimAccountId"])
449
450 for in_vld in get_iterable(indata.get("vld")):
451 for vldd in get_iterable(nsd.get("vld")):
452 if in_vld["name"] == vldd["name"] or in_vld["name"] == vldd["id"]:
453 break
454 else:
455 raise EngineException("Invalid parameter vld:name='{}' is not present at nsd:vld".format(
456 in_vld["name"]))
457
458 def _look_for_pdu(self, session, rollback, vnfr, vim_account, vnfr_update, vnfr_update_rollback):
459 """
460 Look for a free PDU in the catalog matching vdur type and interfaces. Fills vnfr.vdur with the interface
461 (ip_address, ...) information.
462 Modifies PDU _admin.usageState to 'IN_USE'
463
464 :param session: client session information
465 :param rollback: list with the database modifications to rollback if needed
466 :param vnfr: vnfr to be updated. It is modified with pdu interface info if pdu is found
467 :param vim_account: vim_account where this vnfr should be deployed
468 :param vnfr_update: dictionary filled by this method with changes to be done at database vnfr
469 :param vnfr_update_rollback: dictionary filled by this method with original content of vnfr in case a rollback
470 of the changed vnfr is needed
471
472 :return: List of PDU interfaces that are connected to an existing VIM network. Each item contains:
473 "vim-network-name": used at VIM
474 "name": interface name
475 "vnf-vld-id": internal VNFD vld where this interface is connected, or
476 "ns-vld-id": NSD vld where this interface is connected.
477 NOTE: One, and only one between 'vnf-vld-id' and 'ns-vld-id' contains a value. The other will be None
478 """
479
480 ifaces_forcing_vim_network = []
481 for vdur_index, vdur in enumerate(get_iterable(vnfr.get("vdur"))):
482 if not vdur.get("pdu-type"):
483 continue
484 pdu_type = vdur.get("pdu-type")
485 pdu_filter = self._get_project_filter(session, write=True, show_all=True)
486 pdu_filter["vim_accounts"] = vim_account
487 pdu_filter["type"] = pdu_type
488 pdu_filter["_admin.operationalState"] = "ENABLED"
489 pdu_filter["_admin.usageState"] = "NOT_IN_USE"
490 # TODO feature 1417: "shared": True,
491
492 available_pdus = self.db.get_list("pdus", pdu_filter)
493 for pdu in available_pdus:
494 # step 1 check if this pdu contains needed interfaces:
495 match_interfaces = True
496 for vdur_interface in vdur["interfaces"]:
497 for pdu_interface in pdu["interfaces"]:
498 if pdu_interface["name"] == vdur_interface["name"]:
499 # TODO feature 1417: match per mgmt type
500 break
501 else: # no interface found for name
502 match_interfaces = False
503 break
504 if match_interfaces:
505 break
506 else:
507 raise EngineException(
508 "No PDU of type={} at vim_account={} found for member_vnf_index={}, vdu={} matching interface "
509 "names".format(pdu_type, vim_account, vnfr["member-vnf-index-ref"], vdur["vdu-id-ref"]))
510
511 # step 2. Update pdu
512 rollback_pdu = {
513 "_admin.usageState": pdu["_admin"]["usageState"],
514 "_admin.usage.vnfr_id": None,
515 "_admin.usage.nsr_id": None,
516 "_admin.usage.vdur": None,
517 }
518 self.db.set_one("pdus", {"_id": pdu["_id"]},
519 {"_admin.usageState": "IN_USE",
520 "_admin.usage": {"vnfr_id": vnfr["_id"],
521 "nsr_id": vnfr["nsr-id-ref"],
522 "vdur": vdur["vdu-id-ref"]}
523 })
524 rollback.append({"topic": "pdus", "_id": pdu["_id"], "operation": "set", "content": rollback_pdu})
525
526 # step 3. Fill vnfr info by filling vdur
527 vdu_text = "vdur.{}".format(vdur_index)
528 vnfr_update_rollback[vdu_text + ".pdu-id"] = None
529 vnfr_update[vdu_text + ".pdu-id"] = pdu["_id"]
530 for iface_index, vdur_interface in enumerate(vdur["interfaces"]):
531 for pdu_interface in pdu["interfaces"]:
532 if pdu_interface["name"] == vdur_interface["name"]:
533 iface_text = vdu_text + ".interfaces.{}".format(iface_index)
534 for k, v in pdu_interface.items():
535 if k in ("ip-address", "mac-address"): # TODO: switch-xxxxx must be inserted
536 vnfr_update[iface_text + ".{}".format(k)] = v
537 vnfr_update_rollback[iface_text + ".{}".format(k)] = vdur_interface.get(v)
538 if pdu_interface.get("ip-address"):
539 if vdur_interface.get("mgmt-interface"):
540 vnfr_update_rollback[vdu_text + ".ip-address"] = vdur.get("ip-address")
541 vnfr_update[vdu_text + ".ip-address"] = pdu_interface["ip-address"]
542 if vdur_interface.get("mgmt-vnf"):
543 vnfr_update_rollback["ip-address"] = vnfr.get("ip-address")
544 vnfr_update["ip-address"] = pdu_interface["ip-address"]
545 if pdu_interface.get("vim-network-name") or pdu_interface.get("vim-network-id"):
546 ifaces_forcing_vim_network.append({
547 "name": vdur_interface.get("vnf-vld-id") or vdur_interface.get("ns-vld-id"),
548 "vnf-vld-id": vdur_interface.get("vnf-vld-id"),
549 "ns-vld-id": vdur_interface.get("ns-vld-id")})
550 if pdu_interface.get("vim-network-id"):
551 ifaces_forcing_vim_network.append({
552 "vim-network-id": pdu_interface.get("vim-network-id")})
553 if pdu_interface.get("vim-network-name"):
554 ifaces_forcing_vim_network.append({
555 "vim-network-name": pdu_interface.get("vim-network-name")})
556 break
557
558 return ifaces_forcing_vim_network
559
560 def _update_vnfrs(self, session, rollback, nsr, indata):
561 vnfrs = None
562 # get vnfr
563 nsr_id = nsr["_id"]
564 vnfrs = self.db.get_list("vnfrs", {"nsr-id-ref": nsr_id})
565
566 for vnfr in vnfrs:
567 vnfr_update = {}
568 vnfr_update_rollback = {}
569 member_vnf_index = vnfr["member-vnf-index-ref"]
570 # update vim-account-id
571
572 vim_account = indata["vimAccountId"]
573 # check instantiate parameters
574 for vnf_inst_params in get_iterable(indata.get("vnf")):
575 if vnf_inst_params["member-vnf-index"] != member_vnf_index:
576 continue
577 if vnf_inst_params.get("vimAccountId"):
578 vim_account = vnf_inst_params.get("vimAccountId")
579
580 vnfr_update["vim-account-id"] = vim_account
581 vnfr_update_rollback["vim-account-id"] = vnfr.get("vim-account-id")
582
583 # get pdu
584 ifaces_forcing_vim_network = self._look_for_pdu(session, rollback, vnfr, vim_account, vnfr_update,
585 vnfr_update_rollback)
586
587 # updata database vnfr
588 self.db.set_one("vnfrs", {"_id": vnfr["_id"]}, vnfr_update)
589 rollback.append({"topic": "vnfrs", "_id": vnfr["_id"], "operation": "set", "content": vnfr_update_rollback})
590
591 # Update indada in case pdu forces to use a concrete vim-network-name
592 # TODO check if user has already insert a vim-network-name and raises an error
593 if not ifaces_forcing_vim_network:
594 continue
595 for iface_info in ifaces_forcing_vim_network:
596 if iface_info.get("ns-vld-id"):
597 if "vld" not in indata:
598 indata["vld"] = []
599 indata["vld"].append({key: iface_info[key] for key in
600 ("name", "vim-network-name", "vim-network-id") if iface_info.get(key)})
601
602 elif iface_info.get("vnf-vld-id"):
603 if "vnf" not in indata:
604 indata["vnf"] = []
605 indata["vnf"].append({
606 "member-vnf-index": member_vnf_index,
607 "internal-vld": [{key: iface_info[key] for key in
608 ("name", "vim-network-name", "vim-network-id") if iface_info.get(key)}]
609 })
610
611 @staticmethod
612 def _create_nslcmop(nsr_id, operation, params):
613 """
614 Creates a ns-lcm-opp content to be stored at database.
615 :param nsr_id: internal id of the instance
616 :param operation: instantiate, terminate, scale, action, ...
617 :param params: user parameters for the operation
618 :return: dictionary following SOL005 format
619 """
620 now = time()
621 _id = str(uuid4())
622 nslcmop = {
623 "id": _id,
624 "_id": _id,
625 "operationState": "PROCESSING", # COMPLETED,PARTIALLY_COMPLETED,FAILED_TEMP,FAILED,ROLLING_BACK,ROLLED_BACK
626 "statusEnteredTime": now,
627 "nsInstanceId": nsr_id,
628 "lcmOperationType": operation,
629 "startTime": now,
630 "isAutomaticInvocation": False,
631 "operationParams": params,
632 "isCancelPending": False,
633 "links": {
634 "self": "/osm/nslcm/v1/ns_lcm_op_occs/" + _id,
635 "nsInstance": "/osm/nslcm/v1/ns_instances/" + nsr_id,
636 }
637 }
638 return nslcmop
639
640 def new(self, rollback, session, indata=None, kwargs=None, headers=None, force=False, make_public=False,
641 slice_object=False):
642 """
643 Performs a new operation over a ns
644 :param rollback: list to append created items at database in case a rollback must to be done
645 :param session: contains the used login username and working project
646 :param indata: descriptor with the parameters of the operation. It must contains among others
647 nsInstanceId: _id of the nsr to perform the operation
648 operation: it can be: instantiate, terminate, action, TODO: update, heal
649 :param kwargs: used to override the indata descriptor
650 :param headers: http request headers
651 :param force: If True avoid some dependence checks
652 :param make_public: Make the created item public to all projects
653 :return: id of the nslcmops
654 """
655 try:
656 # Override descriptor with query string kwargs
657 self._update_input_with_kwargs(indata, kwargs)
658 operation = indata["lcmOperationType"]
659 nsInstanceId = indata["nsInstanceId"]
660
661 validate_input(indata, self.operation_schema[operation])
662 # get ns from nsr_id
663 _filter = BaseTopic._get_project_filter(session, write=True, show_all=False)
664 _filter["_id"] = nsInstanceId
665 nsr = self.db.get_one("nsrs", _filter)
666
667 # initial checking
668 if not nsr["_admin"].get("nsState") or nsr["_admin"]["nsState"] == "NOT_INSTANTIATED":
669 if operation == "terminate" and indata.get("autoremove"):
670 # NSR must be deleted
671 return None # a none in this case is used to indicate not instantiated. It can be removed
672 if operation != "instantiate":
673 raise EngineException("ns_instance '{}' cannot be '{}' because it is not instantiated".format(
674 nsInstanceId, operation), HTTPStatus.CONFLICT)
675 else:
676 if operation == "instantiate" and not indata.get("force"):
677 raise EngineException("ns_instance '{}' cannot be '{}' because it is already instantiated".format(
678 nsInstanceId, operation), HTTPStatus.CONFLICT)
679 self._check_ns_operation(session, nsr, operation, indata)
680
681 if operation == "instantiate":
682 self._update_vnfrs(session, rollback, nsr, indata)
683
684 nslcmop_desc = self._create_nslcmop(nsInstanceId, operation, indata)
685 self.format_on_new(nslcmop_desc, session["project_id"], make_public=make_public)
686 _id = self.db.create("nslcmops", nslcmop_desc)
687 rollback.append({"topic": "nslcmops", "_id": _id})
688 if not slice_object:
689 self.msg.write("ns", operation, nslcmop_desc)
690 return _id
691 except ValidationError as e:
692 raise EngineException(e, HTTPStatus.UNPROCESSABLE_ENTITY)
693 # except DbException as e:
694 # raise EngineException("Cannot get ns_instance '{}': {}".format(e), HTTPStatus.NOT_FOUND)
695
696 def delete(self, session, _id, force=False, dry_run=False):
697 raise EngineException("Method delete called directly", HTTPStatus.INTERNAL_SERVER_ERROR)
698
699 def edit(self, session, _id, indata=None, kwargs=None, force=False, content=None):
700 raise EngineException("Method edit called directly", HTTPStatus.INTERNAL_SERVER_ERROR)
701
702
703 class NsiTopic(BaseTopic):
704 topic = "nsis"
705 topic_msg = "nsi"
706
707 def __init__(self, db, fs, msg):
708 BaseTopic.__init__(self, db, fs, msg)
709
710 def _check_descriptor_dependencies(self, session, descriptor):
711 """
712 Check that the dependent descriptors exist on a new descriptor or edition
713 :param session: client session information
714 :param descriptor: descriptor to be inserted or edit
715 :return: None or raises exception
716 """
717 if not descriptor.get("nst-ref"):
718 return
719 nstd_id = descriptor["nst-ref"]
720 if not self.get_item_list(session, "nsts", {"id": nstd_id}):
721 raise EngineException("Descriptor error at nst-ref='{}' references a non exist nstd".format(nstd_id),
722 http_code=HTTPStatus.CONFLICT)
723
724 @staticmethod
725 def format_on_new(content, project_id=None, make_public=False):
726 BaseTopic.format_on_new(content, project_id=project_id, make_public=make_public)
727
728 def check_conflict_on_del(self, session, _id, force=False):
729 if force:
730 return
731 nsi = self.db.get_one("nsis", {"_id": _id})
732 if nsi["_admin"].get("nsiState") == "INSTANTIATED":
733 raise EngineException("nsi '{}' cannot be deleted because it is in 'INSTANTIATED' state. "
734 "Launch 'terminate' operation first; or force deletion".format(_id),
735 http_code=HTTPStatus.CONFLICT)
736
737 def delete(self, session, _id, force=False, dry_run=False):
738 """
739 Delete item by its internal _id
740 :param session: contains the used login username, working project, and admin rights
741 :param _id: server internal id
742 :param force: indicates if deletion must be forced in case of conflict
743 :param dry_run: make checking but do not delete
744 :return: dictionary with deleted item _id. It raises EngineException on error: not found, conflict, ...
745 """
746 # TODO add admin to filter, validate rights
747 BaseTopic.delete(self, session, _id, force, dry_run=True)
748 if dry_run:
749 return
750
751 # deletes NetSlice instance object
752 v = self.db.del_one("nsis", {"_id": _id})
753
754 # makes a temporal list of nsilcmops objects related to the _id given and deletes them from db
755 _filter = {"netsliceInstanceId": _id}
756 self.db.del_list("nsilcmops", _filter)
757
758 _filter = {"operationParams.netsliceInstanceId": _id}
759 nslcmops_list = self.db.get_list("nslcmops", _filter)
760
761 for id_item in nslcmops_list:
762 _filter = {"_id": id_item}
763 nslcmop = self.db.get_one("nslcmops", _filter)
764 nsr_id = nslcmop["operationParams"]["nsr_id"]
765 NsrTopic.delete(self, session, nsr_id, force=False, dry_run=False)
766 self._send_msg("deleted", {"_id": _id})
767 return v
768
769 def new(self, rollback, session, indata=None, kwargs=None, headers=None, force=False, make_public=False):
770 """
771 Creates a new netslice instance record into database. It also creates needed nsrs and vnfrs
772 :param rollback: list to append the created items at database in case a rollback must be done
773 :param session: contains the used login username and working project
774 :param indata: params to be used for the nsir
775 :param kwargs: used to override the indata descriptor
776 :param headers: http request headers
777 :param force: If True avoid some dependence checks
778 :param make_public: Make the created item public to all projects
779 :return: the _id of nsi descriptor created at database
780 """
781
782 try:
783 slice_request = self._remove_envelop(indata)
784 # Override descriptor with query string kwargs
785 self._update_input_with_kwargs(slice_request, kwargs)
786 self._validate_input_new(slice_request, force)
787
788 step = ""
789 # look for nstd
790 step = "getting nstd id='{}' from database".format(slice_request.get("nstId"))
791 _filter = {"_id": slice_request["nstId"]}
792 _filter.update(BaseTopic._get_project_filter(session, write=False, show_all=True))
793 nstd = self.db.get_one("nsts", _filter)
794 nstd.pop("_admin", None)
795 nstd.pop("_id", None)
796 nsi_id = str(uuid4())
797 step = "filling nsi_descriptor with input data"
798
799 # Creating the NSIR
800 nsi_descriptor = {
801 "id": nsi_id,
802 "name": slice_request["nsiName"],
803 "description": slice_request.get("nsiDescription", ""),
804 "datacenter": slice_request["vimAccountId"],
805 "nst-ref": nstd["id"],
806 "instantiation_parameters": slice_request,
807 "network-slice-template": nstd,
808 "nsr-ref-list": [],
809 "vlr-list": [],
810 "_id": nsi_id,
811 }
812
813 step = "creating nsi at database"
814 self.format_on_new(nsi_descriptor, session["project_id"], make_public=make_public)
815 nsi_descriptor["_admin"]["nsiState"] = "NOT_INSTANTIATED"
816 nsi_descriptor["_admin"]["netslice-subnet"] = None
817
818 # Creating netslice-vld for the RO.
819 step = "creating netslice-vld at database"
820 instantiation_parameters = slice_request
821
822 # Building the vlds list to be deployed
823 # From netslice descriptors, creating the initial list
824 nsi_vlds = []
825 if nstd.get("netslice-vld"):
826 # Building VLDs from NST
827 for netslice_vlds in nstd["netslice-vld"]:
828 nsi_vld = {}
829 # Adding nst vld name and global vimAccountId for netslice vld creation
830 nsi_vld["name"] = netslice_vlds["name"]
831 nsi_vld["vimAccountId"] = slice_request["vimAccountId"]
832 # Getting template Instantiation parameters from NST
833 for netslice_vld in netslice_vlds["nss-connection-point-ref"]:
834 for netslice_subnet in nstd["netslice-subnet"]:
835 nsi_vld["nsd-ref"] = netslice_subnet["nsd-ref"]
836 nsi_vld["nsd-connection-point-ref"] = netslice_vld["nsd-connection-point-ref"]
837 # Obtaining the vimAccountId from template instantiation parameter
838 if netslice_subnet.get("instantiation-parameters"):
839 # Taking the vimAccountId from NST netslice-subnet instantiation parameters
840 if netslice_subnet["instantiation-parameters"].get("vimAccountId"):
841 netsn = netslice_subnet["instantiation-parameters"]["vimAccountId"]
842 nsi_vld["vimAccountId"] = netsn
843 # Obtaining the vimAccountId from user instantiation parameter
844 if instantiation_parameters.get("netslice-subnet"):
845 for ins_param in instantiation_parameters["netslice-subnet"]:
846 if ins_param.get("id") == netslice_vld["nss-ref"]:
847 if ins_param.get("vimAccountId"):
848 nsi_vld["vimAccountId"] = ins_param["vimAccountId"]
849 # Adding vim-network-name defined by the user to vld
850 if instantiation_parameters.get("netslice-vld"):
851 for ins_param in instantiation_parameters["netslice-vld"]:
852 if ins_param["name"] == netslice_vlds["name"]:
853 if ins_param.get("vim-network-name"):
854 nsi_vld["vim-network-name"] = ins_param.get("vim-network-name")
855 if ins_param.get("vim-network-id"):
856 nsi_vld["vim-network-id"] = ins_param.get("vim-network-id")
857 nsi_vlds.append(nsi_vld)
858
859 nsi_descriptor["_admin"]["netslice-vld"] = nsi_vlds
860 # Creating netslice-subnet_record.
861 needed_nsds = {}
862 services = []
863
864 for member_ns in nstd["netslice-subnet"]:
865 nsd_id = member_ns["nsd-ref"]
866 step = "getting nstd id='{}' constituent-nsd='{}' from database".format(
867 member_ns["nsd-ref"], member_ns["id"])
868 if nsd_id not in needed_nsds:
869 # Obtain nsd
870 nsd = DescriptorTopic.get_one_by_id(self.db, session, "nsds", nsd_id)
871 nsd.pop("_admin")
872 needed_nsds[nsd_id] = nsd
873 member_ns["_id"] = needed_nsds[nsd_id].get("_id")
874 services.append(member_ns)
875 else:
876 nsd = needed_nsds[nsd_id]
877 member_ns["_id"] = needed_nsds[nsd_id].get("_id")
878 services.append(member_ns)
879
880 step = "filling nsir nsd-id='{}' constituent-nsd='{}' from database".format(
881 member_ns["nsd-ref"], member_ns["id"])
882
883 # creates Network Services records (NSRs)
884 step = "creating nsrs at database using NsrTopic.new()"
885 ns_params = slice_request.get("netslice-subnet")
886
887 nsrs_list = []
888 nsi_netslice_subnet = []
889 for service in services:
890 indata_ns = {}
891 indata_ns["nsdId"] = service["_id"]
892 indata_ns["nsName"] = slice_request.get("nsiName") + "." + service["id"]
893 indata_ns["vimAccountId"] = slice_request.get("vimAccountId")
894 indata_ns["nsDescription"] = service["description"]
895 indata_ns["key-pair-ref"] = None
896
897 # NsrTopic(rollback, session, indata_ns, kwargs, headers, force)
898 # Overwriting ns_params filtering by nsName == netslice-subnet.id
899
900 if ns_params:
901 for ns_param in ns_params:
902 if ns_param.get("id") == service["id"]:
903 copy_ns_param = deepcopy(ns_param)
904 del copy_ns_param["id"]
905 indata_ns.update(copy_ns_param)
906 # TODO: Improve network selection via networkID
907 if nsi_vlds:
908 indata_ns_list = []
909 for nsi_vld in nsi_vlds:
910 nsd = self.db.get_one("nsds", {"id": nsi_vld["nsd-ref"]})
911 if nsd["connection-point"]:
912 for vld_id_ref in nsd["connection-point"]:
913 name = vld_id_ref["vld-id-ref"]
914 vnm = nsi_vld.get("vim-network-name")
915 if type(vnm) is not dict:
916 vnm = {slice_request.get("vimAccountId"): vnm}
917 if vld_id_ref["name"] == nsi_vld["nsd-connection-point-ref"]:
918 if list(vnm.values())[0] is None:
919 networkName = "default"
920 else:
921 networkName = str(list(vnm.values())[0])
922 # VIMNetworkName = NetSliceName-NetworkName
923 vimnetname = str(slice_request["nsiName"]) + "-" + networkName
924 indata_ns_list.append({"name": name, "vim-network-name": vimnetname})
925 indata_ns["vld"] = indata_ns_list
926
927 _id_nsr = NsrTopic.new(self, rollback, session, indata_ns, kwargs, headers, force)
928 nsrs_item = {"nsrId": _id_nsr}
929 nsrs_list.append(nsrs_item)
930 nsi_netslice_subnet.append(indata_ns)
931 nsr_ref = {"nsr-ref": _id_nsr}
932 nsi_descriptor["nsr-ref-list"].append(nsr_ref)
933
934 # Adding the nsrs list to the nsi
935 nsi_descriptor["_admin"]["nsrs-detailed-list"] = nsrs_list
936 nsi_descriptor["_admin"]["netslice-subnet"] = nsi_netslice_subnet
937 # Creating the entry in the database
938 self.db.create("nsis", nsi_descriptor)
939 rollback.append({"topic": "nsis", "_id": nsi_id})
940 return nsi_id
941 except Exception as e:
942 self.logger.exception("Exception {} at NsiTopic.new()".format(e), exc_info=True)
943 raise EngineException("Error {}: {}".format(step, e))
944 except ValidationError as e:
945 raise EngineException(e, HTTPStatus.UNPROCESSABLE_ENTITY)
946
947 def edit(self, session, _id, indata=None, kwargs=None, force=False, content=None):
948 raise EngineException("Method edit called directly", HTTPStatus.INTERNAL_SERVER_ERROR)
949
950
951 class NsiLcmOpTopic(BaseTopic):
952 topic = "nsilcmops"
953 topic_msg = "nsi"
954 operation_schema = { # mapping between operation and jsonschema to validate
955 "instantiate": nsi_instantiate,
956 "terminate": None
957 }
958
959 def __init__(self, db, fs, msg):
960 BaseTopic.__init__(self, db, fs, msg)
961
962 def _check_nsi_operation(self, session, nsir, operation, indata):
963 """
964 Check that user has enter right parameters for the operation
965 :param session:
966 :param operation: it can be: instantiate, terminate, action, TODO: update, heal
967 :param indata: descriptor with the parameters of the operation
968 :return: None
969 """
970 nsds = {}
971 nstd = nsir["network-slice-template"]
972
973 def check_valid_netslice_subnet_id(nstId):
974 # TODO change to vnfR (??)
975 for netslice_subnet in nstd["netslice-subnet"]:
976 if nstId == netslice_subnet["id"]:
977 nsd_id = netslice_subnet["nsd-ref"]
978 if nsd_id not in nsds:
979 nsds[nsd_id] = self.db.get_one("nsds", {"id": nsd_id})
980 return nsds[nsd_id]
981 else:
982 raise EngineException("Invalid parameter nstId='{}' is not one of the "
983 "nst:netslice-subnet".format(nstId))
984 if operation == "instantiate":
985 # check the existance of netslice-subnet items
986 for in_nst in get_iterable(indata.get("netslice-subnet")):
987 check_valid_netslice_subnet_id(in_nst["id"])
988
989 def _create_nsilcmop(self, session, netsliceInstanceId, operation, params):
990 now = time()
991 _id = str(uuid4())
992 nsilcmop = {
993 "id": _id,
994 "_id": _id,
995 "operationState": "PROCESSING", # COMPLETED,PARTIALLY_COMPLETED,FAILED_TEMP,FAILED,ROLLING_BACK,ROLLED_BACK
996 "statusEnteredTime": now,
997 "netsliceInstanceId": netsliceInstanceId,
998 "lcmOperationType": operation,
999 "startTime": now,
1000 "isAutomaticInvocation": False,
1001 "operationParams": params,
1002 "isCancelPending": False,
1003 "links": {
1004 "self": "/osm/nsilcm/v1/nsi_lcm_op_occs/" + _id,
1005 "nsInstance": "/osm/nsilcm/v1/netslice_instances/" + netsliceInstanceId,
1006 }
1007 }
1008 return nsilcmop
1009
1010 def new(self, rollback, session, indata=None, kwargs=None, headers=None, force=False, make_public=False):
1011 """
1012 Performs a new operation over a ns
1013 :param rollback: list to append created items at database in case a rollback must to be done
1014 :param session: contains the used login username and working project
1015 :param indata: descriptor with the parameters of the operation. It must contains among others
1016 nsiInstanceId: _id of the nsir to perform the operation
1017 operation: it can be: instantiate, terminate, action, TODO: update, heal
1018 :param kwargs: used to override the indata descriptor
1019 :param headers: http request headers
1020 :param force: If True avoid some dependence checks
1021 :param make_public: Make the created item public to all projects
1022 :return: id of the nslcmops
1023 """
1024 try:
1025 # Override descriptor with query string kwargs
1026 self._update_input_with_kwargs(indata, kwargs)
1027 operation = indata["lcmOperationType"]
1028 nsiInstanceId = indata["nsiInstanceId"]
1029 validate_input(indata, self.operation_schema[operation])
1030
1031 # get nsi from nsiInstanceId
1032 _filter = BaseTopic._get_project_filter(session, write=True, show_all=False)
1033 _filter["_id"] = nsiInstanceId
1034 nsir = self.db.get_one("nsis", _filter)
1035
1036 # initial checking
1037 if not nsir["_admin"].get("nsiState") or nsir["_admin"]["nsiState"] == "NOT_INSTANTIATED":
1038 if operation == "terminate" and indata.get("autoremove"):
1039 # NSIR must be deleted
1040 return None # a none in this case is used to indicate not instantiated. It can be removed
1041 if operation != "instantiate":
1042 raise EngineException("netslice_instance '{}' cannot be '{}' because it is not instantiated".format(
1043 nsiInstanceId, operation), HTTPStatus.CONFLICT)
1044 else:
1045 if operation == "instantiate" and not indata.get("force"):
1046 raise EngineException("netslice_instance '{}' cannot be '{}' because it is already instantiated".
1047 format(nsiInstanceId, operation), HTTPStatus.CONFLICT)
1048
1049 # Creating all the NS_operation (nslcmop)
1050 # Get service list from db
1051 nsrs_list = nsir["_admin"]["nsrs-detailed-list"]
1052 nslcmops = []
1053 for nsr_item in nsrs_list:
1054 service = self.db.get_one("nsrs", {"_id": nsr_item["nsrId"]})
1055 indata_ns = {}
1056 indata_ns = service["instantiate_params"]
1057 indata_ns["lcmOperationType"] = operation
1058 indata_ns["nsInstanceId"] = service["_id"]
1059 # Including netslice_id in the ns instantiate Operation
1060 indata_ns["netsliceInstanceId"] = nsiInstanceId
1061 del indata_ns["key-pair-ref"]
1062 nsi_NsLcmOpTopic = NsLcmOpTopic(self.db, self.fs, self.msg)
1063 # Creating NS_LCM_OP with the flag slice_object=True to not trigger the service instantiation
1064 # message via kafka bus
1065 nslcmop = nsi_NsLcmOpTopic.new(rollback, session, indata_ns, kwargs, headers, force, slice_object=True)
1066 nslcmops.append(nslcmop)
1067
1068 # Creates nsilcmop
1069 indata["nslcmops_ids"] = nslcmops
1070 self._check_nsi_operation(session, nsir, operation, indata)
1071 nsilcmop_desc = self._create_nsilcmop(session, nsiInstanceId, operation, indata)
1072 self.format_on_new(nsilcmop_desc, session["project_id"], make_public=make_public)
1073 _id = self.db.create("nsilcmops", nsilcmop_desc)
1074 rollback.append({"topic": "nsilcmops", "_id": _id})
1075 self.msg.write("nsi", operation, nsilcmop_desc)
1076 return _id
1077 except ValidationError as e:
1078 raise EngineException(e, HTTPStatus.UNPROCESSABLE_ENTITY)
1079 # except DbException as e:
1080 # raise EngineException("Cannot get nsi_instance '{}': {}".format(e), HTTPStatus.NOT_FOUND)
1081
1082 def delete(self, session, _id, force=False, dry_run=False):
1083 raise EngineException("Method delete called directly", HTTPStatus.INTERNAL_SERVER_ERROR)
1084
1085 def edit(self, session, _id, indata=None, kwargs=None, force=False, content=None):
1086 raise EngineException("Method edit called directly", HTTPStatus.INTERNAL_SERVER_ERROR)