def post(self, ctx: HandlerContext, resource: Config) -> None: if self.connection: try: # Vyos cannot logout before exiting configuration mode self.connection.exit(force=True) self.connection.logout() self.connection = None except: # noqa: E722 ctx.exception("Failed to close connection")
def _execute(self, ctx: handler.HandlerContext, events: dict, cache: AgentCache) -> (bool, bool): """ :param ctx The context to use during execution of this deploy :param events Possible events that are available for this resource :param cache The cache instance to use :return (success, send_event) Return whether the execution was successful and whether a change event should be sent to provides of this resource. """ ctx.debug("Start deploy %(deploy_id)s of resource %(resource_id)s", deploy_id=self.gid, resource_id=self.resource_id) provider = None try: provider = handler.Commander.get_provider(cache, self.scheduler.agent, self.resource) provider.set_cache(cache) except Exception: if provider is not None: provider.close() cache.close_version(self.resource.id.version) ctx.set_status(const.ResourceState.unavailable) ctx.exception("Unable to find a handler for %(resource_id)s", resource_id=str(self.resource.id)) return False, False yield self.scheduler.agent.thread_pool.submit(provider.execute, ctx, self.resource) send_event = (hasattr(self.resource, "send_event") and self.resource.send_event) if ctx.status is not const.ResourceState.deployed: provider.close() cache.close_version(self.resource.id.version) return False, send_event if len(events) > 0 and provider.can_process_events(): ctx.info( "Sending events to %(resource_id)s because of modified dependencies", resource_id=str(self.resource.id)) yield self.scheduler.agent.thread_pool.submit( provider.process_events, ctx, self.resource, events) provider.close() cache.close_version(self.resource_id.version) return True, send_event