Esempio n. 1
0
def duplicate(vm, background, count, all_, filter):
    """Duplicate a broker-procured vm

    COMMAND: broker duplicate <vm hostname>|<local id>|all

    :param vm: Hostname or local id of host

    :param background: run a new broker subprocess to carry out command

    :param all_: Click option all

    :param filter: a filter string matching broker's specification
    """
    if background:
        helpers.fork_broker()
    inventory = helpers.load_inventory(filter=filter)
    for num, host in enumerate(inventory):
        if str(num
               ) in vm or host["hostname"] in vm or host["name"] in vm or all_:
            broker_args = host.get("_broker_args")
            if broker_args:
                if count:
                    broker_args["_count"] = count
                logger.info(f"Duplicating: {host['hostname']}")
                broker_inst = VMBroker(**broker_args)
                broker_inst.checkout()
            else:
                logger.warning(
                    f"Unable to duplicate {host['hostname']}, no _broker_args found"
                )
Esempio n. 2
0
def checkout(ctx, background, nick, count, args_file, **kwargs):
    """Checkout or "create" a Virtual Machine broker instance
    COMMAND: broker checkout --workflow "workflow-name" --workflow-arg1 something
    or
    COMMAND: broker checkout --nick "nickname"

    :param ctx: clicks context object

    :param background: run a new broker subprocess to carry out command

    :param nick: shortcut for arguments saved in settings.yaml, passed in as a string

    :param args_file: this broker argument wil be replaced with the contents of the file passed in
    """
    broker_args = helpers.clean_dict(kwargs)
    if nick:
        broker_args["nick"] = nick
    if count:
        broker_args["_count"] = count
    if args_file:
        broker_args["args_file"] = args_file
    # if additional arguments were passed, include them in the broker args
    # strip leading -- characters
    broker_args.update({(key[2:] if key.startswith("--") else key): val
                        for key, val in zip(ctx.args[::2], ctx.args[1::2])})
    broker_args = helpers.resolve_file_args(broker_args)
    if background:
        helpers.fork_broker()
    broker_inst = VMBroker(**broker_args)
    broker_inst.checkout()
Esempio n. 3
0
def checkout(ctx, background, workflow, nick):
    """Checkout or "create" a Virtual Machine broker instance
    COMMAND: broker checkout --workflow "workflow-name" --workflow-arg1 something
    or
    COMMAND: broker checkout --nick "nickname"

    :param ctx: clicks context object

    :param background: run a new broker subprocess to carry out command

    :param workflow: workflow template stored in Ansible Tower, passed in as a string

    :param nick: shortcut for arguments saved in settings.yaml, passed in as a string
    """
    broker_args = {}
    if nick:
        broker_args["nick"] = nick
    if workflow:
        broker_args["workflow"] = workflow
    # if additional arguments were passed, include them in the broker args
    broker_args.update(dict(zip(ctx.args[::2], ctx.args[1::2])))
    if background:
        fork_broker()
    broker_inst = VMBroker(**broker_args)
    broker_inst.checkout()
Esempio n. 4
0
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)
Esempio n. 5
0
def duplicate(vm, all_):
    """Duplicate a broker-procured vm

    COMMAND: broker duplicate <vm hostname>|<local id>|all

    :param vm: Hostname or local id of host

    :param all_: Click option all
    """
    inventory = helpers.load_inventory()
    for num, host in enumerate(inventory):
        if str(num) in vm or host["hostname"] in vm or all_:
            broker_args = host.get("_broker_args")
            if broker_args:
                logger.info(f"Duplicating: {host['hostname']}")
                broker_inst = VMBroker(**broker_args)
                broker_inst.checkout()
            else:
                logger.warning(
                    f"Unable to duplicate {host['hostname']}, no _broker_args found"
                )