d54187dce5d0e9319c84332d8bcac1cdf321f7ae
2 # -*- coding: utf-8 -*-
7 import logging
.handlers
12 from lcm_utils
import LcmException
, LcmBase
14 from osm_common
.dbbase
import DbException
, deep_update
15 from osm_common
.fsbase
import FsException
16 from n2vc
.vnf
import N2VC
18 from copy
import deepcopy
19 from http
import HTTPStatus
23 __author__
= "Alfonso Tierno"
28 def __init__(self
, db
, msg
, fs
, lcm_tasks
, ro_config
, vca_config
, loop
):
30 Init, Connect to database, filesystem storage, and messaging
31 :param config: two level dictionary with configuration. Top level should contain 'database', 'storage',
35 self
.logger
= logging
.getLogger('lcm.ns')
37 self
.lcm_tasks
= lcm_tasks
39 super().__init
__(db
, msg
, fs
, self
.logger
)
41 self
.ro_config
= ro_config
45 server
=vca_config
['host'],
46 port
=vca_config
['port'],
47 user
=vca_config
['user'],
48 secret
=vca_config
['secret'],
49 # TODO: This should point to the base folder where charms are stored,
50 # if there is a common one (like object storage). Otherwise, leave
51 # it unset and pass it via DeployCharms
52 # artifacts=vca_config[''],
56 def vnfd2RO(self
, vnfd
, new_id
=None):
58 Converts creates a new vnfd descriptor for RO base on input OSM IM vnfd
59 :param vnfd: input vnfd
60 :param new_id: overrides vnf id if provided
65 vnfd_RO
= deepcopy(vnfd
)
66 vnfd_RO
.pop("_id", None)
67 vnfd_RO
.pop("_admin", None)
69 vnfd_RO
["id"] = new_id
70 for vdu
in vnfd_RO
["vdu"]:
71 if "cloud-init-file" in vdu
:
72 base_folder
= vnfd
["_admin"]["storage"]
73 clout_init_file
= "{}/{}/cloud_init/{}".format(
74 base_folder
["folder"],
75 base_folder
["pkg-dir"],
76 vdu
["cloud-init-file"]
78 ci_file
= self
.fs
.file_open(clout_init_file
, "r")
79 # TODO: detect if binary or text. Propose to read as binary and try to decode to utf8. If fails
80 # convert to base 64 or similar
81 clout_init_content
= ci_file
.read()
84 vdu
.pop("cloud-init-file", None)
85 vdu
["cloud-init"] = clout_init_content
86 # remnove unused by RO configuration, monitoring, scaling
87 vnfd_RO
.pop("vnf-configuration", None)
88 vnfd_RO
.pop("monitoring-param", None)
89 vnfd_RO
.pop("scaling-group-descriptor", None)
91 except FsException
as e
:
92 raise LcmException("Error reading file at vnfd {}: {} ".format(vnfd
["_id"], e
))
97 def n2vc_callback(self
, model_name
, application_name
, status
, message
, n2vc_info
, task
=None):
99 Callback both for charm status change and task completion
100 :param model_name: Charm model name
101 :param application_name: Charm application name
102 :param status: Can be
103 - blocked: The unit needs manual intervention
104 - maintenance: The unit is actively deploying/configuring
105 - waiting: The unit is waiting for another charm to be ready
106 - active: The unit is deployed, configured, and ready
107 - error: The charm has failed and needs attention.
108 - terminated: The charm has been destroyed
111 :param message: detailed message error
112 :param n2vc_info dictionary with information shared with instantiate task. Contains:
115 lcmOperationType: currently "instantiate"
116 deployed: dictionary with {<application>: {operational-status: <status>, detailed-status: <text>}}
117 db_update: dictionary to be filled with the changes to be wrote to database with format key.key.key: value
118 n2vc_event: event used to notify instantiation task that some change has been produced
119 :param task: None for charm status change, or task for completion task callback
123 nsr_id
= n2vc_info
["nsr_id"]
124 deployed
= n2vc_info
["deployed"]
125 db_nsr_update
= n2vc_info
["db_update"]
126 nslcmop_id
= n2vc_info
["nslcmop_id"]
127 ns_operation
= n2vc_info
["lcmOperationType"]
128 n2vc_event
= n2vc_info
["n2vc_event"]
129 logging_text
= "Task ns={} {}={} [n2vc_callback] application={}".format(nsr_id
, ns_operation
, nslcmop_id
,
131 vca_deployed
= deployed
.get(application_name
)
133 self
.logger
.error(logging_text
+ " Not present at nsr._admin.deployed.VCA")
138 self
.logger
.debug(logging_text
+ " task Cancelled")
139 vca_deployed
['operational-status'] = "error"
140 db_nsr_update
["_admin.deployed.VCA.{}.operational-status".format(application_name
)] = "error"
141 vca_deployed
['detailed-status'] = "Task Cancelled"
142 db_nsr_update
["_admin.deployed.VCA.{}.detailed-status".format(application_name
)] = "Task Cancelled"
145 exc
= task
.exception()
147 self
.logger
.error(logging_text
+ " task Exception={}".format(exc
))
148 vca_deployed
['operational-status'] = "error"
149 db_nsr_update
["_admin.deployed.VCA.{}.operational-status".format(application_name
)] = "error"
150 vca_deployed
['detailed-status'] = str(exc
)
151 db_nsr_update
["_admin.deployed.VCA.{}.detailed-status".format(application_name
)] = str(exc
)
153 self
.logger
.debug(logging_text
+ " task Done")
154 # task is Done, but callback is still ongoing. So ignore
157 self
.logger
.debug(logging_text
+ " Enter status={}".format(status
))
158 if vca_deployed
['operational-status'] == status
:
159 return # same status, ignore
160 vca_deployed
['operational-status'] = status
161 db_nsr_update
["_admin.deployed.VCA.{}.operational-status".format(application_name
)] = status
162 vca_deployed
['detailed-status'] = str(message
)
163 db_nsr_update
["_admin.deployed.VCA.{}.detailed-status".format(application_name
)] = str(message
)
165 self
.logger
.critical(logging_text
+ " Enter with bad parameters", exc_info
=True)
167 # wake up instantiate task
169 except Exception as e
:
170 self
.logger
.critical(logging_text
+ " Exception {}".format(e
), exc_info
=True)
172 def ns_params_2_RO(self
, ns_params
, nsd
, vnfd_dict
):
174 Creates a RO ns descriptor from OSM ns_instantite params
175 :param ns_params: OSM instantiate params
176 :return: The RO ns descriptor
180 def vim_account_2_RO(vim_account
):
181 if vim_account
in vim_2_RO
:
182 return vim_2_RO
[vim_account
]
184 db_vim
= self
.db
.get_one("vim_accounts", {"_id": vim_account
})
185 if db_vim
["_admin"]["operationalState"] != "ENABLED":
186 raise LcmException("VIM={} is not available. operationalState={}".format(
187 vim_account
, db_vim
["_admin"]["operationalState"]))
188 RO_vim_id
= db_vim
["_admin"]["deployed"]["RO"]
189 vim_2_RO
[vim_account
] = RO_vim_id
192 def ip_profile_2_RO(ip_profile
):
193 RO_ip_profile
= deepcopy((ip_profile
))
194 if "dns-server" in RO_ip_profile
:
195 if isinstance(RO_ip_profile
["dns-server"], list):
196 RO_ip_profile
["dns-address"] = []
197 for ds
in RO_ip_profile
.pop("dns-server"):
198 RO_ip_profile
["dns-address"].append(ds
['address'])
200 RO_ip_profile
["dns-address"] = RO_ip_profile
.pop("dns-server")
201 if RO_ip_profile
.get("ip-version") == "ipv4":
202 RO_ip_profile
["ip-version"] = "IPv4"
203 if RO_ip_profile
.get("ip-version") == "ipv6":
204 RO_ip_profile
["ip-version"] = "IPv6"
205 if "dhcp-params" in RO_ip_profile
:
206 RO_ip_profile
["dhcp"] = RO_ip_profile
.pop("dhcp-params")
212 # "name": ns_params["nsName"],
213 # "description": ns_params.get("nsDescription"),
214 "datacenter": vim_account_2_RO(ns_params
["vimAccountId"]),
215 # "scenario": ns_params["nsdId"],
219 if ns_params
.get("vduImage"):
220 RO_ns_params
["vduImage"] = ns_params
["vduImage"]
222 if ns_params
.get("ssh-authorized-key"):
223 RO_ns_params
["cloud-config"] = {"key-pairs": ns_params
["ssh-authorized-key"]}
224 if ns_params
.get("vnf"):
225 for vnf_params
in ns_params
["vnf"]:
226 for constituent_vnfd
in nsd
["constituent-vnfd"]:
227 if constituent_vnfd
["member-vnf-index"] == vnf_params
["member-vnf-index"]:
228 vnf_descriptor
= vnfd_dict
[constituent_vnfd
["vnfd-id-ref"]]
231 raise LcmException("Invalid instantiate parameter vnf:member-vnf-index={} is not present at nsd:"
232 "constituent-vnfd".format(vnf_params
["member-vnf-index"]))
233 RO_vnf
= {"vdus": {}, "networks": {}}
234 if vnf_params
.get("vimAccountId"):
235 RO_vnf
["datacenter"] = vim_account_2_RO(vnf_params
["vimAccountId"])
236 if vnf_params
.get("vdu"):
237 for vdu_params
in vnf_params
["vdu"]:
238 RO_vnf
["vdus"][vdu_params
["id"]] = {}
239 if vdu_params
.get("volume"):
240 RO_vnf
["vdus"][vdu_params
["id"]]["devices"] = {}
241 for volume_params
in vdu_params
["volume"]:
242 RO_vnf
["vdus"][vdu_params
["id"]]["devices"][volume_params
["name"]] = {}
243 if volume_params
.get("vim-volume-id"):
244 RO_vnf
["vdus"][vdu_params
["id"]]["devices"][volume_params
["name"]]["vim_id"] = \
245 volume_params
["vim-volume-id"]
246 if vdu_params
.get("interface"):
247 RO_vnf
["vdus"][vdu_params
["id"]]["interfaces"] = {}
248 for interface_params
in vdu_params
["interface"]:
250 RO_vnf
["vdus"][vdu_params
["id"]]["interfaces"][interface_params
["name"]] = RO_interface
251 if interface_params
.get("ip-address"):
252 RO_interface
["ip_address"] = interface_params
["ip-address"]
253 if interface_params
.get("mac-address"):
254 RO_interface
["mac_address"] = interface_params
["mac-address"]
255 if interface_params
.get("floating-ip-required"):
256 RO_interface
["floating-ip"] = interface_params
["floating-ip-required"]
257 if vnf_params
.get("internal-vld"):
258 for internal_vld_params
in vnf_params
["internal-vld"]:
259 RO_vnf
["networks"][internal_vld_params
["name"]] = {}
260 if internal_vld_params
.get("vim-network-name"):
261 RO_vnf
["networks"][internal_vld_params
["name"]]["vim-network-name"] = \
262 internal_vld_params
["vim-network-name"]
263 if internal_vld_params
.get("ip-profile"):
264 RO_vnf
["networks"][internal_vld_params
["name"]]["ip-profile"] = \
265 ip_profile_2_RO(internal_vld_params
["ip-profile"])
266 if internal_vld_params
.get("internal-connection-point"):
267 for icp_params
in internal_vld_params
["internal-connection-point"]:
270 for vdu_descriptor
in vnf_descriptor
["vdu"]:
271 for vdu_interface
in vdu_descriptor
["interface"]:
272 if vdu_interface
.get("internal-connection-point-ref") == icp_params
["id-ref"]:
273 RO_interface_update
= {}
274 if icp_params
.get("ip-address"):
275 RO_interface_update
["ip_address"] = icp_params
["ip-address"]
276 if icp_params
.get("mac-address"):
277 RO_interface_update
["mac_address"] = icp_params
["mac-address"]
278 if RO_interface_update
:
279 RO_vnf_update
= {"vdus": {vdu_descriptor
["id"]: {
280 "interfaces": {vdu_interface
["name"]: RO_interface_update
}}}}
281 deep_update(RO_vnf
, RO_vnf_update
)
287 raise LcmException("Invalid instantiate parameter vnf:member-vnf-index[{}]:"
288 "internal-vld:id-ref={} is not present at vnfd:internal-"
289 "connection-point".format(vnf_params
["member-vnf-index"],
290 icp_params
["id-ref"]))
292 if not RO_vnf
["vdus"]:
294 if not RO_vnf
["networks"]:
295 del RO_vnf
["networks"]
297 RO_ns_params
["vnfs"][vnf_params
["member-vnf-index"]] = RO_vnf
298 if ns_params
.get("vld"):
299 for vld_params
in ns_params
["vld"]:
301 if "ip-profile" in vld_params
:
302 RO_vld
["ip-profile"] = ip_profile_2_RO(vld_params
["ip-profile"])
303 if "vim-network-name" in vld_params
:
305 if isinstance(vld_params
["vim-network-name"], dict):
306 for vim_account
, vim_net
in vld_params
["vim-network-name"].items():
307 RO_vld
["sites"].append({
308 "netmap-use": vim_net
,
309 "datacenter": vim_account_2_RO(vim_account
)
311 else: # isinstance str
312 RO_vld
["sites"].append({"netmap-use": vld_params
["vim-network-name"]})
313 if "vnfd-connection-point-ref" in vld_params
:
314 for cp_params
in vld_params
["vnfd-connection-point-ref"]:
316 for constituent_vnfd
in nsd
["constituent-vnfd"]:
317 if constituent_vnfd
["member-vnf-index"] == cp_params
["member-vnf-index-ref"]:
318 vnf_descriptor
= vnfd_dict
[constituent_vnfd
["vnfd-id-ref"]]
322 "Invalid instantiate parameter vld:vnfd-connection-point-ref:member-vnf-index-ref={} "
323 "is not present at nsd:constituent-vnfd".format(cp_params
["member-vnf-index-ref"]))
325 for vdu_descriptor
in vnf_descriptor
["vdu"]:
326 for interface_descriptor
in vdu_descriptor
["interface"]:
327 if interface_descriptor
.get("external-connection-point-ref") == \
328 cp_params
["vnfd-connection-point-ref"]:
335 "Invalid instantiate parameter vld:vnfd-connection-point-ref:member-vnf-index-ref={}:"
336 "vnfd-connection-point-ref={} is not present at vnfd={}".format(
337 cp_params
["member-vnf-index-ref"],
338 cp_params
["vnfd-connection-point-ref"],
339 vnf_descriptor
["id"]))
341 if cp_params
.get("ip-address"):
342 RO_cp_params
["ip_address"] = cp_params
["ip-address"]
343 if cp_params
.get("mac-address"):
344 RO_cp_params
["mac_address"] = cp_params
["mac-address"]
347 cp_params
["member-vnf-index-ref"]: {
349 vdu_descriptor
["id"]: {
351 interface_descriptor
["name"]: RO_cp_params
357 deep_update(RO_ns_params
["vnfs"], RO_vnf_params
)
359 RO_ns_params
["networks"][vld_params
["name"]] = RO_vld
362 def ns_update_vnfr(self
, db_vnfrs
, nsr_desc_RO
):
364 Updates database vnfr with the RO info, e.g. ip_address, vim_id... Descriptor db_vnfrs is also updated
369 for vnf_index
, db_vnfr
in db_vnfrs
.items():
370 for vnf_RO
in nsr_desc_RO
["vnfs"]:
371 if vnf_RO
["member_vnf_index"] == vnf_index
:
373 db_vnfr
["ip-address"] = vnfr_update
["ip-address"] = vnf_RO
.get("ip_address")
375 for vdur_RO
in vnf_RO
.get("vms", ()):
377 "vim-id": vdur_RO
.get("vim_vm_id"),
378 "ip-address": vdur_RO
.get("ip_address"),
379 "vdu-id-ref": vdur_RO
.get("vdu_osm_id"),
380 "name": vdur_RO
.get("vim_name"),
381 "status": vdur_RO
.get("status"),
382 "status-detailed": vdur_RO
.get("error_msg"),
386 for interface_RO
in vdur_RO
.get("interfaces", ()):
387 vdur
["interfaces"].append({
388 "ip-address": interface_RO
.get("ip_address"),
389 "mac-address": interface_RO
.get("mac_address"),
390 "name": interface_RO
.get("internal_name"),
392 vdur_list
.append(vdur
)
393 db_vnfr
["vdur"] = vnfr_update
["vdur"] = vdur_list
394 self
.update_db_2("vnfrs", db_vnfr
["_id"], vnfr_update
)
398 raise LcmException("ns_update_vnfr: Not found member_vnf_index={} at RO info".format(vnf_index
))
400 async def instantiate(self
, nsr_id
, nslcmop_id
):
401 logging_text
= "Task ns={} instantiate={} ".format(nsr_id
, nslcmop_id
)
402 self
.logger
.debug(logging_text
+ "Enter")
403 # get all needed from database
406 db_nsr_update
= {"_admin.nslcmop": nslcmop_id
}
407 db_nslcmop_update
= {}
408 nslcmop_operation_state
= None
410 RO_descriptor_number
= 0 # number of descriptors created at RO
411 descriptor_id_2_RO
= {} # map between vnfd/nsd id to the id used at RO
415 step
= "Getting nslcmop={} from db".format(nslcmop_id
)
416 db_nslcmop
= self
.db
.get_one("nslcmops", {"_id": nslcmop_id
})
417 step
= "Getting nsr={} from db".format(nsr_id
)
418 db_nsr
= self
.db
.get_one("nsrs", {"_id": nsr_id
})
419 ns_params
= db_nsr
.get("instantiate_params")
421 nsr_name
= db_nsr
["name"] # TODO short-name??
423 # look if previous tasks in process
424 task_name
, task_dependency
= self
.lcm_tasks
.lookfor_related("ns", nsr_id
, nslcmop_id
)
426 step
= db_nslcmop_update
["detailed-status"] = \
427 "Waiting for related tasks to be completed: {}".format(task_name
)
428 self
.logger
.debug(logging_text
+ step
)
429 self
.update_db_2("nslcmops", nslcmop_id
, db_nslcmop_update
)
430 _
, pending
= await asyncio
.wait(task_dependency
, timeout
=3600)
432 raise LcmException("Timeout waiting related tasks to be completed")
435 vnfr_filter
= {"nsr-id-ref": nsr_id
, "member-vnf-index-ref": None}
436 for c_vnf
in nsd
["constituent-vnfd"]:
437 vnfd_id
= c_vnf
["vnfd-id-ref"]
438 vnfr_filter
["member-vnf-index-ref"] = c_vnf
["member-vnf-index"]
439 step
= "Getting vnfr={} of nsr={} from db".format(c_vnf
["member-vnf-index"], nsr_id
)
440 db_vnfrs
[c_vnf
["member-vnf-index"]] = self
.db
.get_one("vnfrs", vnfr_filter
)
441 if vnfd_id
not in needed_vnfd
:
442 step
= "Getting vnfd={} from db".format(vnfd_id
)
443 needed_vnfd
[vnfd_id
] = self
.db
.get_one("vnfds", {"id": vnfd_id
})
445 nsr_lcm
= db_nsr
["_admin"].get("deployed")
447 nsr_lcm
= db_nsr
["_admin"]["deployed"] = {
449 "RO": {"vnfd_id": {}, "nsd_id": None, "nsr_id": None, "nsr_status": "SCHEDULED"},
453 db_nsr_update
["detailed-status"] = "creating"
454 db_nsr_update
["operational-status"] = "init"
456 RO
= ROclient
.ROClient(self
.loop
, **self
.ro_config
)
458 # get vnfds, instantiate at RO
459 for vnfd_id
, vnfd
in needed_vnfd
.items():
460 step
= db_nsr_update
["detailed-status"] = "Creating vnfd={} at RO".format(vnfd_id
)
461 # self.logger.debug(logging_text + step)
462 vnfd_id_RO
= "{}.{}.{}".format(nsr_id
, RO_descriptor_number
, vnfd_id
[:23])
463 descriptor_id_2_RO
[vnfd_id
] = vnfd_id_RO
464 RO_descriptor_number
+= 1
467 vnfd_list
= await RO
.get_list("vnfd", filter_by
={"osm_id": vnfd_id_RO
})
469 db_nsr_update
["_admin.deployed.RO.vnfd_id.{}".format(vnfd_id
)] = vnfd_list
[0]["uuid"]
470 self
.logger
.debug(logging_text
+ "vnfd={} exists at RO. Using RO_id={}".format(
471 vnfd_id
, vnfd_list
[0]["uuid"]))
473 vnfd_RO
= self
.vnfd2RO(vnfd
, vnfd_id_RO
)
474 desc
= await RO
.create("vnfd", descriptor
=vnfd_RO
)
475 db_nsr_update
["_admin.deployed.RO.vnfd_id.{}".format(vnfd_id
)] = desc
["uuid"]
476 db_nsr_update
["_admin.nsState"] = "INSTANTIATED"
477 self
.logger
.debug(logging_text
+ "vnfd={} created at RO. RO_id={}".format(
478 vnfd_id
, desc
["uuid"]))
479 self
.update_db_2("nsrs", nsr_id
, db_nsr_update
)
483 step
= db_nsr_update
["detailed-status"] = "Creating nsd={} at RO".format(nsd_id
)
484 # self.logger.debug(logging_text + step)
486 RO_osm_nsd_id
= "{}.{}.{}".format(nsr_id
, RO_descriptor_number
, nsd_id
[:23])
487 descriptor_id_2_RO
[nsd_id
] = RO_osm_nsd_id
488 RO_descriptor_number
+= 1
489 nsd_list
= await RO
.get_list("nsd", filter_by
={"osm_id": RO_osm_nsd_id
})
491 db_nsr_update
["_admin.deployed.RO.nsd_id"] = RO_nsd_uuid
= nsd_list
[0]["uuid"]
492 self
.logger
.debug(logging_text
+ "nsd={} exists at RO. Using RO_id={}".format(
493 nsd_id
, RO_nsd_uuid
))
495 nsd_RO
= deepcopy(nsd
)
496 nsd_RO
["id"] = RO_osm_nsd_id
497 nsd_RO
.pop("_id", None)
498 nsd_RO
.pop("_admin", None)
499 for c_vnf
in nsd_RO
["constituent-vnfd"]:
500 vnfd_id
= c_vnf
["vnfd-id-ref"]
501 c_vnf
["vnfd-id-ref"] = descriptor_id_2_RO
[vnfd_id
]
502 desc
= await RO
.create("nsd", descriptor
=nsd_RO
)
503 db_nsr_update
["_admin.nsState"] = "INSTANTIATED"
504 db_nsr_update
["_admin.deployed.RO.nsd_id"] = RO_nsd_uuid
= desc
["uuid"]
505 self
.logger
.debug(logging_text
+ "nsd={} created at RO. RO_id={}".format(nsd_id
, RO_nsd_uuid
))
506 self
.update_db_2("nsrs", nsr_id
, db_nsr_update
)
509 # if present use it unless in error status
510 RO_nsr_id
= db_nsr
["_admin"].get("deployed", {}).get("RO", {}).get("nsr_id")
513 step
= db_nsr_update
["detailed-status"] = "Looking for existing ns at RO"
514 # self.logger.debug(logging_text + step + " RO_ns_id={}".format(RO_nsr_id))
515 desc
= await RO
.show("ns", RO_nsr_id
)
516 except ROclient
.ROClientException
as e
:
517 if e
.http_code
!= HTTPStatus
.NOT_FOUND
:
519 RO_nsr_id
= db_nsr_update
["_admin.deployed.RO.nsr_id"] = None
521 ns_status
, ns_status_info
= RO
.check_ns_status(desc
)
522 db_nsr_update
["_admin.deployed.RO.nsr_status"] = ns_status
523 if ns_status
== "ERROR":
524 step
= db_nsr_update
["detailed-status"] = "Deleting ns at RO. RO_ns_id={}".format(RO_nsr_id
)
525 self
.logger
.debug(logging_text
+ step
)
526 await RO
.delete("ns", RO_nsr_id
)
527 RO_nsr_id
= db_nsr_update
["_admin.deployed.RO.nsr_id"] = None
529 step
= db_nsr_update
["detailed-status"] = "Checking dependencies"
530 # self.logger.debug(logging_text + step)
532 # check if VIM is creating and wait look if previous tasks in process
533 task_name
, task_dependency
= self
.lcm_tasks
.lookfor_related("vim_account", ns_params
["vimAccountId"])
535 step
= "Waiting for related tasks to be completed: {}".format(task_name
)
536 self
.logger
.debug(logging_text
+ step
)
537 await asyncio
.wait(task_dependency
, timeout
=3600)
538 if ns_params
.get("vnf"):
539 for vnf
in ns_params
["vnf"]:
540 if "vimAccountId" in vnf
:
541 task_name
, task_dependency
= self
.lcm_tasks
.lookfor_related("vim_account",
544 step
= "Waiting for related tasks to be completed: {}".format(task_name
)
545 self
.logger
.debug(logging_text
+ step
)
546 await asyncio
.wait(task_dependency
, timeout
=3600)
548 step
= db_nsr_update
["detailed-status"] = "Checking instantiation parameters"
549 RO_ns_params
= self
.ns_params_2_RO(ns_params
, nsd
, needed_vnfd
)
551 n2vc_key
= await self
.n2vc
.GetPublicKey()
552 RO_ns_params
["mgmt_keys"] = [n2vc_key
]
553 # TODO feature 1429. Add this option only to VMs with configuration and no password
555 step
= db_nsr_update
["detailed-status"] = "Creating ns at RO"
556 desc
= await RO
.create("ns", descriptor
=RO_ns_params
,
558 scenario
=RO_nsd_uuid
)
559 RO_nsr_id
= db_nsr_update
["_admin.deployed.RO.nsr_id"] = desc
["uuid"]
560 db_nsr_update
["_admin.nsState"] = "INSTANTIATED"
561 db_nsr_update
["_admin.deployed.RO.nsr_status"] = "BUILD"
562 self
.logger
.debug(logging_text
+ "ns created at RO. RO_id={}".format(desc
["uuid"]))
563 self
.update_db_2("nsrs", nsr_id
, db_nsr_update
)
565 # update VNFR vimAccount
566 step
= "Updating VNFR vimAcccount"
567 for vnf_index
, vnfr
in db_vnfrs
.items():
568 if vnfr
.get("vim-account-id"):
570 vnfr_update
= {"vim-account-id": db_nsr
["instantiate_params"]["vimAccountId"]}
571 if db_nsr
["instantiate_params"].get("vnf"):
572 for vnf_params
in db_nsr
["instantiate_params"]["vnf"]:
573 if vnf_params
.get("member-vnf-index") == vnf_index
:
574 if vnf_params
.get("vimAccountId"):
575 vnfr_update
["vim-account-id"] = vnf_params
.get("vimAccountId")
577 self
.update_db_2("vnfrs", vnfr
["_id"], vnfr_update
)
579 # wait until NS is ready
580 step
= ns_status_detailed
= detailed_status
= "Waiting ns ready at RO. RO_id={}".format(RO_nsr_id
)
581 detailed_status_old
= None
582 self
.logger
.debug(logging_text
+ step
)
584 deployment_timeout
= 2 * 3600 # Two hours
585 while deployment_timeout
> 0:
586 desc
= await RO
.show("ns", RO_nsr_id
)
587 ns_status
, ns_status_info
= RO
.check_ns_status(desc
)
588 db_nsr_update
["admin.deployed.RO.nsr_status"] = ns_status
589 if ns_status
== "ERROR":
590 raise ROclient
.ROClientException(ns_status_info
)
591 elif ns_status
== "BUILD":
592 detailed_status
= ns_status_detailed
+ "; {}".format(ns_status_info
)
593 elif ns_status
== "ACTIVE":
594 step
= detailed_status
= "Waiting for management IP address reported by the VIM"
596 nsr_lcm
["nsr_ip"] = RO
.get_ns_vnf_info(desc
)
598 except ROclient
.ROClientException
as e
:
599 if e
.http_code
!= 409: # IP address is not ready return code is 409 CONFLICT
602 assert False, "ROclient.check_ns_status returns unknown {}".format(ns_status
)
603 if detailed_status
!= detailed_status_old
:
604 detailed_status_old
= db_nsr_update
["detailed-status"] = detailed_status
605 self
.update_db_2("nsrs", nsr_id
, db_nsr_update
)
606 await asyncio
.sleep(5, loop
=self
.loop
)
607 deployment_timeout
-= 5
608 if deployment_timeout
<= 0:
609 raise ROclient
.ROClientException("Timeout waiting ns to be ready")
611 step
= "Updating VNFRs"
612 self
.ns_update_vnfr(db_vnfrs
, desc
)
614 db_nsr
["detailed-status"] = "Configuring vnfr"
615 self
.update_db_2("nsrs", nsr_id
, db_nsr_update
)
617 # The parameters we'll need to deploy a charm
618 number_to_configure
= 0
620 def deploy(vnf_index
, vdu_id
, mgmt_ip_address
, n2vc_info
, config_primitive
=None):
621 """An inner function to deploy the charm from either vnf or vdu
622 vnf_index is mandatory. vdu_id can be None for a vnf configuration or the id for vdu configuration
624 if not mgmt_ip_address
:
625 raise LcmException("vnfd/vdu has not management ip address to configure it")
627 # if number_to_configure == 0:
628 # self.logger.debug("Logging into N2VC...")
629 # task = asyncio.ensure_future(self.n2vc.login())
630 # yield from asyncio.wait_for(task, 30.0)
631 # self.logger.debug("Logged into N2VC!")
633 # # await self.n2vc.login()
635 # Note: The charm needs to exist on disk at the location
636 # specified by charm_path.
637 base_folder
= vnfd
["_admin"]["storage"]
638 storage_params
= self
.fs
.get_params()
639 charm_path
= "{}{}/{}/charms/{}".format(
640 storage_params
["path"],
641 base_folder
["folder"],
642 base_folder
["pkg-dir"],
646 # Setup the runtime parameters for this VNF
647 params
= {'rw_mgmt_ip': mgmt_ip_address
}
649 params
["initial-config-primitive"] = config_primitive
651 # ns_name will be ignored in the current version of N2VC
652 # but will be implemented for the next point release.
653 model_name
= 'default'
657 application_name
= self
.n2vc
.FormatApplicationName(
662 if not nsr_lcm
.get("VCA"):
664 nsr_lcm
["VCA"][application_name
] = db_nsr_update
["_admin.deployed.VCA.{}".format(application_name
)] = {
665 "member-vnf-index": vnf_index
,
668 "application": application_name
,
669 "operational-status": "init",
670 "detailed-status": "",
673 self
.update_db_2("nsrs", nsr_id
, db_nsr_update
)
675 self
.logger
.debug("Task create_ns={} Passing artifacts path '{}' for {}".format(nsr_id
, charm_path
,
678 n2vc_info
["nsr_id"] = nsr_id
679 n2vc_info
["nslcmop_id"] = nslcmop_id
680 n2vc_info
["n2vc_event"] = asyncio
.Event(loop
=self
.loop
)
681 n2vc_info
["lcmOperationType"] = "instantiate"
682 n2vc_info
["deployed"] = nsr_lcm
["VCA"]
683 n2vc_info
["db_update"] = db_nsr_update
684 task
= asyncio
.ensure_future(
685 self
.n2vc
.DeployCharms(
686 model_name
, # The network service name
687 application_name
, # The application name
688 vnfd
, # The vnf descriptor
689 charm_path
, # Path to charm
690 params
, # Runtime params, like mgmt ip
691 {}, # for native charms only
692 self
.n2vc_callback
, # Callback for status changes
693 n2vc_info
, # Callback parameter
694 None, # Callback parameter (task)
697 task
.add_done_callback(functools
.partial(self
.n2vc_callback
, model_name
, application_name
, None, None,
699 self
.lcm_tasks
.register("ns", nsr_id
, nslcmop_id
, "create_charm:" + application_name
, task
)
701 step
= "Looking for needed vnfd to configure"
702 self
.logger
.debug(logging_text
+ step
)
704 for c_vnf
in nsd
["constituent-vnfd"]:
705 vnfd_id
= c_vnf
["vnfd-id-ref"]
706 vnf_index
= str(c_vnf
["member-vnf-index"])
707 vnfd
= needed_vnfd
[vnfd_id
]
709 # Check if this VNF has a charm configuration
710 vnf_config
= vnfd
.get("vnf-configuration")
712 if vnf_config
and vnf_config
.get("juju"):
713 proxy_charm
= vnf_config
["juju"]["charm"]
714 config_primitive
= None
717 if 'initial-config-primitive' in vnf_config
:
718 config_primitive
= vnf_config
['initial-config-primitive']
720 # Login to the VCA. If there are multiple calls to login(),
721 # subsequent calls will be a nop and return immediately.
722 step
= "connecting to N2VC to configure vnf {}".format(vnf_index
)
723 await self
.n2vc
.login()
724 deploy(vnf_index
, None, db_vnfrs
[vnf_index
]["ip-address"], n2vc_info
, config_primitive
)
725 number_to_configure
+= 1
727 # Deploy charms for each VDU that supports one.
729 for vdu
in vnfd
['vdu']:
730 vdu_config
= vdu
.get('vdu-configuration')
732 config_primitive
= None
734 if vdu_config
and vdu_config
.get("juju"):
735 proxy_charm
= vdu_config
["juju"]["charm"]
737 if 'initial-config-primitive' in vdu_config
:
738 config_primitive
= vdu_config
['initial-config-primitive']
741 step
= "connecting to N2VC to configure vdu {} from vnf {}".format(vdu
["id"], vnf_index
)
742 await self
.n2vc
.login()
743 deploy(vnf_index
, vdu
["id"], db_vnfrs
[vnf_index
]["vdur"][vdu_index
]["ip-address"],
744 n2vc_info
, config_primitive
)
745 number_to_configure
+= 1
748 db_nsr_update
["operational-status"] = "running"
749 configuration_failed
= False
750 if number_to_configure
:
751 old_status
= "configuring: init: {}".format(number_to_configure
)
752 db_nsr_update
["config-status"] = old_status
753 db_nsr_update
["detailed-status"] = old_status
754 db_nslcmop_update
["detailed-status"] = old_status
756 # wait until all are configured.
759 self
.update_db_2("nsrs", nsr_id
, db_nsr_update
)
760 if db_nslcmop_update
:
761 self
.update_db_2("nslcmops", nslcmop_id
, db_nslcmop_update
)
762 await n2vc_info
["n2vc_event"].wait()
763 n2vc_info
["n2vc_event"].clear()
766 n2vc_error_text
= [] # contain text error list. If empty no one is in error status
767 for _
, vca_info
in nsr_lcm
["VCA"].items():
768 vca_status
= vca_info
["operational-status"]
769 if vca_status
not in status_map
:
771 status_map
[vca_status
] = 0
772 status_map
[vca_status
] += 1
774 if vca_status
!= "active":
776 if vca_status
in ("error", "blocked"):
777 n2vc_error_text
.append(
778 "member_vnf_index={} vdu_id={} {}: {}".format(vca_info
["member-vnf-index"],
779 vca_info
["vdu_id"], vca_status
,
780 vca_info
["detailed-status"]))
784 elif n2vc_error_text
:
785 db_nsr_update
["config-status"] = "failed"
786 error_text
= "fail configuring " + ";".join(n2vc_error_text
)
787 db_nsr_update
["detailed-status"] = error_text
788 db_nslcmop_update
["operationState"] = nslcmop_operation_state
= "FAILED_TEMP"
789 db_nslcmop_update
["detailed-status"] = error_text
790 db_nslcmop_update
["statusEnteredTime"] = time()
791 configuration_failed
= True
796 for status
, num
in status_map
.items():
797 cs
+= separator
+ "{}: {}".format(status
, num
)
800 db_nsr_update
["config-status"] = cs
801 db_nsr_update
["detailed-status"] = cs
802 db_nslcmop_update
["detailed-status"] = cs
805 if not configuration_failed
:
807 db_nslcmop_update
["operationState"] = nslcmop_operation_state
= "COMPLETED"
808 db_nslcmop_update
["statusEnteredTime"] = time()
809 db_nslcmop_update
["detailed-status"] = "done"
810 db_nsr_update
["config-status"] = "configured"
811 db_nsr_update
["detailed-status"] = "done"
815 except (ROclient
.ROClientException
, DbException
, LcmException
) as e
:
816 self
.logger
.error(logging_text
+ "Exit Exception while '{}': {}".format(step
, e
))
818 except asyncio
.CancelledError
:
819 self
.logger
.error(logging_text
+ "Cancelled Exception while '{}'".format(step
))
820 exc
= "Operation was cancelled"
821 except Exception as e
:
822 exc
= traceback
.format_exc()
823 self
.logger
.critical(logging_text
+ "Exit Exception {} while '{}': {}".format(type(e
).__name
__, step
, e
),
828 db_nsr_update
["detailed-status"] = "ERROR {}: {}".format(step
, exc
)
829 db_nsr_update
["operational-status"] = "failed"
831 db_nslcmop_update
["detailed-status"] = "FAILED {}: {}".format(step
, exc
)
832 db_nslcmop_update
["operationState"] = nslcmop_operation_state
= "FAILED"
833 db_nslcmop_update
["statusEnteredTime"] = time()
835 db_nsr_update
["_admin.nslcmop"] = None
836 self
.update_db_2("nsrs", nsr_id
, db_nsr_update
)
837 if db_nslcmop_update
:
838 self
.update_db_2("nslcmops", nslcmop_id
, db_nslcmop_update
)
839 if nslcmop_operation_state
:
841 await self
.msg
.aiowrite("ns", "instantiated", {"nsr_id": nsr_id
, "nslcmop_id": nslcmop_id
,
842 "operationState": nslcmop_operation_state
})
843 except Exception as e
:
844 self
.logger
.error(logging_text
+ "kafka_write notification Exception {}".format(e
))
846 self
.logger
.debug(logging_text
+ "Exit")
847 self
.lcm_tasks
.remove("ns", nsr_id
, nslcmop_id
, "ns_instantiate")
849 async def terminate(self
, nsr_id
, nslcmop_id
):
850 logging_text
= "Task ns={} terminate={} ".format(nsr_id
, nslcmop_id
)
851 self
.logger
.debug(logging_text
+ "Enter")
855 failed_detail
= [] # annotates all failed error messages
858 db_nsr_update
= {"_admin.nslcmop": nslcmop_id
}
859 db_nslcmop_update
= {}
860 nslcmop_operation_state
= None
862 step
= "Getting nslcmop={} from db".format(nslcmop_id
)
863 db_nslcmop
= self
.db
.get_one("nslcmops", {"_id": nslcmop_id
})
864 step
= "Getting nsr={} from db".format(nsr_id
)
865 db_nsr
= self
.db
.get_one("nsrs", {"_id": nsr_id
})
866 # nsd = db_nsr["nsd"]
867 nsr_lcm
= deepcopy(db_nsr
["_admin"].get("deployed"))
868 if db_nsr
["_admin"]["nsState"] == "NOT_INSTANTIATED":
871 # db_vim = self.db.get_one("vim_accounts", {"_id": db_nsr["datacenter"]})
872 # #TODO check if VIM is creating and wait
873 # RO_vim_id = db_vim["_admin"]["deployed"]["RO"]
875 db_nsr_update
["operational-status"] = "terminating"
876 db_nsr_update
["config-status"] = "terminating"
878 if nsr_lcm
and nsr_lcm
.get("VCA"):
880 step
= "Scheduling configuration charms removing"
881 db_nsr_update
["detailed-status"] = "Deleting charms"
882 self
.logger
.debug(logging_text
+ step
)
883 self
.update_db_2("nsrs", nsr_id
, db_nsr_update
)
884 for application_name
, deploy_info
in nsr_lcm
["VCA"].items():
885 if deploy_info
: # TODO it would be desirable having a and deploy_info.get("deployed"):
886 task
= asyncio
.ensure_future(
887 self
.n2vc
.RemoveCharms(
888 deploy_info
['model'],
890 # self.n2vc_callback,
895 vca_task_list
.append(task
)
896 vca_task_dict
[application_name
] = task
897 # task.add_done_callback(functools.partial(self.n2vc_callback, deploy_info['model'],
898 # deploy_info['application'], None, db_nsr,
899 # db_nslcmop, vnf_index))
900 self
.lcm_tasks
.register("ns", nsr_id
, nslcmop_id
, "delete_charm:" + application_name
, task
)
901 except Exception as e
:
902 self
.logger
.debug(logging_text
+ "Failed while deleting charms: {}".format(e
))
906 RO
= ROclient
.ROClient(self
.loop
, **self
.ro_config
)
909 RO_nsr_id
= RO_delete_action
= None
910 if nsr_lcm
and nsr_lcm
.get("RO"):
911 RO_nsr_id
= nsr_lcm
["RO"].get("nsr_id")
912 RO_delete_action
= nsr_lcm
["RO"].get("nsr_delete_action_id")
915 step
= db_nsr_update
["detailed-status"] = db_nslcmop_update
["detailed-status"] = "Deleting ns at RO"
916 self
.logger
.debug(logging_text
+ step
)
917 desc
= await RO
.delete("ns", RO_nsr_id
)
918 RO_delete_action
= desc
["action_id"]
919 db_nsr_update
["_admin.deployed.RO.nsr_delete_action_id"] = RO_delete_action
920 db_nsr_update
["_admin.deployed.RO.nsr_id"] = None
921 db_nsr_update
["_admin.deployed.RO.nsr_status"] = "DELETED"
923 # wait until NS is deleted from VIM
924 step
= detailed_status
= "Waiting ns deleted from VIM. RO_id={}".format(RO_nsr_id
)
925 detailed_status_old
= None
926 self
.logger
.debug(logging_text
+ step
)
928 delete_timeout
= 20 * 60 # 20 minutes
929 while delete_timeout
> 0:
930 desc
= await RO
.show("ns", item_id_name
=RO_nsr_id
, extra_item
="action",
931 extra_item_id
=RO_delete_action
)
932 ns_status
, ns_status_info
= RO
.check_action_status(desc
)
933 if ns_status
== "ERROR":
934 raise ROclient
.ROClientException(ns_status_info
)
935 elif ns_status
== "BUILD":
936 detailed_status
= step
+ "; {}".format(ns_status_info
)
937 elif ns_status
== "ACTIVE":
940 assert False, "ROclient.check_action_status returns unknown {}".format(ns_status
)
941 await asyncio
.sleep(5, loop
=self
.loop
)
943 if detailed_status
!= detailed_status_old
:
944 detailed_status_old
= db_nslcmop_update
["detailed-status"] = detailed_status
945 self
.update_db_2("nslcmops", nslcmop_id
, db_nslcmop_update
)
946 else: # delete_timeout <= 0:
947 raise ROclient
.ROClientException("Timeout waiting ns deleted from VIM")
949 except ROclient
.ROClientException
as e
:
950 if e
.http_code
== 404: # not found
951 db_nsr_update
["_admin.deployed.RO.nsr_id"] = None
952 db_nsr_update
["_admin.deployed.RO.nsr_status"] = "DELETED"
953 self
.logger
.debug(logging_text
+ "RO_ns_id={} already deleted".format(RO_nsr_id
))
954 elif e
.http_code
== 409: # conflict
955 failed_detail
.append("RO_ns_id={} delete conflict: {}".format(RO_nsr_id
, e
))
956 self
.logger
.debug(logging_text
+ failed_detail
[-1])
959 failed_detail
.append("RO_ns_id={} delete error: {}".format(RO_nsr_id
, e
))
960 self
.logger
.error(logging_text
+ failed_detail
[-1])
964 if not RO_fail
and nsr_lcm
and nsr_lcm
.get("RO") and nsr_lcm
["RO"].get("nsd_id"):
965 RO_nsd_id
= nsr_lcm
["RO"]["nsd_id"]
967 step
= db_nsr_update
["detailed-status"] = db_nslcmop_update
["detailed-status"] =\
969 await RO
.delete("nsd", RO_nsd_id
)
970 self
.logger
.debug(logging_text
+ "RO_nsd_id={} deleted".format(RO_nsd_id
))
971 db_nsr_update
["_admin.deployed.RO.nsd_id"] = None
972 except ROclient
.ROClientException
as e
:
973 if e
.http_code
== 404: # not found
974 db_nsr_update
["_admin.deployed.RO.nsd_id"] = None
975 self
.logger
.debug(logging_text
+ "RO_nsd_id={} already deleted".format(RO_nsd_id
))
976 elif e
.http_code
== 409: # conflict
977 failed_detail
.append("RO_nsd_id={} delete conflict: {}".format(RO_nsd_id
, e
))
978 self
.logger
.debug(logging_text
+ failed_detail
[-1])
981 failed_detail
.append("RO_nsd_id={} delete error: {}".format(RO_nsd_id
, e
))
982 self
.logger
.error(logging_text
+ failed_detail
[-1])
985 if not RO_fail
and nsr_lcm
and nsr_lcm
.get("RO") and nsr_lcm
["RO"].get("vnfd_id"):
986 for vnf_id
, RO_vnfd_id
in nsr_lcm
["RO"]["vnfd_id"].items():
990 step
= db_nsr_update
["detailed-status"] = db_nslcmop_update
["detailed-status"] =\
991 "Deleting vnfd={} at RO".format(vnf_id
)
992 await RO
.delete("vnfd", RO_vnfd_id
)
993 self
.logger
.debug(logging_text
+ "RO_vnfd_id={} deleted".format(RO_vnfd_id
))
994 db_nsr_update
["_admin.deployed.RO.vnfd_id.{}".format(vnf_id
)] = None
995 except ROclient
.ROClientException
as e
:
996 if e
.http_code
== 404: # not found
997 db_nsr_update
["_admin.deployed.RO.vnfd_id.{}".format(vnf_id
)] = None
998 self
.logger
.debug(logging_text
+ "RO_vnfd_id={} already deleted ".format(RO_vnfd_id
))
999 elif e
.http_code
== 409: # conflict
1000 failed_detail
.append("RO_vnfd_id={} delete conflict: {}".format(RO_vnfd_id
, e
))
1001 self
.logger
.debug(logging_text
+ failed_detail
[-1])
1003 failed_detail
.append("RO_vnfd_id={} delete error: {}".format(RO_vnfd_id
, e
))
1004 self
.logger
.error(logging_text
+ failed_detail
[-1])
1007 db_nsr_update
["detailed-status"] = db_nslcmop_update
["detailed-status"] =\
1008 "Waiting for deletion of configuration charms"
1009 self
.update_db_2("nslcmops", nslcmop_id
, db_nslcmop_update
)
1010 self
.update_db_2("nsrs", nsr_id
, db_nsr_update
)
1011 await asyncio
.wait(vca_task_list
, timeout
=300)
1012 for application_name
, task
in vca_task_dict
.items():
1013 if task
.cancelled():
1014 failed_detail
.append("VCA[{}] Deletion has been cancelled".format(application_name
))
1016 exc
= task
.exception()
1018 failed_detail
.append("VCA[{}] Deletion exception: {}".format(application_name
, exc
))
1020 db_nsr_update
["_admin.deployed.VCA.{}".format(application_name
)] = None
1022 # TODO Should it be cancelled?!!
1024 failed_detail
.append("VCA[{}] Deletion timeout".format(application_name
))
1027 self
.logger
.error(logging_text
+ " ;".join(failed_detail
))
1028 db_nsr_update
["operational-status"] = "failed"
1029 db_nsr_update
["detailed-status"] = "Deletion errors " + "; ".join(failed_detail
)
1030 db_nslcmop_update
["detailed-status"] = "; ".join(failed_detail
)
1031 db_nslcmop_update
["operationState"] = nslcmop_operation_state
= "FAILED"
1032 db_nslcmop_update
["statusEnteredTime"] = time()
1033 elif db_nslcmop
["operationParams"].get("autoremove"):
1034 self
.db
.del_one("nsrs", {"_id": nsr_id
})
1035 db_nsr_update
.clear()
1036 self
.db
.del_list("nslcmops", {"nsInstanceId": nsr_id
})
1037 nslcmop_operation_state
= "COMPLETED"
1038 db_nslcmop_update
.clear()
1039 self
.db
.del_list("vnfrs", {"nsr-id-ref": nsr_id
})
1040 self
.logger
.debug(logging_text
+ "Delete from database")
1042 db_nsr_update
["operational-status"] = "terminated"
1043 db_nsr_update
["detailed-status"] = "Done"
1044 db_nsr_update
["_admin.nsState"] = "NOT_INSTANTIATED"
1045 db_nslcmop_update
["detailed-status"] = "Done"
1046 db_nslcmop_update
["operationState"] = nslcmop_operation_state
= "COMPLETED"
1047 db_nslcmop_update
["statusEnteredTime"] = time()
1049 except (ROclient
.ROClientException
, DbException
) as e
:
1050 self
.logger
.error(logging_text
+ "Exit Exception {}".format(e
))
1052 except asyncio
.CancelledError
:
1053 self
.logger
.error(logging_text
+ "Cancelled Exception while '{}'".format(step
))
1054 exc
= "Operation was cancelled"
1055 except Exception as e
:
1056 exc
= traceback
.format_exc()
1057 self
.logger
.critical(logging_text
+ "Exit Exception {}".format(e
), exc_info
=True)
1059 if exc
and db_nslcmop
:
1060 db_nslcmop_update
["detailed-status"] = "FAILED {}: {}".format(step
, exc
)
1061 db_nslcmop_update
["operationState"] = nslcmop_operation_state
= "FAILED"
1062 db_nslcmop_update
["statusEnteredTime"] = time()
1063 if db_nslcmop_update
:
1064 self
.update_db_2("nslcmops", nslcmop_id
, db_nslcmop_update
)
1066 db_nsr_update
["_admin.nslcmop"] = None
1067 self
.update_db_2("nsrs", nsr_id
, db_nsr_update
)
1068 if nslcmop_operation_state
:
1070 await self
.msg
.aiowrite("ns", "terminated", {"nsr_id": nsr_id
, "nslcmop_id": nslcmop_id
,
1071 "operationState": nslcmop_operation_state
})
1072 except Exception as e
:
1073 self
.logger
.error(logging_text
+ "kafka_write notification Exception {}".format(e
))
1074 self
.logger
.debug(logging_text
+ "Exit")
1075 self
.lcm_tasks
.remove("ns", nsr_id
, nslcmop_id
, "ns_terminate")
1077 async def _ns_execute_primitive(self
, db_deployed
, nsr_name
, member_vnf_index
, vdu_id
, primitive
, primitive_params
):
1079 vdu_id_text
= "vnfd"
1081 vdu_id_text
= vdu_id
1082 application_name
= self
.n2vc
.FormatApplicationName(
1087 vca_deployed
= db_deployed
["VCA"].get(application_name
)
1088 if not vca_deployed
:
1089 raise LcmException("charm for member_vnf_index={} vdu_id={} is not deployed".format(member_vnf_index
,
1091 model_name
= vca_deployed
.get("model")
1092 application_name
= vca_deployed
.get("application")
1093 if not model_name
or not application_name
:
1094 raise LcmException("charm for member_vnf_index={} is not properly deployed".format(member_vnf_index
))
1095 if vca_deployed
["operational-status"] != "active":
1096 raise LcmException("charm for member_vnf_index={} operational_status={} not 'active'".format(
1097 member_vnf_index
, vca_deployed
["operational-status"]))
1098 callback
= None # self.n2vc_callback
1099 callback_args
= () # [db_nsr, db_nslcmop, member_vnf_index, None]
1100 await self
.n2vc
.login()
1101 task
= asyncio
.ensure_future(
1102 self
.n2vc
.ExecutePrimitive(
1105 primitive
, callback
,
1110 # task.add_done_callback(functools.partial(self.n2vc_callback, model_name, application_name, None,
1111 # db_nsr, db_nslcmop, member_vnf_index))
1112 # self.lcm_tasks.register("ns", nsr_id, nslcmop_id, "action:" + primitive, task)
1113 # wait until completed with timeout
1114 await asyncio
.wait((task
,), timeout
=600)
1116 result
= "FAILED" # by default
1118 if task
.cancelled():
1119 result_detail
= "Task has been cancelled"
1121 exc
= task
.exception()
1123 result_detail
= str(exc
)
1125 # TODO revise with Adam if action is finished and ok when task is done or callback is needed
1126 result
= "COMPLETED"
1127 result_detail
= "Done"
1129 # TODO Should it be cancelled?!!
1131 result_detail
= "timeout"
1132 return result
, result_detail
1134 async def action(self
, nsr_id
, nslcmop_id
):
1135 logging_text
= "Task ns={} action={} ".format(nsr_id
, nslcmop_id
)
1136 self
.logger
.debug(logging_text
+ "Enter")
1137 # get all needed from database
1140 db_nsr_update
= {"_admin.nslcmop": nslcmop_id
}
1141 db_nslcmop_update
= {}
1142 nslcmop_operation_state
= None
1145 step
= "Getting information from database"
1146 db_nslcmop
= self
.db
.get_one("nslcmops", {"_id": nslcmop_id
})
1147 db_nsr
= self
.db
.get_one("nsrs", {"_id": nsr_id
})
1148 nsr_lcm
= db_nsr
["_admin"].get("deployed")
1149 nsr_name
= db_nsr
["name"]
1150 vnf_index
= db_nslcmop
["operationParams"]["member_vnf_index"]
1151 vdu_id
= db_nslcmop
["operationParams"].get("vdu_id")
1153 # look if previous tasks in process
1154 task_name
, task_dependency
= self
.lcm_tasks
.lookfor_related("ns", nsr_id
, nslcmop_id
)
1156 step
= db_nslcmop_update
["detailed-status"] = \
1157 "Waiting for related tasks to be completed: {}".format(task_name
)
1158 self
.logger
.debug(logging_text
+ step
)
1159 self
.update_db_2("nslcmops", nslcmop_id
, db_nslcmop_update
)
1160 _
, pending
= await asyncio
.wait(task_dependency
, timeout
=3600)
1162 raise LcmException("Timeout waiting related tasks to be completed")
1164 # TODO check if ns is in a proper status
1165 primitive
= db_nslcmop
["operationParams"]["primitive"]
1166 primitive_params
= db_nslcmop
["operationParams"]["primitive_params"]
1167 result
, result_detail
= await self
._ns
_execute
_primitive
(nsr_lcm
, nsr_name
, vnf_index
, vdu_id
, primitive
,
1169 db_nslcmop_update
["detailed-status"] = result_detail
1170 db_nslcmop_update
["operationState"] = nslcmop_operation_state
= result
1171 db_nslcmop_update
["statusEnteredTime"] = time()
1172 self
.logger
.debug(logging_text
+ " task Done with result {} {}".format(result
, result_detail
))
1173 return # database update is called inside finally
1175 except (DbException
, LcmException
) as e
:
1176 self
.logger
.error(logging_text
+ "Exit Exception {}".format(e
))
1178 except asyncio
.CancelledError
:
1179 self
.logger
.error(logging_text
+ "Cancelled Exception while '{}'".format(step
))
1180 exc
= "Operation was cancelled"
1181 except Exception as e
:
1182 exc
= traceback
.format_exc()
1183 self
.logger
.critical(logging_text
+ "Exit Exception {} {}".format(type(e
).__name
__, e
), exc_info
=True)
1185 if exc
and db_nslcmop
:
1186 db_nslcmop_update
["detailed-status"] = "FAILED {}: {}".format(step
, exc
)
1187 db_nslcmop_update
["operationState"] = nslcmop_operation_state
= "FAILED"
1188 db_nslcmop_update
["statusEnteredTime"] = time()
1189 if db_nslcmop_update
:
1190 self
.update_db_2("nslcmops", nslcmop_id
, db_nslcmop_update
)
1192 db_nsr_update
["_admin.nslcmop"] = None
1193 self
.update_db_2("nsrs", nsr_id
, db_nsr_update
)
1194 self
.logger
.debug(logging_text
+ "Exit")
1195 if nslcmop_operation_state
:
1197 await self
.msg
.aiowrite("ns", "actioned", {"nsr_id": nsr_id
, "nslcmop_id": nslcmop_id
,
1198 "operationState": nslcmop_operation_state
})
1199 except Exception as e
:
1200 self
.logger
.error(logging_text
+ "kafka_write notification Exception {}".format(e
))
1201 self
.logger
.debug(logging_text
+ "Exit")
1202 self
.lcm_tasks
.remove("ns", nsr_id
, nslcmop_id
, "ns_action")
1204 async def scale(self
, nsr_id
, nslcmop_id
):
1205 logging_text
= "Task ns={} scale={} ".format(nsr_id
, nslcmop_id
)
1206 self
.logger
.debug(logging_text
+ "Enter")
1207 # get all needed from database
1210 db_nslcmop_update
= {}
1211 nslcmop_operation_state
= None
1212 db_nsr_update
= {"_admin.nslcmop": nslcmop_id
}
1214 # in case of error, indicates what part of scale was failed to put nsr at error status
1215 scale_process
= None
1216 old_operational_status
= ""
1217 old_config_status
= ""
1219 step
= "Getting nslcmop from database"
1220 db_nslcmop
= self
.db
.get_one("nslcmops", {"_id": nslcmop_id
})
1221 step
= "Getting nsr from database"
1222 db_nsr
= self
.db
.get_one("nsrs", {"_id": nsr_id
})
1223 old_operational_status
= db_nsr
["operational-status"]
1224 old_config_status
= db_nsr
["config-status"]
1226 # look if previous tasks in process
1227 task_name
, task_dependency
= self
.lcm_tasks
.lookfor_related("ns", nsr_id
, nslcmop_id
)
1229 step
= db_nslcmop_update
["detailed-status"] = \
1230 "Waiting for related tasks to be completed: {}".format(task_name
)
1231 self
.logger
.debug(logging_text
+ step
)
1232 self
.update_db_2("nslcmops", nslcmop_id
, db_nslcmop_update
)
1233 _
, pending
= await asyncio
.wait(task_dependency
, timeout
=3600)
1235 raise LcmException("Timeout waiting related tasks to be completed")
1237 step
= "Parsing scaling parameters"
1238 db_nsr_update
["operational-status"] = "scaling"
1239 self
.update_db_2("nsrs", nsr_id
, db_nsr_update
)
1240 nsr_lcm
= db_nsr
["_admin"].get("deployed")
1241 RO_nsr_id
= nsr_lcm
["RO"]["nsr_id"]
1242 vnf_index
= db_nslcmop
["operationParams"]["scaleVnfData"]["scaleByStepData"]["member-vnf-index"]
1243 scaling_group
= db_nslcmop
["operationParams"]["scaleVnfData"]["scaleByStepData"]["scaling-group-descriptor"]
1244 scaling_type
= db_nslcmop
["operationParams"]["scaleVnfData"]["scaleVnfType"]
1245 # scaling_policy = db_nslcmop["operationParams"]["scaleVnfData"]["scaleByStepData"].get("scaling-policy")
1247 step
= "Getting vnfr from database"
1248 db_vnfr
= self
.db
.get_one("vnfrs", {"member-vnf-index-ref": vnf_index
, "nsr-id-ref": nsr_id
})
1249 step
= "Getting vnfd from database"
1250 db_vnfd
= self
.db
.get_one("vnfds", {"_id": db_vnfr
["vnfd-id"]})
1251 step
= "Getting scaling-group-descriptor"
1252 for scaling_descriptor
in db_vnfd
["scaling-group-descriptor"]:
1253 if scaling_descriptor
["name"] == scaling_group
:
1256 raise LcmException("input parameter 'scaleByStepData':'scaling-group-descriptor':'{}' is not present "
1257 "at vnfd:scaling-group-descriptor".format(scaling_group
))
1259 # for scaling_policy_descriptor in scaling_descriptor.get("scaling-policy", ()):
1260 # cooldown_time = scaling_policy_descriptor.get("cooldown-time", 0)
1261 # if scaling_policy and scaling_policy == scaling_policy_descriptor.get("name"):
1264 # TODO check if ns is in a proper status
1265 step
= "Sending scale order to RO"
1267 if not db_nsr
["_admin"].get("scaling-group"):
1268 self
.update_db_2("nsrs", nsr_id
, {"_admin.scaling-group": [{"name": scaling_group
, "nb-scale-op": 0}]})
1269 admin_scale_index
= 0
1271 for admin_scale_index
, admin_scale_info
in enumerate(db_nsr
["_admin"]["scaling-group"]):
1272 if admin_scale_info
["name"] == scaling_group
:
1273 nb_scale_op
= admin_scale_info
.get("nb-scale-op", 0)
1275 else: # not found, set index one plus last element and add new entry with the name
1276 admin_scale_index
+= 1
1277 db_nsr_update
["_admin.scaling-group.{}.name".format(admin_scale_index
)] = scaling_group
1278 RO_scaling_info
= []
1279 vdu_scaling_info
= {"scaling_group_name": scaling_group
, "vdu": []}
1280 if scaling_type
== "SCALE_OUT":
1281 # count if max-instance-count is reached
1282 if "max-instance-count" in scaling_descriptor
and scaling_descriptor
["max-instance-count"] is not None:
1283 max_instance_count
= int(scaling_descriptor
["max-instance-count"])
1284 if nb_scale_op
>= max_instance_count
:
1285 raise LcmException("reached the limit of {} (max-instance-count) scaling-out operations for the"
1286 " scaling-group-descriptor '{}'".format(nb_scale_op
, scaling_group
))
1287 nb_scale_op
= nb_scale_op
+ 1
1288 vdu_scaling_info
["scaling_direction"] = "OUT"
1289 vdu_scaling_info
["vdu-create"] = {}
1290 for vdu_scale_info
in scaling_descriptor
["vdu"]:
1291 RO_scaling_info
.append({"osm_vdu_id": vdu_scale_info
["vdu-id-ref"], "member-vnf-index": vnf_index
,
1292 "type": "create", "count": vdu_scale_info
.get("count", 1)})
1293 vdu_scaling_info
["vdu-create"][vdu_scale_info
["vdu-id-ref"]] = vdu_scale_info
.get("count", 1)
1294 elif scaling_type
== "SCALE_IN":
1295 # count if min-instance-count is reached
1296 if "min-instance-count" in scaling_descriptor
and scaling_descriptor
["min-instance-count"] is not None:
1297 min_instance_count
= int(scaling_descriptor
["min-instance-count"])
1298 if nb_scale_op
<= min_instance_count
:
1299 raise LcmException("reached the limit of {} (min-instance-count) scaling-in operations for the "
1300 "scaling-group-descriptor '{}'".format(nb_scale_op
, scaling_group
))
1301 nb_scale_op
= nb_scale_op
- 1
1302 vdu_scaling_info
["scaling_direction"] = "IN"
1303 vdu_scaling_info
["vdu-delete"] = {}
1304 for vdu_scale_info
in scaling_descriptor
["vdu"]:
1305 RO_scaling_info
.append({"osm_vdu_id": vdu_scale_info
["vdu-id-ref"], "member-vnf-index": vnf_index
,
1306 "type": "delete", "count": vdu_scale_info
.get("count", 1)})
1307 vdu_scaling_info
["vdu-delete"][vdu_scale_info
["vdu-id-ref"]] = vdu_scale_info
.get("count", 1)
1309 # update VDU_SCALING_INFO with the VDUs to delete ip_addresses
1310 if vdu_scaling_info
["scaling_direction"] == "IN":
1311 for vdur
in reversed(db_vnfr
["vdur"]):
1312 if vdu_scaling_info
["vdu-delete"].get(vdur
["vdu-id-ref"]):
1313 vdu_scaling_info
["vdu-delete"][vdur
["vdu-id-ref"]] -= 1
1314 vdu_scaling_info
["vdu"].append({
1315 "name": vdur
["name"],
1316 "vdu_id": vdur
["vdu-id-ref"],
1319 for interface
in vdur
["interfaces"]:
1320 vdu_scaling_info
["vdu"][-1]["interface"].append({
1321 "name": interface
["name"],
1322 "ip_address": interface
["ip-address"],
1323 "mac_address": interface
.get("mac-address"),
1325 del vdu_scaling_info
["vdu-delete"]
1327 # execute primitive service PRE-SCALING
1328 step
= "Executing pre-scale vnf-config-primitive"
1329 if scaling_descriptor
.get("scaling-config-action"):
1330 for scaling_config_action
in scaling_descriptor
["scaling-config-action"]:
1331 if scaling_config_action
.get("trigger") and scaling_config_action
["trigger"] == "pre-scale-in" \
1332 and scaling_type
== "SCALE_IN":
1333 vnf_config_primitive
= scaling_config_action
["vnf-config-primitive-name-ref"]
1334 step
= db_nslcmop_update
["detailed-status"] = \
1335 "executing pre-scale scaling-config-action '{}'".format(vnf_config_primitive
)
1336 # look for primitive
1337 primitive_params
= {}
1338 for config_primitive
in db_vnfd
.get("vnf-configuration", {}).get("config-primitive", ()):
1339 if config_primitive
["name"] == vnf_config_primitive
:
1340 for parameter
in config_primitive
.get("parameter", ()):
1341 if 'default-value' in parameter
and \
1342 parameter
['default-value'] == "<VDU_SCALE_INFO>":
1343 primitive_params
[parameter
["name"]] = yaml
.safe_dump(vdu_scaling_info
,
1344 default_flow_style
=True,
1349 "Invalid vnfd descriptor at scaling-group-descriptor[name='{}']:scaling-config-action"
1350 "[vnf-config-primitive-name-ref='{}'] does not match any vnf-cnfiguration:config-"
1351 "primitive".format(scaling_group
, config_primitive
))
1352 scale_process
= "VCA"
1353 db_nsr_update
["config-status"] = "configuring pre-scaling"
1354 result
, result_detail
= await self
._ns
_execute
_primitive
(nsr_lcm
, vnf_index
,
1355 vnf_config_primitive
, primitive_params
)
1356 self
.logger
.debug(logging_text
+ "vnf_config_primitive={} Done with result {} {}".format(
1357 vnf_config_primitive
, result
, result_detail
))
1358 if result
== "FAILED":
1359 raise LcmException(result_detail
)
1360 db_nsr_update
["config-status"] = old_config_status
1361 scale_process
= None
1364 scale_process
= "RO"
1365 RO
= ROclient
.ROClient(self
.loop
, **self
.ro_config
)
1366 RO_desc
= await RO
.create_action("ns", RO_nsr_id
, {"vdu-scaling": RO_scaling_info
})
1367 db_nsr_update
["_admin.scaling-group.{}.nb-scale-op".format(admin_scale_index
)] = nb_scale_op
1368 db_nsr_update
["_admin.scaling-group.{}.time".format(admin_scale_index
)] = time()
1370 RO_nslcmop_id
= RO_desc
["instance_action_id"]
1371 db_nslcmop_update
["_admin.deploy.RO"] = RO_nslcmop_id
1373 RO_task_done
= False
1374 step
= detailed_status
= "Waiting RO_task_id={} to complete the scale action.".format(RO_nslcmop_id
)
1375 detailed_status_old
= None
1376 self
.logger
.debug(logging_text
+ step
)
1378 deployment_timeout
= 1 * 3600 # One hour
1379 while deployment_timeout
> 0:
1380 if not RO_task_done
:
1381 desc
= await RO
.show("ns", item_id_name
=RO_nsr_id
, extra_item
="action",
1382 extra_item_id
=RO_nslcmop_id
)
1383 ns_status
, ns_status_info
= RO
.check_action_status(desc
)
1384 if ns_status
== "ERROR":
1385 raise ROclient
.ROClientException(ns_status_info
)
1386 elif ns_status
== "BUILD":
1387 detailed_status
= step
+ "; {}".format(ns_status_info
)
1388 elif ns_status
== "ACTIVE":
1390 step
= detailed_status
= "Waiting ns ready at RO. RO_id={}".format(RO_nsr_id
)
1391 self
.logger
.debug(logging_text
+ step
)
1393 assert False, "ROclient.check_action_status returns unknown {}".format(ns_status
)
1395 desc
= await RO
.show("ns", RO_nsr_id
)
1396 ns_status
, ns_status_info
= RO
.check_ns_status(desc
)
1397 if ns_status
== "ERROR":
1398 raise ROclient
.ROClientException(ns_status_info
)
1399 elif ns_status
== "BUILD":
1400 detailed_status
= step
+ "; {}".format(ns_status_info
)
1401 elif ns_status
== "ACTIVE":
1402 step
= detailed_status
= "Waiting for management IP address reported by the VIM"
1404 desc
= await RO
.show("ns", RO_nsr_id
)
1405 nsr_lcm
["nsr_ip"] = RO
.get_ns_vnf_info(desc
)
1407 except ROclient
.ROClientException
as e
:
1408 if e
.http_code
!= 409: # IP address is not ready return code is 409 CONFLICT
1411 assert False, "ROclient.check_ns_status returns unknown {}".format(ns_status
)
1412 if detailed_status
!= detailed_status_old
:
1413 detailed_status_old
= db_nslcmop_update
["detailed-status"] = detailed_status
1414 self
.update_db_2("nslcmops", nslcmop_id
, db_nslcmop_update
)
1416 await asyncio
.sleep(5, loop
=self
.loop
)
1417 deployment_timeout
-= 5
1418 if deployment_timeout
<= 0:
1419 raise ROclient
.ROClientException("Timeout waiting ns to be ready")
1421 step
= "Updating VNFRs"
1422 self
.ns_update_vnfr({db_vnfr
["member-vnf-index-ref"]: db_vnfr
}, desc
)
1424 # update VDU_SCALING_INFO with the obtained ip_addresses
1425 if vdu_scaling_info
["scaling_direction"] == "OUT":
1426 for vdur
in reversed(db_vnfr
["vdur"]):
1427 if vdu_scaling_info
["vdu-create"].get(vdur
["vdu-id-ref"]):
1428 vdu_scaling_info
["vdu-create"][vdur
["vdu-id-ref"]] -= 1
1429 vdu_scaling_info
["vdu"].append({
1430 "name": vdur
["name"],
1431 "vdu_id": vdur
["vdu-id-ref"],
1434 for interface
in vdur
["interfaces"]:
1435 vdu_scaling_info
["vdu"][-1]["interface"].append({
1436 "name": interface
["name"],
1437 "ip_address": interface
["ip-address"],
1438 "mac_address": interface
.get("mac-address"),
1440 del vdu_scaling_info
["vdu-create"]
1442 scale_process
= None
1444 self
.update_db_2("nsrs", nsr_id
, db_nsr_update
)
1446 # execute primitive service POST-SCALING
1447 step
= "Executing post-scale vnf-config-primitive"
1448 if scaling_descriptor
.get("scaling-config-action"):
1449 for scaling_config_action
in scaling_descriptor
["scaling-config-action"]:
1450 if scaling_config_action
.get("trigger") and scaling_config_action
["trigger"] == "post-scale-out" \
1451 and scaling_type
== "SCALE_OUT":
1452 vnf_config_primitive
= scaling_config_action
["vnf-config-primitive-name-ref"]
1453 step
= db_nslcmop_update
["detailed-status"] = \
1454 "executing post-scale scaling-config-action '{}'".format(vnf_config_primitive
)
1455 # look for primitive
1456 primitive_params
= {}
1457 for config_primitive
in db_vnfd
.get("vnf-configuration", {}).get("config-primitive", ()):
1458 if config_primitive
["name"] == vnf_config_primitive
:
1459 for parameter
in config_primitive
.get("parameter", ()):
1460 if 'default-value' in parameter
and \
1461 parameter
['default-value'] == "<VDU_SCALE_INFO>":
1462 primitive_params
[parameter
["name"]] = yaml
.safe_dump(vdu_scaling_info
,
1463 default_flow_style
=True,
1467 raise LcmException("Invalid vnfd descriptor at scaling-group-descriptor[name='{}']:"
1468 "scaling-config-action[vnf-config-primitive-name-ref='{}'] does not "
1469 "match any vnf-configuration:config-primitive".format(scaling_group
,
1471 scale_process
= "VCA"
1472 db_nsr_update
["config-status"] = "configuring post-scaling"
1474 result
, result_detail
= await self
._ns
_execute
_primitive
(nsr_lcm
, vnf_index
,
1475 vnf_config_primitive
, primitive_params
)
1476 self
.logger
.debug(logging_text
+ "vnf_config_primitive={} Done with result {} {}".format(
1477 vnf_config_primitive
, result
, result_detail
))
1478 if result
== "FAILED":
1479 raise LcmException(result_detail
)
1480 db_nsr_update
["config-status"] = old_config_status
1481 scale_process
= None
1483 db_nslcmop_update
["operationState"] = nslcmop_operation_state
= "COMPLETED"
1484 db_nslcmop_update
["statusEnteredTime"] = time()
1485 db_nslcmop_update
["detailed-status"] = "done"
1486 db_nsr_update
["detailed-status"] = "" # "scaled {} {}".format(scaling_group, scaling_type)
1487 db_nsr_update
["operational-status"] = old_operational_status
1488 db_nsr_update
["config-status"] = old_config_status
1490 except (ROclient
.ROClientException
, DbException
, LcmException
) as e
:
1491 self
.logger
.error(logging_text
+ "Exit Exception {}".format(e
))
1493 except asyncio
.CancelledError
:
1494 self
.logger
.error(logging_text
+ "Cancelled Exception while '{}'".format(step
))
1495 exc
= "Operation was cancelled"
1496 except Exception as e
:
1497 exc
= traceback
.format_exc()
1498 self
.logger
.critical(logging_text
+ "Exit Exception {} {}".format(type(e
).__name
__, e
), exc_info
=True)
1502 db_nslcmop_update
["detailed-status"] = "FAILED {}: {}".format(step
, exc
)
1503 db_nslcmop_update
["operationState"] = nslcmop_operation_state
= "FAILED"
1504 db_nslcmop_update
["statusEnteredTime"] = time()
1506 db_nsr_update
["operational-status"] = old_operational_status
1507 db_nsr_update
["config-status"] = old_config_status
1508 db_nsr_update
["detailed-status"] = ""
1509 db_nsr_update
["_admin.nslcmop"] = None
1511 if "VCA" in scale_process
:
1512 db_nsr_update
["config-status"] = "failed"
1513 if "RO" in scale_process
:
1514 db_nsr_update
["operational-status"] = "failed"
1515 db_nsr_update
["detailed-status"] = "FAILED scaling nslcmop={} {}: {}".format(nslcmop_id
, step
,
1517 if db_nslcmop_update
:
1518 self
.update_db_2("nslcmops", nslcmop_id
, db_nslcmop_update
)
1520 db_nsr_update
["_admin.nslcmop"] = None
1521 self
.update_db_2("nsrs", nsr_id
, db_nsr_update
)
1522 if nslcmop_operation_state
:
1524 await self
.msg
.aiowrite("ns", "scaled", {"nsr_id": nsr_id
, "nslcmop_id": nslcmop_id
,
1525 "operationState": nslcmop_operation_state
})
1527 # await asyncio.sleep(cooldown_time)
1528 # await self.msg.aiowrite("ns","scaled-cooldown-time", {"nsr_id": nsr_id, "nslcmop_id": nslcmop_id})
1529 except Exception as e
:
1530 self
.logger
.error(logging_text
+ "kafka_write notification Exception {}".format(e
))
1531 self
.logger
.debug(logging_text
+ "Exit")
1532 self
.lcm_tasks
.remove("ns", nsr_id
, nslcmop_id
, "ns_scale")