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)
def file_upload(context, id, path): """file_upload(context, id, path) Upload a file in a component >>> dcictl component-file-upload [OPTIONS] :param string id: ID of the component to show [required] :param string path: Path to the file to upload [required] """ result = component.file_upload(context, id=id, file_path=path) utils.format_output(result, context.format, 'component_file', component.TABLE_FILE_HEADERS)
def file_upload(context, args): return component.file_upload(context, id=args.id, file_path=args.path)
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'), dest=dict(type='str'), export_control=dict(type='bool'), name=dict(type='str'), type=dict(type='str'), canonical_project_name=dict(type='str'), url=dict(type='str'), data=dict(type='dict'), topic_id=dict(type='str'), path=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: Attach a file to a component # Endpoint called: /components/<component_id>/files/ POST via dci_component.file_upload() # # Attach file to a component elif module.params['path']: res = dci_component.file_upload(ctx, module.params['id'], module.params['path']) # 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, 409]: 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: if not module.params['name']: module.fail_json(msg='name parameter must be speficied') if not module.params['type']: module.fail_json(msg='type parameter must be speficied') kwargs = { 'name': module.params['name'], 'type': module.params['type'], } if module.params['canonical_project_name']: kwargs['canonical_project_name'] = module.params[ 'canonical_project_name'] if module.params['url']: kwargs['url'] = module.params['url'] if module.params['data']: kwargs['data'] = module.params['data'] if module.params['topic_id']: kwargs['topic_id'] = module.params['topic_id'] 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 == 409: result = dci_component.get(ctx, module.params['name']).json() if res.status_code in [400, 401, 409]: result['changed'] = False else: result['changed'] = True except: result = {} result['changed'] = True module.exit_json(**result)