Implement ability to extend volume for v1.

Backport implementation from v2 to v1.

Change-Id: Ibb2334859e937a37481308580b072daef068f511
This commit is contained in:
Mathieu Gagné
2013-07-08 17:59:59 -04:00
parent a3985eeb63
commit d702d5443f
4 changed files with 37 additions and 0 deletions

View File

@@ -152,6 +152,10 @@ def _stub_transfer(id, base_uri, tenant_id):
}
def _stub_extend(id, new_size):
return {'volume_id': '712f4980-5ac1-41e5-9383-390aa7c9f58b'}
class FakeClient(fakes.FakeClient, client.Client):
def __init__(self, *args, **kwargs):
@@ -294,6 +298,8 @@ class FakeHTTPClient(base_client.HTTPClient):
assert body[action] is None
elif action == 'os-reset_status':
assert 'status' in body[action]
elif action == 'os-extend':
assert body[action].keys() == ['new_size']
else:
raise AssertionError("Unexpected action: %s" % action)
return (resp, {}, _body)

View File

@@ -69,3 +69,8 @@ class VolumesTest(utils.TestCase):
keys = ['key1']
cs.volumes.delete_metadata(1234, keys)
cs.assert_called('DELETE', '/volumes/1234/metadata/key1')
def test_extend(self):
v = cs.volumes.get('1234')
cs.volumes.extend(v, 2)
cs.assert_called('POST', '/volumes/1234/action')

View File

@@ -819,3 +819,15 @@ def do_transfer_show(cs, args):
info.pop('links')
utils.print_dict(info)
@utils.arg('volume', metavar='<volume>', help='ID of the volume to extend.')
@utils.arg('new_size',
metavar='<new-size>',
type=int,
help='New size of volume in GB')
@utils.service_type('volume')
def do_extend(cs, args):
"""Attempt to extend the size of an existing volume."""
volume = _find_volume(cs, args.volume)
cs.volumes.extend(volume, args.new_size)

View File

@@ -105,6 +105,15 @@ class Volume(base.Resource):
"""Update the volume with the provided state."""
self.manager.reset_state(self, state)
def extend(self, volume, new_size):
"""Extend the size of the specified volume.
:param volume: The UUID of the volume to extend
:param new_size: The desired size to extend volume to.
"""
self.manager.extend(self, volume, new_size)
class VolumeManager(base.ManagerWithFind):
"""
@@ -338,3 +347,8 @@ class VolumeManager(base.ManagerWithFind):
def reset_state(self, volume, state):
"""Update the provided volume with the provided state."""
return self._action('os-reset_status', volume, {'status': state})
def extend(self, volume, new_size):
return self._action('os-extend',
base.getid(volume),
{'new_size': new_size})