def delete(context, id, etag): """delete(context, id, etag) Delete a jobdefinition. >>> dcictl jobdefinition-delete [OPTIONS] :param string id: ID of the jobdefinition to delete [required] :param string etag: Entity tag of the jobdefinition resource [required] """ result = jobdefinition.delete(context, id=id, etag=etag) if result.status_code == 204: utils.print_json({'id': id, 'message': 'Job Definition deleted.'}) else: utils.format_output(result, context.format)
def main(): module = AnsibleModule( argument_spec=dict( state=dict(default='present', choices=['present', 'absent'], type='str'), # Authentication related parameters # dci_login=dict(required=False, type='str'), dci_password=dict(required=False, type='str'), dci_cs_url=dict(required=False, type='str'), # Resource related parameters # id=dict(type='str'), name=dict(type='str'), priority=dict(type='int'), topic_id=dict(type='str'), active=dict(type='bool'), comment=dict(type='str'), component_types=dict(type='list'), ), ) if not dciclient_found: module.fail_json(msg='The python dciclient module is required') login, password, url = get_details(module) if not login or not password: module.fail_json(msg='login and/or password have not been specified') ctx = dci_context.build_dci_context(url, login, password, 'Ansible') # Action required: List all jobdefinitions # Endpoint called: /jobdefinitions GET via dci_jobdefinition.list() # # List all jobdefinitions if module_params_empty(module.params): res = dci_jobdefinition.list(ctx) # Action required: Delete the jobdefinition matching jobdefinition id # Endpoint called: /jobdefinitions/<jobdefinition_id> DELETE via dci_jobdefinition.delete() # # If the jobdefinition exists and it has been succesfully deleted the changed is # set to true, else if the jobdefinition does not exist changed is set to False elif module.params['state'] == 'absent': if not module.params['id']: module.fail_json(msg='id parameter is required') res = dci_jobdefinition.get(ctx, module.params['id']) if res.status_code not in [400, 401, 404, 409]: kwargs = { 'id': module.params['id'], 'etag': res.json()['jobdefinition']['etag'] } res = dci_jobdefinition.delete(ctx, **kwargs) # Action required: Retrieve jobdefinition informations # Endpoint called: /jobdefinitions/<jobdefinition_id> GET via dci_jobdefinition.get() # # Get jobdefinition informations elif module.params[ 'id'] and not module.params['comment'] and not module.params[ 'component_types'] and module.params['active'] is None: res = dci_jobdefinition.get(ctx, module.params['id']) # Action required: Update an existing jobdefinition # Endpoint called: /jobdefinitions/<jobdefinition_id> PUT via dci_jobdefinition.update() # # Update the jobdefinition with the specified characteristics. elif module.params['id']: res = dci_jobdefinition.get(ctx, module.params['id']) if res.status_code not in [400, 401, 404, 409]: kwargs = { 'id': module.params['id'], 'etag': res.json()['jobdefinition']['etag'] } if module.params['comment']: kwargs['comment'] = module.params['comment'] if module.params['component_types']: kwargs['component_types'] = module.params['component_types'] if module.params['active'] is not None: kwargs['active'] = module.params['active'] res = dci_jobdefinition.update(ctx, **kwargs) # Action required: Creat a jobdefinition with the specified content # Endpoint called: /jobdefinitions POST via dci_jobdefinition.create() # # Create the new jobdefinition. else: if not module.params['name']: module.fail_json(msg='name parameter must be specified') if not module.params['topic_id']: module.fail_json(msg='topic_id parameter must be specified') kwargs = { 'name': module.params['name'], 'topic_id': module.params['topic_id'] } if module.params['priority']: kwargs['priority'] = module.params['priority'] if module.params['comment']: kwargs['comment'] = module.params['comment'] if module.params['component_types']: kwargs['component_types'] = module.params['component_types'] if module.params['active'] is not None: kwargs['active'] = module.params['active'] res = dci_jobdefinition.create(ctx, **kwargs) try: result = res.json() if res.status_code == 404: module.fail_json(msg='The resource does not exist') if res.status_code == 409: result['changed'] = False else: result['changed'] = True except: result = {} result['changed'] = True module.exit_json(**result)
def delete(context, id, etag): result = jobdefinition.delete(context, id=id, etag=etag) if result.status_code == 204: utils.format_output({"id": id, "message": "Job Definition deleted."}, context.format) else: utils.format_output(result.json(), context.format)