Add upload-to-image function to client.

Support uploading a volume to an image in the image service.

Change-Id: Ief996f92aaf6d7a4fee0bce5ca45b92bee3f6990
Fixes: bug #1099866
This commit is contained in:
Avishay Traeger 2013-01-16 15:45:29 +02:00
parent 61e2a4237f
commit 9a064c3d5c
3 changed files with 57 additions and 3 deletions

View File

@ -356,7 +356,7 @@ def do_snapshot_show(cs, args):
@utils.arg('--force',
metavar='<True|False>',
help='Optional flag to indicate whether '
'to snapshot a volume even if its '
'to snapshot a volume even if it\'s '
'attached to an instance. (Default=False)',
default=False)
@utils.arg(
@ -600,3 +600,35 @@ def _print_type_extra_specs(vol_type):
def _find_volume_type(cs, vtype):
"""Get a volume type by name or ID."""
return utils.find_resource(cs.volume_types, vtype)
@utils.arg('volume_id',
metavar='<volume-id>',
help='ID of the volume to snapshot')
@utils.arg('--force',
metavar='<True|False>',
help='Optional flag to indicate whether '
'to upload a volume even if it\'s '
'attached to an instance. (Default=False)',
default=False)
@utils.arg('--container-format',
metavar='<container-format>',
help='Optional type for container format '
'(Default=bare)',
default='bare')
@utils.arg('--disk-format',
metavar='<disk-format>',
help='Optional type for disk format '
'(Default=raw)',
default='raw')
@utils.arg('image_name',
metavar='<image-name>',
help='Name for created image')
@utils.service_type('volume')
def do_upload_to_image(cs, args):
"""Upload volume to image service as image."""
volume = _find_volume(cs, args.volume_id)
volume.upload_to_image(args.force,
args.image_name,
args.container_format,
args.disk_format)

View File

@ -104,6 +104,14 @@ class Volume(base.Resource):
"""
return self.manager.set_metadata(self, metadata)
def upload_to_image(self, force, image_name, container_format,
disk_format):
"""
Upload a volume to image service as an image.
"""
self.manager.upload_to_image(self, force, image_name, container_format,
disk_format)
class VolumeManager(base.ManagerWithFind):
"""
@ -316,3 +324,17 @@ class VolumeManager(base.ManagerWithFind):
"""
for k in keys:
self._delete("/volumes/%s/metadata/%s" % (base.getid(volume), k))
def upload_to_image(self, volume, force, image_name, container_format,
disk_format):
"""
Upload volume to image service as image.
:param volume: The :class:`Volume` to upload.
"""
return self._action('os-volume_upload_image',
volume,
{'force': force,
'image_name': image_name,
'container_format': container_format,
'disk_format': disk_format})

View File

@ -55,7 +55,7 @@ class ShellTest(utils.TestCase):
help_text = self.shell('help')
for r in required:
self.assertThat(help_text,
matchers.MatchesRegex(r, re.DOTALL|re.MULTILINE))
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
def test_help_on_subcommand(self):
required = [
@ -65,4 +65,4 @@ class ShellTest(utils.TestCase):
help_text = self.shell('help list')
for r in required:
self.assertThat(help_text,
matchers.MatchesRegex(r, re.DOTALL|re.MULTILINE))
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))