diff options
author | Pranali Deore <pdeore@redhat.com> | 2022-08-26 04:18:31 +0000 |
---|---|---|
committer | Pranali Deore <pdeore@redhat.com> | 2022-08-30 11:20:40 +0000 |
commit | 92cd70a2240dd5106ebfffecd6007942e898903a (patch) | |
tree | d0e492d705ae60b8ca97f626afda8d6f184e349b /glanceclient/v2 | |
parent | 75218d289ed27b4eddd645436275b1e51aed0fab (diff) | |
download | python-glanceclient-92cd70a2240dd5106ebfffecd6007942e898903a.tar.gz |
Add support for glance-download import method
Implements: blueprint glance-download-import-support
Change-Id: Ia2bfad82bccf9acb6103b21112e680c44e295d39
Diffstat (limited to 'glanceclient/v2')
-rw-r--r-- | glanceclient/v2/images.py | 12 | ||||
-rw-r--r-- | glanceclient/v2/shell.py | 60 |
2 files changed, 66 insertions, 6 deletions
diff --git a/glanceclient/v2/images.py b/glanceclient/v2/images.py index eeb5ee1..67e5f7e 100644 --- a/glanceclient/v2/images.py +++ b/glanceclient/v2/images.py @@ -353,8 +353,9 @@ class Controller(object): @utils.add_req_id_to_object() def image_import(self, image_id, method='glance-direct', uri=None, - backend=None, stores=None, allow_failure=True, - all_stores=None): + remote_region=None, remote_image_id=None, + remote_service_interface=None, backend=None, + stores=None, allow_failure=True, all_stores=None): """Import Image via method.""" headers = {} url = '/v2/images/%s/import' % image_id @@ -370,6 +371,13 @@ class Controller(object): if allow_failure: data['all_stores_must_succeed'] = False + if remote_region and remote_image_id: + if remote_service_interface: + data['method']['glance_service_interface'] = \ + remote_service_interface + data['method']['glance_region'] = remote_region + data['method']['glance_image_id'] = remote_image_id + if uri: if method == 'web-download': data['method']['uri'] = uri diff --git a/glanceclient/v2/shell.py b/glanceclient/v2/shell.py index 84e3639..773c198 100644 --- a/glanceclient/v2/shell.py +++ b/glanceclient/v2/shell.py @@ -148,6 +148,14 @@ def do_image_create(gc, args): 'record if no import-method and no data is supplied')) @utils.arg('--uri', metavar='<IMAGE_URL>', default=None, help=_('URI to download the external image.')) +@utils.arg('--remote-region', metavar='<GLANCE_REGION>', default=None, + help=_('REMOTE_GLANCE_REGION to download the image.')) +@utils.arg('--remote-image-id', metavar='<REMOTE_IMAGE_ID>', default=None, + help=_('The IMAGE ID of the image of remote glance, which needs' + 'to be imported with glance-download')) +@utils.arg('--remote-service-interface', metavar='<REMOTE_SERVICE_INTERFACE>', + default='public', + help=_('The Remote Glance Service Interface for glance-download')) @utils.arg('--store', metavar='<STORE>', default=utils.env('OS_IMAGE_STORE', default=None), help='Backend store to upload image to.') @@ -293,6 +301,22 @@ def do_image_create_via_import(gc, args): utils.exit("You cannot pass data via stdin with the web-download " "import method.") + if args.import_method == 'glance-download': + if not (args.remote_region and args.remote_image_id): + utils.exit("REMOTE GlANCE REGION and REMOTE IMAGE ID are " + "required for glance-download import method. " + "Please use --remote-region <region> and " + "--remote-image-id <remote-image-id>.") + if args.uri: + utils.exit("You cannot specify a --uri with the glance-download " + "import method.") + if file_name: + utils.exit("You cannot specify a --file with the glance-download " + "import method.") + if using_stdin: + utils.exit("You cannot pass data via stdin with the " + "glance-download import method.") + # process image = gc.images.create(**fields) try: @@ -726,6 +750,14 @@ def do_image_stage(gc, args): '"image-stage".')) @utils.arg('--uri', metavar='<IMAGE_URL>', default=None, help=_('URI to download the external image.')) +@utils.arg('--remote-region', metavar='<REMOTE_GLANCE_REGION>', default=None, + help=_('REMOTE GLANCE REGION to download the image.')) +@utils.arg('--remote-image-id', metavar='<REMOTE_IMAGE_ID>', default=None, + help=_('The IMAGE ID of the image of remote glance, which needs' + 'to be imported with glance-download')) +@utils.arg('--remote-service-interface', metavar='<REMOTE_SERVICE_INTERFACE>', + default='public', + help=_('The Remote Glance Service Interface for glance-download')) @utils.arg('id', metavar='<IMAGE_ID>', help=_('ID of image to import.')) @utils.arg('--store', metavar='<STORE>', @@ -757,6 +789,10 @@ def do_image_import(gc, args): stores = getattr(args, "stores", None) all_stores = getattr(args, "os_all_stores", None) allow_failure = getattr(args, "os_allow_failure", True) + uri = getattr(args, "uri", None) + remote_region = getattr(args, "remote-region", None) + remote_image_id = getattr(args, "remote-image-id", None) + remote_service_interface = getattr(args, "remote-service-interface", None) if not getattr(args, 'from_create', False): if (args.store and (stores or all_stores)) or (stores and all_stores): @@ -800,6 +836,20 @@ def do_image_import(gc, args): utils.exit("Import method should be 'web-download' if URI is " "provided.") + if args.import_method == 'glance-download' and \ + not (remote_region and remote_image_id): + utils.exit("Provide REMOTE_IMAGE_ID and remote-region for " + "'glance-download' import method.") + if remote_region and args.import_method != 'glance-download': + utils.exit("Import method should be 'glance-download' if " + "REMOTE REGION is provided.") + if remote_image_id and args.import_method != 'glance-download': + utils.exit("Import method should be 'glance-download' if " + "REMOTE IMAGE ID is provided.") + if remote_service_interface and args.import_method != 'glance-download': + utils.exit("Import method should be 'glance-download' if " + "REMOTE SERVICE INTERFACE is provided.") + if args.import_method == 'copy-image' and not (stores or all_stores): utils.exit("Provide either --stores or --all-stores for " "'copy-image' import method.") @@ -827,10 +877,12 @@ def do_image_import(gc, args): "an image with status 'active'.") # finally, do the import - gc.images.image_import(args.id, args.import_method, args.uri, - backend=backend, - stores=stores, all_stores=all_stores, - allow_failure=allow_failure) + gc.images.image_import(args.id, args.import_method, uri=uri, + remote_region=remote_region, + remote_image_id=remote_image_id, + remote_service_interface=remote_service_interface, + backend=backend, stores=stores, + all_stores=all_stores, allow_failure=allow_failure) image = gc.images.get(args.id) utils.print_image(image) |