def list(context): """list(context) List all Remote CIs >>> dcictl remoteci-list """ result = remoteci.list(context) utils.format_output(result, context.format, remoteci.RESOURCE, remoteci.TABLE_HEADERS)
def list(context): result = remoteci.list(context) utils.format_output(result.json(), context.format, remoteci.RESOURCE, remoteci.TABLE_HEADERS)
ltopics = topic.list(gcontext).json()['topics'] topicids_to_name = {} for current_topic in ltopics: topicids_to_name[current_topic['id']] = current_topic['name'] # get all teams to get association team_id -> team_name print("[*] Get all teams") lteams = team.list(gcontext).json()['teams'] teams_to_name = {} for current_team in lteams: teams_to_name[current_team['id']] = current_team['name'] # get all remotecis to get the association remoteci_id -> remoteci_name # which will be used below print("[*] Get all remotecis") lremotecis = remoteci.list(gcontext).json()['remotecis'] remotecis_to_name = {} for current_remoteci in lremotecis: remoteci_team_id = current_remoteci['team_id'] remoteci_team_name = teams_to_name[remoteci_team_id] remotecis_to_name[current_remoteci['id']] = (current_remoteci['name'], remoteci_team_name) results = {} for current_job in ljobs: topic_id = current_job['jobdefinition']['topic_id'] if topic_id not in results: results[topic_id] = {} remoteci_id = current_job['remoteci_id']
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'), data=dict(type='dict'), active=dict(type='bool'), team_id=dict(type='str'), ), ) 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 remotecis # Endpoint called: /remotecis GET via dci_remoteci.list() # # List all remotecis if module_params_empty(module.params): res = dci_remoteci.list(ctx) # Action required: Delete the remoteci matching remoteci id # Endpoint called: /remotecis/<remoteci_id> DELETE via dci_remoteci.delete() # # If the remoteci exists and it has been succesfully deleted the changed is # set to true, else if the remoteci 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_remoteci.get(ctx, module.params['id']) if res.status_code not in [400, 401, 404, 409]: kwargs = { 'id': module.params['id'], 'etag': res.json()['remoteci']['etag'] } res = dci_remoteci.delete(ctx, **kwargs) # Action required: Retrieve remoteci informations # Endpoint called: /remotecis/<remoteci_id> GET via dci_remoteci.get() # # Get remoteci informations elif module.params['id'] and not module.params[ 'name'] and not module.params['data'] and not module.params[ 'team_id'] and module.params['active'] is None: res = dci_remoteci.get(ctx, module.params['id']) # Action required: Update an existing remoteci # Endpoint called: /remotecis/<remoteci_id> PUT via dci_remoteci.update() # # Update the remoteci with the specified characteristics. elif module.params['id']: res = dci_remoteci.get(ctx, module.params['id']) if res.status_code not in [400, 401, 404, 409]: kwargs = { 'id': module.params['id'], 'etag': res.json()['remoteci']['etag'] } if module.params['name']: kwargs['name'] = module.params['name'] if module.params['data']: kwargs['data'] = module.params['data'] if module.params['team_id']: kwargs['team_id'] = module.params['team_id'] if module.params['active'] is not None: kwargs['active'] = module.params['active'] open('/tmp/tuiti', 'w').write(str(kwargs.keys())) res = dci_remoteci.update(ctx, **kwargs) # Action required: Create a remoteci with the specified content # Endpoint called: /remotecis POST via dci_remoteci.create() # # Create the new remoteci. else: if not module.params['name']: module.fail_json(msg='name parameter must be specified') if not module.params['team_id']: module.fail_json(msg='team_id parameter must be specified') kwargs = { 'name': module.params['name'], 'team_id': module.params['team_id'] } if module.params['data']: kwargs['data'] = module.params['data'] if module.params['active'] is not None: kwargs['active'] = module.params['active'] res = dci_remoteci.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, args): params = { k: getattr(args, k) for k in ["sort", "limit", "offset", "where"] } return remoteci.list(context, **params)