diff --git a/cinderclient/tests/v1/fakes.py b/cinderclient/tests/v1/fakes.py index 2a33ba8..56f086b 100644 --- a/cinderclient/tests/v1/fakes.py +++ b/cinderclient/tests/v1/fakes.py @@ -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) diff --git a/cinderclient/tests/v1/test_volumes.py b/cinderclient/tests/v1/test_volumes.py index 16410c9..768e942 100644 --- a/cinderclient/tests/v1/test_volumes.py +++ b/cinderclient/tests/v1/test_volumes.py @@ -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') diff --git a/cinderclient/v1/shell.py b/cinderclient/v1/shell.py index f3ac3d9..eeb30ba 100644 --- a/cinderclient/v1/shell.py +++ b/cinderclient/v1/shell.py @@ -819,3 +819,15 @@ def do_transfer_show(cs, args): info.pop('links') utils.print_dict(info) + + +@utils.arg('volume', metavar='', help='ID of the volume to extend.') +@utils.arg('new_size', + metavar='', + 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) diff --git a/cinderclient/v1/volumes.py b/cinderclient/v1/volumes.py index 066890d..5f6c566 100644 --- a/cinderclient/v1/volumes.py +++ b/cinderclient/v1/volumes.py @@ -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})