def list(context, topic_id): """list(context, id) List all jobdefinitions. >>> dcictl jobdefinition-list [OPTIONS] :param string topic_id: Topic ID [required] """ result = jobdefinition.list(context, topic_id) utils.format_output(result, context.format, jobdefinition.RESOURCE, jobdefinition.TABLE_HEADERS)
def test_create_jobdefinition_and_add_component(runner, dci_context, components, test_id, topic_id): create_jobdefinition_and_add_component(dci_context, components, test_id, topic_id, jobdef_name='Test suite') team_id = team.list(dci_context).json()['teams'][0]['id'] topic.attach_team(dci_context, topic_id, team_id) jdefs = jobdefinition.list(dci_context, topic_id).json()['jobdefinitions'] jdef_names = [jdef['name'] for jdef in jdefs] jd_id = [jdef['id'] for jdef in jdefs if jdef['name'] == 'Test suite'][0] assert 'Test suite' in jdef_names jdef_cmpt = jobdefinition.get_components(dci_context, jd_id).json() jdef_cmpt = jdef_cmpt['components'] assert 'component1' == jdef_cmpt[0]['name'] assert 'component2' == jdef_cmpt[1]['name']
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 list(context): result = jobdefinition.list(context) utils.format_output(result.json(), context.format, jobdefinition.RESOURCE, jobdefinition.TABLE_HEADERS)