Пример #1
0
def show(context, id):
    """show(context, id)

    Show a test.

    >>> dcictl test-show [OPTIONS]

    :param string id: ID of the test to return [required]
    """
    result = test.get(context, id=id)
    utils.format_output(result, context.format,
                        test.RESOURCE[:-1], test.TABLE_HEADERS)
Пример #2
0
def get_test_id(dci_context, name):
    print("Use test '%s'" % name)
    test.create(dci_context, name)
    return test.get(dci_context, name).json()['test']['id']
Пример #3
0
def show(context, args):
    return test.get(context, id=args.id)
Пример #4
0
def show(context, id):
    result = test.get(context, id=id)
    utils.format_output(result.json(), context.format,
                        test.RESOURCE[:-1], test.TABLE_HEADERS)
Пример #5
0
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'),
            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 test matching test id
    # Endpoint called: /tests/<test_id> DELETE via dci_test.delete()
    #
    # If the test exists and it has been succesfully deleted the changed is
    # set to true, else if the test 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_test.delete(ctx, module.params['id'])

    # Action required: Retrieve test informations
    # Endpoint called: /tests/<test_id> GET via dci_test.get()
    #
    # Get test informations
    elif module.params['id']:
        res = dci_test.get(ctx, module.params['id'])

    # Action required: Create a test with the specified content
    # Endpoint called: /tests POST via dci_test.create()
    #
    # Create the new test.
    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']

        res = dci_test.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)