def execute(ctx, workflow, nick, output_format, artifacts): """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 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 :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 """ broker_args = {} if nick: broker_args["nick"] = nick if workflow: broker_args["workflow"] = workflow if artifacts: broker_args["artifacts"] = True # if additional arguments were passed, include them in the broker args broker_args.update(dict(zip(ctx.args[::2], ctx.args[1::2]))) broker_inst = VMBroker(**broker_args) result = broker_inst.execute() if output_format == "raw": print(result) elif output_format == "log": logger.info(result) elif output_format == "yaml": print(helpers.yaml_format(result))
def execute(ctx, background, workflow, job_template, nick, output_format, artifacts, args_file): """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 workflow: workflow template stored in Ansible Tower, passed in as a string :param job-template: job template stored in Ansible Tower, passed in as a string :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 = {} if nick: broker_args["nick"] = nick if workflow: broker_args["workflow"] = workflow if job_template: broker_args["job_template"] = job_template 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: fork_broker() broker_inst = VMBroker(**broker_args) result = broker_inst.execute() if output_format == "raw": print(result) elif output_format == "log": logger.info(result) elif output_format == "yaml": print(helpers.yaml_format(result))