def __init__(self, tasks, name=None): super(DockerTasks.DestroyTask, self).__init__() # We need to be sure that `default()` will be at first place # every time when vars(self) is being invoked. # This is necessary to exclude `default` from the list of task # because of it's already there as default task. # See `fabric.main.extract_tasks()` for details self.__dict__ = utils.PriorityDict(self.__dict__, priority=['default']) self.tasks = tasks self.name = name or self.name # hide actual 'destroy' task from the tasks list self.run.use_task_objects = False
def __init__(self, callback, color=colors.yellow, title=None): super(Infrastructure, self).__init__() # We need to be sure that `default()` will be at first place # every time when vars(self) is being invoked. # This is necessary to exclude `default` from the list of task # because of it's already there as default task. # See `fabric.main.extract_tasks()` for details self.__dict__ = utils.PriorityDict(self.__dict__, priority=['default']) default, confirm = self.default, self.confirm self.callback = callback self.name = getattr(callback, '__name__', self.name) self.title = color(title or self.name) self.__doc__ = (self.__doc__ or '').format(**self.__dict__) default.__doc__ = (default.__doc__ or '').format(**self.__dict__) confirm.__doc__ = (confirm.__doc__ or '').format(**self.__dict__) # enable "module" behaviour in task mode self.use_task_objects = not is_task_mode()
def __init__( self, service=None, registry=None, host_registry=None, account=None, ssh_tunnel_port=None, # deprecated ssh_tunnel=None, migrate_commands=False, backup_commands=False, pull_command=False, update_command=False, revert_command=False, destroy_command=False, env=None, **kwargs): self.destroy = self.DestroyTask(tasks=self) super(DockerTasks, self).__init__(**kwargs) # We need to be sure that `deploy()` will be at first place # every time when vars(self) is being invoked. # This is necessary to exclude `deploy` from the list of task # because of it's already there as default task. # See `fabric.main.extract_tasks()` for details self.__dict__ = utils.PriorityDict(self.__dict__, priority=['deploy']) # reassign is_default property which is being lost # after applying @fab.hosts/@fab.roles decorators self.deploy.is_default = True self.service = service self.registry = registry self.host_registry = host_registry or registry self.account = account self.ssh_tunnel = ssh_tunnel if ssh_tunnel_port: warnings.warn( 'ssh_tunnel_port is deprecated and will be removed in v0.6, ' 'use ssh_tunnel instead', RuntimeWarning, stacklevel=self._warnings_stacklevel, ) registry = self.registry or self.image and self.image.registry assert registry, 'must provide registry if using ssh_tunnel_port' self.host_registry = 'localhost:%d' % ssh_tunnel_port self.ssh_tunnel = '{port}:{host}:{host_port}'.format( port=ssh_tunnel_port, host=registry.host, host_port=registry.port, ) task_mode = is_task_mode() self.backup.use_task_objects = task_mode or backup_commands self.restore.use_task_objects = task_mode or backup_commands self.migrate.use_task_objects = task_mode or migrate_commands self.migrate_back.use_task_objects = task_mode or migrate_commands self.revert.use_task_objects = task_mode or revert_command self.pull.use_task_objects = task_mode or pull_command self.update.use_task_objects = task_mode or update_command self.destroy.use_task_objects = not task_mode # hide 'destroy' task in the tasks list by removing it from instance if not (destroy_command or task_mode): del self.destroy # set original name for `deploy` method to allow explicit invocation if task_mode: self.deploy.name = 'deploy' # enable following commands only if used custom registry or account custom_registry_mode = task_mode or bool(registry or account) self.prepare.use_task_objects = custom_registry_mode self.push.use_task_objects = custom_registry_mode self.upgrade.use_task_objects = custom_registry_mode self.env = env or {}