Esempio n. 1
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)
Esempio n. 2
0
def file_list(context, id):
    """file_list(context, id, path)

    Show a component file

    >>> dcictl component-file-list [OPTIONS]

    :param string id: ID of the component to show [required]
    """
    result = component.file_list(context, id=id)
    utils.format_output(result, context.format, 'component_files',
                        component.TABLE_FILE_HEADERS)
Esempio n. 3
0
def file_list(context, args):
    params = {
        k: getattr(args, k)
        for k in ["id", "sort", "limit", "offset", "where"]
    }
    return component.file_list(context, **params)
Esempio n. 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'),
            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)