Example #1
0
def create(context, args):
    data = validate_json(context, "data", args.data)
    state = active_string(args.state)
    team_id = args.team_id or identity.my_team_id(context)
    return remoteci.create(context,
                           name=args.name,
                           team_id=team_id,
                           data=data,
                           state=state)
Example #2
0
def test_embed(dci_context):
    team_id = team.create(dci_context, name="teama").json()["team"]["id"]

    rci = remoteci.create(dci_context, name="boa", team_id=team_id).json()
    rci_id = rci["remoteci"]["id"]

    rci_with_embed = remoteci.get(dci_context, id=rci_id, embed="team").json()
    embed_team_id = rci_with_embed["remoteci"]["team"]["id"]

    assert team_id == embed_team_id
Example #3
0
def remoteci_id(dci_context, team_user_id):
    kwargs = {
        "name": "remoteci",
        "team_id": team_user_id,
        "data": {
            "remoteci": "remoteci"
        },
    }
    rci = api_remoteci.create(dci_context, **kwargs).json()
    return rci["remoteci"]["id"]
def test_embed(dci_context):
    team_id = team.create(dci_context, name="teama").json()["team"]["id"]

    rci = remoteci.create(dci_context, name="boa", team_id=team_id).json()
    rci_id = rci["remoteci"]["id"]

    rci_with_embed = remoteci.get(dci_context, id=rci_id, embed=["team"]).json()
    embed_team_id = rci_with_embed["remoteci"]["team"]["id"]

    assert team_id == embed_team_id
def test_embed(dci_context):
    team_id = team.create(dci_context, name='teama').json()['team']['id']

    rci = remoteci.create(dci_context, name='boa', team_id=team_id).json()
    rci_id = rci['remoteci']['id']

    rci_with_embed = remoteci.get(dci_context,
                                  id=rci_id, embed='team').json()
    embed_team_id = rci_with_embed['remoteci']['team']['id']

    assert team_id == embed_team_id
Example #6
0
def create(context, name, team_id, data, active):
    """create(context, name, team_id, data, active)

    Create a Remote CI

    >>> dcictl remoteci-create [OPTIONS]

    :param string name: Name of the Remote CI [required]
    :param string team_id: ID of the team to associate this remote CI with
        [required]
    :param string data: JSON data to pass during remote CI creation
    :param boolean active: Mark remote CI active
    :param boolean no-active: Mark remote CI inactive
    """
    team_id = team_id or user.get(context.login).json()['user']['team_id']
    data = json.loads(data)
    result = remoteci.create(context, name=name, team_id=team_id, data=data,
                             active=active)
    utils.format_output(result, context.format, None, remoteci.TABLE_HEADERS)
Example #7
0
def job_id(dci_context):
    my_team = team.create(dci_context, name='tname').json()['team']
    my_remoteci = remoteci.create(dci_context,
                                  name='tname', team_id=my_team['id'],
                                  data={'remoteci': 'remoteci'}).json()
    my_remoteci_id = my_remoteci['remoteci']['id']
    my_test = test.create(
        dci_context, name='tname', data={'test': 'test'}).json()
    my_test_id = my_test['test']['id']
    my_jobdefinition = jobdefinition.create(
        dci_context, name='tname', test_id=my_test_id).json()
    my_component = component.create(
        dci_context, name='hihi', type='git_review',
        data={'component': 'component'}).json()
    my_component_id = my_component['component']['id']
    jobdefinition.add_component(dci_context,
                                my_jobdefinition['jobdefinition']['id'],
                                my_component_id)
    my_job = job.schedule(dci_context, my_remoteci_id).json()
    return my_job['job']['id']
Example #8
0
def create(context, name, team_id, data, active):
    data = json.loads(data)
    result = remoteci.create(context, name=name, team_id=team_id, data=data,
                             active=active)
    utils.format_output(result.json(), context.format, remoteci.RESOURCE[:-1])
Example #9
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)