示例#1
0
def delete(context, id, etag):
    result = remoteci.delete(context, id=id, etag=etag)

    if result.status_code == 204:
        utils.format_output({'id': id,
                             'message': 'Remote CI deleted.'},
                            context.format)
    else:
        utils.format_output(result.json(), context.format)
示例#2
0
def delete(context, id, etag):
    """delete(context, id, etag)

    Delete a Remote CI.

    >>> dcictl remoteci-delete [OPTIONS]

    :param string id: ID of the remote CI to delete [required]
    :param string etag: Entity tag of the remote CI resource [required]
    """
    result = remoteci.delete(context, id=id, etag=etag)

    if result.status_code == 204:
        utils.print_json({'id': id, 'message': 'Remote CI deleted.'})
    else:
        utils.format_output(result, context.format)
示例#3
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)
示例#4
0
def delete(context, args):
    return remoteci.delete(context, id=args.id, etag=args.etag)