diff --git a/cinderclient/tests/v2/fakes.py b/cinderclient/tests/v2/fakes.py index e888a8b2c..dd2b8feb7 100644 --- a/cinderclient/tests/v2/fakes.py +++ b/cinderclient/tests/v2/fakes.py @@ -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) diff --git a/cinderclient/tests/v2/test_volumes.py b/cinderclient/tests/v2/test_volumes.py index a66dd8ce1..8a2560dc9 100644 --- a/cinderclient/tests/v2/test_volumes.py +++ b/cinderclient/tests/v2/test_volumes.py @@ -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') diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py index 2c009285a..19871350c 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -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) diff --git a/cinderclient/v2/volumes.py b/cinderclient/v2/volumes.py index 3982e4e5c..273668f98 100644 --- a/cinderclient/v2/volumes.py +++ b/cinderclient/v2/volumes.py @@ -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})