diff options
| author | Terry Howe <terrylhowe@gmail.com> | 2014-02-26 12:13:01 -0700 |
|---|---|---|
| committer | Terry Howe <terrylhowe@gmail.com> | 2014-03-05 11:26:13 -0700 |
| commit | e6e0dbf754c4dbc631e5c797b50d8032481a1a27 (patch) | |
| tree | 976236c94e2619e1b5425595e0c5e9b5330d8be5 /openstackclient/image | |
| parent | b7f673cb81f1a6539739dc6d12eaef7455bf63fd (diff) | |
| download | python-openstackclient-e6e0dbf754c4dbc631e5c797b50d8032481a1a27.tar.gz | |
Add --volume option to image create command
Add ability to create an image from a volume.
* Added --volume command to image create
* Added --force option to image create
* Added block to access volume manager in image create
* Tests added for the volume option
Change-Id: I3910a2b5e04acd0d15dd230747ba6ebca07aa316
Closes-Bug: #1207615
Diffstat (limited to 'openstackclient/image')
| -rw-r--r-- | openstackclient/image/v1/image.py | 59 |
1 files changed, 43 insertions, 16 deletions
diff --git a/openstackclient/image/v1/image.py b/openstackclient/image/v1/image.py index 026b583c..8c1501bd 100644 --- a/openstackclient/image/v1/image.py +++ b/openstackclient/image/v1/image.py @@ -112,6 +112,19 @@ class CreateImage(show.ShowOne): " should immediately be copied from the data store", ) parser.add_argument( + "--volume", + metavar="<volume>", + help="Create the image from the specified volume", + ) + parser.add_argument( + "--force", + dest='force', + action='store_true', + default=False, + help="If the image is created from a volume, force creation of the" + " image even if volume is in use.", + ) + parser.add_argument( "--property", dest="properties", metavar="<key=value>", @@ -162,7 +175,9 @@ class CreateImage(show.ShowOne): args.pop("variables") if "location" not in args and "copy_from" not in args: - if "file" in args: + if "volume" in args: + pass + elif "file" in args: args["data"] = open(args.pop("file"), "rb") else: args["data"] = None @@ -171,23 +186,35 @@ class CreateImage(show.ShowOne): msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) args["data"] = sys.stdin - image_client = self.app.client_manager.image - try: - image = utils.find_resource( - image_client.images, - parsed_args.name, - ) - except exceptions.CommandError: - # This is normal for a create or reserve (create w/o an image) - image = image_client.images.create(**args) + if "volume" in args: + volume_client = self.app.client_manager.volume + source_volume = utils.find_resource(volume_client.volumes, + parsed_args.volume) + response, body = volume_client.volumes.upload_to_image( + source_volume, + parsed_args.force, + parsed_args.name, + parsed_args.container_format, + parsed_args.disk_format) + info = body['os-volume_upload_image'] else: - # It must be an update - # If an image is specified via --file, --location or --copy-from - # let the API handle it - image = image_client.images.update(image, **args) + image_client = self.app.client_manager.image + try: + image = utils.find_resource( + image_client.images, + parsed_args.name, + ) + except exceptions.CommandError: + # This is normal for a create or reserve (create w/o an image) + image = image_client.images.create(**args) + else: + # It must be an update + # If an image is specified via --file, --location or + # --copy-from let the API handle it + image = image_client.images.update(image, **args) - info = {} - info.update(image._info) + info = {} + info.update(image._info) return zip(*sorted(six.iteritems(info))) |
