def create_jobdefinition(dci_context, components, test_ids,
                         topic_id, jobdef_name=None):
    # If at least one component doesn't exist in the database then a new
    # jobdefinition must be created.
    at_least_one = False
    component_ids = []
    names = []
    for cmpt in components:
        names.append(cmpt['name'])
        created_cmpt = component.create(dci_context, **cmpt)
        if created_cmpt.status_code == 201:
            at_least_one = True
        elif created_cmpt.status_code == 422:
            created_cmpt = component.get(dci_context, cmpt['name'])
        created_cmpt_name = created_cmpt.json()['component']['name']
        component_ids.append(created_cmpt.json()['component']['id'])

    if at_least_one:
        if jobdef_name is None:
            jobdef_name = created_cmpt_name
        jobdef = jobdefinition.create(dci_context, jobdef_name, topic_id)
        if jobdef.status_code == 201:
            jobdef_id = jobdef.json()['jobdefinition']['id']
            for cmpt_id in component_ids:
                jobdefinition.add_component(dci_context, jobdef_id, cmpt_id)
            for test_id in test_ids:
                jobdefinition.add_test(dci_context, jobdef_id, test_id)
            print("Jobdefinition '%s' created." % jobdef_name)
        else:
            print("Error on jobdefinition creation: '%s'", jobdef.json())
    else:
        print("No jobdefinition created.")
Exemple #2
0
def update(context, args):
    component_info = component.get(context, args.id)

    etag = component_info.json()["component"]["etag"]

    return component.update(context,
                            id=args.id,
                            etag=etag,
                            state=active_string(args.state))
Exemple #3
0
def refresh_puddles(ctx):
    versions = [
        {
            'name': '10.0',
            'urls': [
                'http://download.eng.bos.redhat.com/rcm-guest/puddles/OpenStack/10.0-RHEL-7/latest/RH7-RHOS-10.0.repo',  # noqa
             ],
            'topic_id': dci_topic.get(ctx, 'OSP10').json()['topic']['id']
        },
        {
            'name': '9.0',
            'urls': [
                'http://download.eng.bos.redhat.com/rcm-guest/puddles/OpenStack/9.0-RHEL-7/latest/RH7-RHOS-9.0.repo',  # noqa
                'http://download.eng.bos.redhat.com/rcm-guest/puddles/OpenStack/9.0-RHEL-7-director/latest/RH7-RHOS-9.0-director.repo'],  # noqa
            'topic_id': dci_topic.get(ctx, 'OSP9').json()['topic']['id']
        },
        {
            'name': '8.0',
            'urls': [
                'http://download.eng.bos.redhat.com/rel-eng/OpenStack/8.0-RHEL-7/latest/RH7-RHOS-8.0.repo',  # noqa
                'http://download.eng.bos.redhat.com/rel-eng/OpenStack/8.0-RHEL-7-director/latest/RH7-RHOS-8.0-director.repo'],  # noqa
            'topic_id': dci_topic.get(ctx, 'OSP8').json()['topic']['id']
        }
    ]

    for v in versions:
        components = get_components(v['urls'], v['topic_id'])
        for c in components:
            dci_component.create(ctx, **c)
            r = dci_component.get(ctx, c['name'], embed='file')
            if r.status_code == 401:
                continue
            if r.status_code == 404:
                print('Component %s not found' % c['name'])
                exit(1)
            component = r.json()['component']
            r_current_components = dci_component.file_list(
                ctx, id=component['id'])
            if len(r_current_components.json()['component_files']):
                print('%s already has its data. Skipped.' % component['name'])
                continue

            clean_up(component)
            prepare_archive(component)
            print('Uploading bits...')
            r = dci_component.file_upload(
                ctx, id=component['id'], file_path='archive.tar')
            if r.status_code != 201:
                print((
                    '  Upload of archive.tar has '
                    'failed for component %s: %s') % (
                        component['name'], r.text))
                exit(1)
            else:
                print('  success: %s' % r.json())
            clean_up(component)
Exemple #4
0
def get_component_by_id(component_id):
    context = build_signature_context()
    c = dci_component.get(context, component_id)
    component = c.json()["component"]
    if len(component) == 0:
        print("Ensure that component %s exists or that you have access" %
              component_id)
        print("Contact your EPM for more information.")
        return
    return component
def show(context, id):
    """show(context, id)

    Show a component

    >>> dcictl component-show [OPTIONS]

    :param string id: ID of the component to show [required]
    """
    result = component.get(context, id=id)
    utils.format_output(result, context.format, component.RESOURCE[:-1],
                        component.TABLE_HEADERS)
def update(context, id, export_control):
    """update(context, id, export_control)

    Update a component

    >>> dcictl component-update [OPTIONS]

    :param string id: ID of the component [required]
    """

    component_info = component.get(context, id=id)

    etag = component_info.json()['component']['etag']
    result = component.update(context, id=id, etag=etag,
                              export_control=export_control)

    if result.status_code == 204:
        status = 'Enabled' if export_control else 'Disabled'
        utils.print_json({'id': id, 'message': 'Export Control %s.' % status})
    else:
        utils.format_output(result, context.format)
Exemple #7
0
def show(context, args):
    return component.get(context, args.id)
def show(context, id):
    result = component.get(context, id=id).json()
    utils.format_output(result, context.format, component.RESOURCE[:-1],
                        component.TABLE_HEADERS)
Exemple #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'),
            dest=dict(type='str'),
            export_control=dict(type='bool'),
            #title=dict(type='str'),
            #message=dict(type='str'),
            #canonical_project_name=dict(type='str'),
            #component_url=dict(type='str'),
            #type=dict(type='str'),
            #active=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 component matching the component id
    # Endpoint called: /components/<component_id> DELETE via dci_component.delete()
    #
    # If the component exist and it has been succesfully deleted the changed is
    # set to true, else if the file 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_component.delete(ctx, module.params['id'])

    # Action required: Download a component
    # Endpoint called: /components/<component_id>/files/<file_id>/content GET via dci_component.file_download()
    #
    # Download the component
    elif module.params['dest']:
        component_file = dci_component.file_list(
            ctx, module.params['id']).json()['component_files'][0]
        res = dci_component.file_download(ctx, module.params['id'],
                                          component_file['id'],
                                          module.params['dest'])

    # Action required: Get component informations
    # Endpoint called: /components/<component_id> GET via dci_component.get()
    #
    # Get component informations
    elif module.params['id'] and module.params['export_control'] is None:
        res = dci_component.get(ctx, module.params['id'])

    # Action required: Update an existing component
    # Endpoint called: /components/<component_id> PUT via dci_component.update()
    #
    # Update the component with the specified parameters.
    elif module.params['id']:
        res = dci_component.get(ctx, module.params['id'])
        if res.status_code not in [400, 401, 404, 422]:
            updated_kwargs = {
                'id': module.params['id'],
                'etag': res.json()['component']['etag']
            }
            if module.params['export_control'] is not None:
                updated_kwargs['export_control'] = module.params[
                    'export_control']

            res = dci_component.update(ctx, **updated_kwargs)

    # Action required: Create a new component
    # Endpoint called: /component POST via dci_component.create()
    #
    # Create a new component
    else:
        # TODO
        module.fail_json(msg='Not implemented yet')
        # kwargs = {}
        # if module.params['export_control']:
        #    kwargs['export_control'] = module.params['export_control']
        #res = dci_component.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 in [400, 401, 422]:
            result['changed'] = False
        else:
            result['changed'] = True
    except:
        result = {}
        result['changed'] = True

    module.exit_json(**result)