示例#1
0
def update(context, id, etag, name, team_id, data, active):
    result = remoteci.update(context, id=id, etag=etag, name=name,
                             team_id=team_id, data=data, active=active)
    if result.status_code == 204:
        utils.format_output({'id': id,
                             'etag': etag,
                             'name': name,
                             'active': active,
                             'message': 'Remote CI updated.'},
                            context.format)
    else:
        utils.format_output(result.json(), context.format)
示例#2
0
def update(context, args):
    data = validate_json(context, "data", args.data)
    state = active_string(args.state)
    return remoteci.update(
        context,
        id=args.id,
        etag=args.etag,
        name=args.name,
        team_id=args.team_id,
        data=data,
        state=state,
    )
示例#3
0
def update(context, id, etag, name, team_id, data, active):
    """update(context, id, etag, name, team_id, data, active)

    Update a Remote CI.

    >>> dcictl remoteci-update [OPTIONS]

    :param string id: ID of the remote CI [required]
    :param string etag: Entity tag of the remote CI resource [required]
    :param string name: Name of the Remote CI
    :param string team_id: ID of the team to associate this remote CI with
    :param string data: JSON data to pass during remote CI update
    :param boolean active: Mark remote CI active
    :param boolean no-active: Mark remote CI inactive
    """
    result = remoteci.update(context, id=id, etag=etag, name=name,
                             team_id=team_id, data=data, active=active)
    if result.status_code == 204:
        utils.print_json({'id': id, 'message': 'Remote CI updated.'})
    else:
        utils.format_output(result, context.format)
示例#4
0
def main():
    module = AnsibleModule(
        argument_spec=dict(
            state=dict(default='present', choices=['present', 'absent'], type='str'),
            # Authentication related parameters
            #
            login=dict(required=False, type='str'),
            password=dict(required=False, type='str'),
            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: 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
    if 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, 422]:
            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, 422]:
            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 == 422:
            result['changed'] = False
        else:
            result['changed'] = True
    except:
        result = {}
        result['changed'] = True

    module.exit_json(**result)