diff options
author | PranaliD <pdeore@redhat.com> | 2018-03-12 05:38:34 -0400 |
---|---|---|
committer | Erno Kuvaja <jokke@usr.fi> | 2018-03-21 15:09:13 +0000 |
commit | aedabec9e46e80266cdefb315f112a30927e216a (patch) | |
tree | 602cebe7c19726f1a85d900c4b05f4c48f1bd1a3 /glanceclient/v2 | |
parent | 558580febfe7c468e6aefe4dc78f28be30f74ace (diff) | |
download | python-glanceclient-aedabec9e46e80266cdefb315f112a30927e216a.tar.gz |
Add support for web-download import method
This change adds support for 'web-download' import method
to 'image-import' and 'create-image-via-import' call.
To use this 'web-download' import method, user needs to pass
--uri option 'a valid uri to external image to import in glance'
to 'image-import' and 'create-image-via-imaport' calls.
Co-authored-by: Pranali Deore <pdeore@redhat.com>
Co-authored-by: Erno Kuvaja <jokke@usr.fi>
Change-Id: I0e1d18844f64723608288de473e97710798eb602
Diffstat (limited to 'glanceclient/v2')
-rw-r--r-- | glanceclient/v2/images.py | 8 | ||||
-rw-r--r-- | glanceclient/v2/shell.py | 26 |
2 files changed, 28 insertions, 6 deletions
diff --git a/glanceclient/v2/images.py b/glanceclient/v2/images.py index 29abc30..89aa912 100644 --- a/glanceclient/v2/images.py +++ b/glanceclient/v2/images.py @@ -254,10 +254,16 @@ class Controller(object): return body, resp @utils.add_req_id_to_object() - def image_import(self, image_id, method='glance-direct'): + def image_import(self, image_id, method='glance-direct', uri=None): """Import Image via method.""" url = '/v2/images/%s/import' % image_id data = {'method': {'name': method}} + if uri: + if method == 'web-download': + data['method']['uri'] = uri + else: + raise exc.HTTPBadRequest('URI is only supported with method: ' + '"web-download"') resp, body = self.http_client.post(url, data=data) return body, resp diff --git a/glanceclient/v2/shell.py b/glanceclient/v2/shell.py index c9f1fe1..2b83304 100644 --- a/glanceclient/v2/shell.py +++ b/glanceclient/v2/shell.py @@ -105,6 +105,8 @@ def do_image_create(gc, args): @utils.arg('--import-method', metavar='<METHOD>', default='glance-direct', help=_('Import method used for Image Import workflow. ' 'Valid values can be retrieved with import-info command.')) +@utils.arg('--uri', metavar='<IMAGE_URL>', default=None, + help=_('URI to download the external image.')) @utils.on_data_require_fields(DATA_FIELDS) def do_image_create_via_import(gc, args): """EXPERIMENTAL: Create a new image via image import.""" @@ -129,15 +131,22 @@ def do_image_create_via_import(gc, args): 'glance-direct' not in import_methods.get('value')): utils.exit("No suitable import method available for direct upload, " "please use image-create instead.") + if args.import_method == 'web-download' and not args.uri: + utils.exit("URI is required for web-download import method. " + "Please use '--uri <uri>'.") + if args.uri and args.import_method != 'web-download': + utils.exit("Import method should be 'web-download' if URI is " + "provided.") + image = gc.images.create(**fields) try: + args.id = image['id'] if utils.get_data_file(args) is not None: - args.id = image['id'] args.size = None do_image_stage(gc, args) - args.from_create = True - do_image_import(gc, args) - image = gc.images.get(args.id) + args.from_create = True + do_image_import(gc, args) + image = gc.images.get(args.id) finally: utils.print_image(image) @@ -418,12 +427,19 @@ def do_image_stage(gc, args): 'Valid values can be retrieved with import-info command ' 'and the default "glance-direct" is used with ' '"image-stage".')) +@utils.arg('--uri', metavar='<IMAGE_URL>', default=None, + help=_('URI to download the external image.')) @utils.arg('id', metavar='<IMAGE_ID>', help=_('ID of image to import.')) def do_image_import(gc, args): """Initiate the image import taskflow.""" try: - gc.images.image_import(args.id, args.import_method) + if args.import_method == 'web-download' and not args.uri: + utils.exit("Provide URI for web-download import method.") + if args.uri and args.import_method != 'web-download': + utils.exit("Import method should be 'web-download' if URI is " + "provided.") + gc.images.image_import(args.id, args.import_method, args.uri) except exc.HTTPNotFound: utils.exit('Target Glance does not support Image Import workflow') else: |