class AbstractCommand: def __init__(self, command_args, global_args, molecule=False): """ Initialize commands :param command_args: arguments of the command :param global_args: arguments from the CLI :param molecule: molecule instance """ self.args = docopt(self.__doc__, argv=command_args) self.args['<command>'] = self.__class__.__name__.lower() self.command_args = command_args self.static = False # give us the option to reuse an existing molecule instance if not molecule: self.molecule = Molecule(self.args) self.molecule.main() else: self.molecule = molecule # init doesn't need to load molecule files if self.__class__.__name__ == 'Init': return # assume static inventory if no vagrant config block is defined if self.molecule._provisioner is None: self.static = True # assume static inventory if no instances are defined in vagrant config block if self.molecule._provisioner.instances is None: self.static = True # Add or update the group_vars if needed. self.molecule._add_or_update_group_vars() def disabled(self, cmd): """ Prints 'command disabled' message and exits program. :param cmd: Name of the disabled command to print. :return: None """ fmt = [colorama.Fore.RED, cmd, colorama.Fore.RESET] errmsg = "{}The `{}` command isn't supported with static inventory.{}" utilities.logger.error(errmsg.format(*fmt)) sys.exit(1) def execute(self): raise NotImplementedError
class AbstractCommand: def __init__(self, command_args, global_args, molecule=False): """ Initialize commands :param command_args: arguments of the command :param global_args: arguments from the CLI :param molecule: molecule instance """ self.args = docopt(self.__doc__, argv=command_args) self.args['<command>'] = self.__class__.__name__.lower() self.command_args = command_args self.static = False # give us the option to reuse an existing molecule instance if not molecule: self.molecule = Molecule(self.args) self.molecule.main() else: self.molecule = molecule # init doesn't need to load molecule files if self.__class__.__name__ == 'Init': return # assume static inventory if no vagrant config block is defined if self.molecule._provisioner is None: self.static = True # assume static inventory if no instances are defined in vagrant config block if self.molecule._provisioner.instances is None: self.static = True # Add or update the group_vars if needed. self.molecule._add_or_update_group_vars() def disabled(self, cmd): """ Prints 'command disabled' message and exits program. :param cmd: Name of the disabled command to print. :return: None """ fmt = [Fore.RED, cmd, Fore.RESET] errmsg = "{}The `{}` command isn't supported with static inventory.{}" print(errmsg.format(*fmt)) sys.exit(1) def execute(self): raise NotImplementedError
class Commands(object): def __init__(self, args): self.args = args def main(self): self.molecule = Molecule(self.args) self.molecule.main() # assume static inventory if no vagrant config block is defined if self.molecule._config.config.get('vagrant') is None: self.commands = StaticCommands(self.molecule) return # assume static inventory if no instances are defined in vagrant config block if self.molecule._config.config['vagrant'].get('instances') is None: self.commands = StaticCommands(self.molecule) return self.commands = BaseCommands(self.molecule) def destroy(self): self.commands.destroy() def create(self): self.commands.create() def converge(self): self.commands.converge() def idempotence(self): self.commands.idempotence() def verify(self): self.commands.verify() def test(self): self.commands.test() def list(self): self.commands.list() def status(self): self.commands.status() def login(self): self.commands.login() def init(self): self.commands.init()
class AbstractCommand: def __init__(self, args, molecule=False): """ Initialize commands :param args: arguments from the CLI :param molecule: molecule instance """ self.args = args self.static = False # only create a molecule instance if one doesn't exist if not molecule: self.molecule = Molecule(self.args) self.molecule.main() else: self.molecule = molecule # assume static inventory if no vagrant config block is defined if self.molecule._provisioner is None: self.static = True # assume static inventory if no instances are defined in vagrant config block if self.molecule._provisioner.instances is None: self.static = True def disabled(self, cmd): """ Prints 'command disabled' message and exits program. :param cmd: Name of the disabled command to print. :return: None """ fmt = [Fore.RED, cmd, Fore.RESET] errmsg = "{}The `{}` command isn't supported with static inventory.{}" print(errmsg.format(*fmt)) sys.exit(1) def execute(self): raise NotImplementedError