+ def n2vc_callback(self, nsd, vnfd, vnf_member_index, workload_status, *args):
+ """Update the lcm database with the status of the charm.
+
+ Updates the VNF's operational status with the state of the charm:
+ - blocked: The unit needs manual intervention
+ - maintenance: The unit is actively deploying/configuring
+ - waiting: The unit is waiting for another charm to be ready
+ - active: The unit is deployed, configured, and ready
+ - error: The charm has failed and needs attention.
+ - terminated: The charm has been destroyed
+
+ Updates the network service's config-status to reflect the state of all
+ charms.
+ """
+ if workload_status and len(args) == 3:
+ # self.logger.debug("[n2vc_callback] Workload status \"{}\"".format(workload_status))
+ try:
+ (db_nsr, vnf_index, task) = args
+
+ nsr_id = db_nsr["_id"]
+ nsr_lcm = db_nsr["_admin"]["deploy"]
+ nsr_lcm["VCA"][vnf_index]['operational-status'] = workload_status
+
+ if task:
+ if task.cancelled():
+ return
+
+ if task.done():
+ exc = task.exception()
+ if exc:
+ nsr_lcm = db_nsr["_admin"]["deploy"]
+ nsr_lcm["VCA"][vnf_index]['operational-status'] = "failed"
+ db_nsr["detailed-status"] = "fail configuring vnf_index={} {}".format(vnf_index, exc)
+ db_nsr["config-status"] = "failed"
+ self.update_nsr_db(nsr_id, db_nsr)
+ else:
+ units = len(nsr_lcm["VCA"])
+ active = 0
+ statusmap = {}
+ for vnf_index in nsr_lcm["VCA"]:
+ if 'operational-status' in nsr_lcm["VCA"][vnf_index]:
+
+ if nsr_lcm["VCA"][vnf_index]['operational-status'] not in statusmap:
+ # Initialize it
+ statusmap[nsr_lcm["VCA"][vnf_index]['operational-status']] = 0
+
+ statusmap[nsr_lcm["VCA"][vnf_index]['operational-status']] += 1
+
+ if nsr_lcm["VCA"][vnf_index]['operational-status'] == "active":
+ active += 1
+ else:
+ self.logger.debug("No operational-status")
+
+ cs = ""
+ for status in statusmap:
+ cs += "{} ({}) ".format(status, statusmap[status])
+ db_nsr["config-status"] = cs
+ self.update_nsr_db(nsr_id, db_nsr)
+
+ except Exception as e:
+ # self.logger.critical("Task create_ns={} n2vc_callback Exception {}".format(nsr_id, e), exc_info=True)
+ self.logger.critical("Task create_ns n2vc_callback Exception {}".format(e), exc_info=True)
+ pass
+