def __init__(self, **kwargs): self._hosts = kwargs.pop("hosts", []) # if a nick was specified, pull in the resolved arguments if "nick" in kwargs: nick = kwargs.pop("nick") kwargs = helpers.merge_dicts(kwargs, helpers.resolve_nick(nick)) # determine the provider actions based on kwarg parameters self._provider_actions = {} for key, action in PROVIDER_ACTIONS.items(): if key in kwargs: self._provider_actions[key] = action self._kwargs = kwargs
def __init__(self, **kwargs): self._hosts = kwargs.pop("hosts", []) self.host_classes = {"host": Host} # if a nick was specified, pull in the resolved arguments logger.debug(f"Broker instantiated with {kwargs=}") if "nick" in kwargs: nick = kwargs.pop("nick") kwargs = helpers.merge_dicts(kwargs, helpers.resolve_nick(nick)) logger.debug(f"kwargs after nick resolution {kwargs=}") if "host_classes" in kwargs: self.host_classes.update(kwargs.pop("host_classes")) # determine the provider actions based on kwarg parameters self._provider_actions = {} for key, action in PROVIDER_ACTIONS.items(): if key in kwargs: self._provider_actions[key] = action self._kwargs = kwargs
def checkout(ctx, workflow, nick): """Checkout a Virtual Machine COMMAND: broker checkout --<action> <argument> """ broker_args = {} if nick: broker_args = helpers.resolve_nick(nick) if workflow: broker_args["workflow"] = workflow # if additional arguments were passes, include them in the broker args broker_args.update(dict(zip(ctx.args[::2], ctx.args[1::2]))) broker_inst = VMBroker(**broker_args) broker_inst.checkout() new_hosts = [] for host in broker_inst._hosts: logger.info(f"{host.__class__.__name__}: {host.hostname}") new_hosts.append(host.to_dict()) helpers.update_inventory(new_hosts)