- def n2vc_callback(self, model_name, application_name, status, message, n2vc_info, task=None):
- """
- Callback both for charm status change and task completion
- :param model_name: Charm model name
- :param application_name: Charm application name
- :param status: Can be
- - 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
- - removing,
- - removed
- :param message: detailed message error
- :param n2vc_info: dictionary with information shared with instantiate task. It contains:
- nsr_id:
- nslcmop_id:
- lcmOperationType: currently "instantiate"
- deployed: dictionary with {<application>: {operational-status: <status>, detailed-status: <text>}}
- db_update: dictionary to be filled with the changes to be wrote to database with format key.key.key: value
- n2vc_event: event used to notify instantiation task that some change has been produced
- :param task: None for charm status change, or task for completion task callback
- :return:
- """
- try:
- nsr_id = n2vc_info["nsr_id"]
- deployed = n2vc_info["deployed"]
- db_nsr_update = n2vc_info["db_update"]
- nslcmop_id = n2vc_info["nslcmop_id"]
- ns_operation = n2vc_info["lcmOperationType"]
- n2vc_event = n2vc_info["n2vc_event"]
- logging_text = "Task ns={} {}={} [n2vc_callback] application={}".format(nsr_id, ns_operation, nslcmop_id,
- application_name)
- for vca_index, vca_deployed in enumerate(deployed):
- if not vca_deployed:
- continue
- if model_name == vca_deployed["model"] and application_name == vca_deployed["application"]:
- break
- else:
- self.logger.error(logging_text + " Not present at nsr._admin.deployed.VCA. Received model_name={}".
- format(model_name))
- return
- if task:
- if task.cancelled():
- self.logger.debug(logging_text + " task Cancelled")
- vca_deployed['operational-status'] = "error"
- db_nsr_update["_admin.deployed.VCA.{}.operational-status".format(vca_index)] = "error"
- vca_deployed['detailed-status'] = "Task Cancelled"
- db_nsr_update["_admin.deployed.VCA.{}.detailed-status".format(vca_index)] = "Task Cancelled"
-
- elif task.done():
- exc = task.exception()
- if exc:
- self.logger.error(logging_text + " task Exception={}".format(exc))
- vca_deployed['operational-status'] = "error"
- db_nsr_update["_admin.deployed.VCA.{}.operational-status".format(vca_index)] = "error"
- vca_deployed['detailed-status'] = str(exc)
- db_nsr_update["_admin.deployed.VCA.{}.detailed-status".format(vca_index)] = str(exc)
- else:
- self.logger.debug(logging_text + " task Done")
- # task is Done, but callback is still ongoing. So ignore
- return
- elif status:
- self.logger.debug(logging_text + " Enter status={} message={}".format(status, message))
- if vca_deployed['operational-status'] == status:
- return # same status, ignore
- vca_deployed['operational-status'] = status
- db_nsr_update["_admin.deployed.VCA.{}.operational-status".format(vca_index)] = status
- vca_deployed['detailed-status'] = str(message)
- db_nsr_update["_admin.deployed.VCA.{}.detailed-status".format(vca_index)] = str(message)
- else:
- self.logger.critical(logging_text + " Enter with bad parameters", exc_info=True)
- return
- # wake up instantiate task
- n2vc_event.set()
- except Exception as e:
- self.logger.critical(logging_text + " Exception {}".format(e), exc_info=True)
-