def compose_cancel(socket_path, api_version, args, show_json=False, testmode=0): """Cancel a running compose :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool :param testmode: unused in this function :type testmode: int compose cancel <uuid> This will cancel a running compose. It does nothing if the compose has finished. """ if len(args) == 0: log.error("cancel is missing the compose build id") return 1 api_route = client.api_url(api_version, "/compose/cancel/%s" % args[0]) result = client.delete_url_json(socket_path, api_route) return handle_api_result(result, show_json)
def compose_delete(socket_path, api_version, args, show_json=False, testmode=0, api=None): """Delete a finished compose's results :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool :param testmode: unused in this function :type testmode: int compose delete <uuid,...> Delete the listed compose results. It will only delete results for composes that have finished or failed, not a running compose. """ if len(args) == 0: log.error("delete is missing the compose build id") return 1 api_route = client.api_url(api_version, "/compose/delete/%s" % (",".join(argify(args)))) result = client.delete_url_json(socket_path, api_route) return handle_api_result(result, show_json)[0]
def providers_delete(socket_path, api_version, args, show_json=False, testmode=0): """Delete a profile from a provider :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool :param testmode: unused in this function :type testmode: int providers delete <provider> <profile> """ if len(args) == 0: log.error("delete is missing the provider name") return 1 if len(args) == 1: log.error("delete is missing the profile name") return 1 api_route = client.api_url(api_version, "/upload/providers/delete/%s/%s" % (args[0], args[1])) result = client.delete_url_json(socket_path, api_route) return handle_api_result(result, show_json)[0]
def sources_delete(socket_path, api_version, args, show_json=False): """Delete a source :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool sources delete <source-name> """ api_route = client.api_url(api_version, "/projects/source/delete/%s" % args[0]) result = client.delete_url_json(socket_path, api_route) return handle_api_result(result, show_json)
def upload_delete(socket_path, api_version, args, show_json=False, testmode=0): """Delete an upload and remove it from the build :param socket_path: Path to the Unix socket to use for API communication :type socket_path: str :param api_version: Version of the API to talk to. eg. "0" :type api_version: str :param args: List of remaining arguments from the cmdline :type args: list of str :param show_json: Set to True to show the JSON output instead of the human readable output :type show_json: bool :param testmode: unused in this function :type testmode: int upload delete <build-uuid> """ if len(args) == 0: log.error("delete is missing the upload uuid") return 1 api_route = client.api_url(api_version, "/upload/delete/%s" % args[0]) result = client.delete_url_json(socket_path, api_route) return handle_api_result(result, show_json)[0]
def run_module(): """Module main function """ # define available arguments/parameters a user can pass to the module module_args = dict( name=dict(type='str', required=False), definition=dict(type='str', required=False), state=dict(type='str', required=False, default='present'), ) mutually_exclusive = [('name', 'definition')] # seed the result dict in the object # we primarily care about changed and state # change is if this module effectively modified the target # state will include any data that you want your module to pass back # for consumption, for example, in a subsequent task result = dict(changed=False, ansible_module_results='') # the AnsibleModule object will be our abstraction working with Ansible # this includes instantiation, a couple of common attr would be the # args/params passed to the execution, as well as if the module # supports check mode module = AnsibleModule( argument_spec=module_args, mutually_exclusive=mutually_exclusive, supports_check_mode=True, ) # if the user is working with this module in only check mode we do not # want to make any changes to the environment, just return the current # state with no modifications if module.check_mode: module.exit_json(**result) # Figure out the name of the blueprint, either from the name or the TOML definition if module.params['name']: blueprint_name = module.params['name'] else: blueprint_name = toml.loads(module.params['definition'])['name'] result['blueprint_name'] = blueprint_name # See what is already present blueprint_present = True try: available_blueprint = client.get_url_raw( SOCKET, '/api/v1/blueprints/info/' + blueprint_name + '?format=toml') except RuntimeError: # The composer.http_client throws a Runtime Error if the API returns 400 blueprint_present = False if module.params['state'] == 'present' and not blueprint_present: result['ansible_module_results'] = client.post_url_toml( SOCKET, '/api/v1/blueprints/new', module.params['definition']) result['ansible_module_results']['definition'] = client.get_url_raw( SOCKET, '/api/v1/blueprints/info/' + blueprint_name + '?format=toml') result['changed'] = True elif module.params['state'] == 'present' \ and blueprint_present \ and available_blueprint != module.params['definition']: result['ansible_module_results'] = client.post_url_toml( SOCKET, '/api/v1/blueprints/new', module.params['definition']) result['ansible_module_results']['definition'] = client.get_url_raw( SOCKET, '/api/v1/blueprints/info/' + blueprint_name + '?format=toml') result['changed'] = True elif module.params['state'] == 'absent' and blueprint_present: result['ansible_module_results'] = client.delete_url_json( SOCKET, '/api/v1/blueprints/delete/' + blueprint_name) result['changed'] = True else: result['ansible_module_results']['definition'] = client.get_url_raw( SOCKET, '/api/v1/blueprints/info/' + blueprint_name + '?format=toml') result['changed'] = False # in the event of a successful module execution, you will want to # simple AnsibleModule.exit_json(), passing the key/value results module.exit_json(**result)