Merge "Implement ability to extend volume."

This commit is contained in:
Jenkins 2013-07-05 16:37:03 +00:00 committed by Gerrit Code Review
commit a7a48b8fee
4 changed files with 36 additions and 0 deletions

View File

@ -159,6 +159,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):
@ -290,6 +294,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

@ -85,3 +85,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

@ -889,3 +889,15 @@ def do_transfer_show(cs, args):
info.pop('links', None)
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(volume, args.new_size)

View File

@ -104,6 +104,14 @@ 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):
"""Manage :class:`Volume` resources."""
@ -321,3 +329,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})