def edge_deploy_result(self, task):
     """callback when deployment task finished."""
     jobdata = task.userdata['jobdata']
     lrouter = jobdata['lrouter']
     context = jobdata['context']
     name = task.userdata['router_name']
     router_db = self.plugin._get_router(context, lrouter['uuid'])
     if task.status == TaskStatus.COMPLETED:
         LOG.debug(_("Successfully deployed %(edge_id)s for "
                     "router %(name)s"), {
                         'edge_id': task.userdata['edge_id'],
                         'name': name})
         if router_db['status'] == service_constants.PENDING_CREATE:
             router_db['status'] = service_constants.ACTIVE
             binding = vcns_db.get_vcns_router_binding(
                 context.session, lrouter['uuid'])
             # only update status to active if its status is pending create
             if binding['status'] == service_constants.PENDING_CREATE:
                 vcns_db.update_vcns_router_binding(
                     context.session, lrouter['uuid'],
                     status=service_constants.ACTIVE)
     else:
         LOG.debug(_("Failed to deploy Edge for router %s"), name)
         router_db['status'] = service_constants.ERROR
         vcns_db.update_vcns_router_binding(
             context.session, lrouter['uuid'],
             status=service_constants.ERROR)
    def _delete_lrouter(self, context, id):
        if not self._is_advanced_service_router(context, id):
            super(NvpAdvancedPlugin, self)._delete_lrouter(context, id)
            if id in self._router_type:
                del self._router_type[id]
            return

        binding = vcns_db.get_vcns_router_binding(context.session, id)
        if binding:
            vcns_db.update_vcns_router_binding(
                context.session, id, status=service_constants.PENDING_DELETE)

            lswitch_id = binding['lswitch_id']
            edge_id = binding['edge_id']

            # delete lswitch
            try:
                self.vcns_driver.delete_lswitch(lswitch_id)
            except exceptions.ResourceNotFound:
                LOG.warning(_("Did not found lswitch %s in NVP"), lswitch_id)

            # delete edge
            jobdata = {
                'context': context
            }
            self.vcns_driver.delete_edge(id, edge_id, jobdata=jobdata)

        # delete LR
        nvplib.delete_lrouter(self.cluster, id)
        if id in self._router_type:
            del self._router_type[id]
 def edge_deploy_started(self, task):
     """callback when deployment task started."""
     jobdata = task.userdata['jobdata']
     lrouter = jobdata['lrouter']
     context = jobdata['context']
     edge_id = task.userdata.get('edge_id')
     name = task.userdata['router_name']
     if edge_id:
         LOG.debug(_("Start deploying %(edge_id)s for router %(name)s"), {
             'edge_id': edge_id,
             'name': name})
         vcns_db.update_vcns_router_binding(
             context.session, lrouter['uuid'], edge_id=edge_id)
     else:
             LOG.debug(_("Failed to deploy Edge for router %s"), name)
             vcns_db.update_vcns_router_binding(
                 context.session, lrouter['uuid'],
                 status=service_constants.ERROR)