예제 #1
0
def extend(vm, background, all_, sequential, filter, **kwargs):
    """Extend a host's lease time

    COMMAND: broker extend <vm hostname>|<vm name>|<local id>

    :param vm: Hostname, VM Name, or local id of host

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

    :param all_: Click option all

    :param sequential: Flag for whether to run extends sequentially

    :param filter: a filter string matching broker's specification
    """
    broker_args = helpers.clean_dict(kwargs)
    if background:
        helpers.fork_broker()
    inventory = helpers.load_inventory(filter=filter)
    to_extend = []
    for num, host in enumerate(inventory):
        if str(num
               ) in vm or host["hostname"] in vm or host["name"] in vm or all_:
            to_extend.append(VMBroker().reconstruct_host(host))
    broker_inst = VMBroker(hosts=to_extend, **broker_args)
    broker_inst.extend(sequential=sequential)
예제 #2
0
파일: commands.py 프로젝트: latran/broker
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()
예제 #3
0
def execute(ctx, background, nick, output_format, artifacts, args_file, **kwargs):
    """Execute an arbitrary provider action
    COMMAND: broker execute --workflow "workflow-name" --workflow-arg1 something
    or
    COMMAND: broker execute --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 output_format: change the format of the output to one of the choice options

    :param artifacts: AnsibleTower provider specific option for choosing what to return

    :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 artifacts:
        broker_args["artifacts"] = artifacts
    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)
    result = broker_inst.execute()
    helpers.emit({"output": result})
    if output_format == "raw":
        print(result)
    elif output_format == "log":
        logger.info(result)
    elif output_format == "yaml":
        print(helpers.yaml_format(result))