From 806fa65d84c200ffa33e11461c280cadde9912ed Mon Sep 17 00:00:00 2001 From: liyingjun Date: Wed, 9 Sep 2015 10:08:19 +0800 Subject: [PATCH] Updating volume type 'is_public' status support Cinder supports updating volume type 'is_public' status, it should be added in cinderclient also. New option 'is_public' will be introduced for 'cinder type-update'. DocImpact Change-Id: Ibfa9ba16c0775e401f6eda0729fcf34a99a14697 Closes-bug: #1493612 --- cinderclient/tests/unit/v2/test_shell.py | 9 +++++++++ cinderclient/tests/unit/v2/test_types.py | 5 +++-- cinderclient/v2/shell.py | 9 +++++++-- cinderclient/v2/volume_types.py | 4 +++- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/cinderclient/tests/unit/v2/test_shell.py b/cinderclient/tests/unit/v2/test_shell.py index 3a88691be..128e1450e 100644 --- a/cinderclient/tests/unit/v2/test_shell.py +++ b/cinderclient/tests/unit/v2/test_shell.py @@ -559,6 +559,15 @@ class ShellTest(utils.TestCase): '--is-public=False') self.assert_called('POST', '/types', body=expected) + def test_type_update(self): + expected = {'volume_type': {'name': 'test-type-1', + 'description': 'test_type-1-desc', + 'is_public': False}} + self.run_command('type-update --name test-type-1 ' + '--description=test_type-1-desc ' + '--is-public=False 1') + self.assert_called('PUT', '/types/1', body=expected) + def test_type_access_list(self): self.run_command('type-access-list --volume-type 3') self.assert_called('GET', '/types/3/os-volume-type-access') diff --git a/cinderclient/tests/unit/v2/test_types.py b/cinderclient/tests/unit/v2/test_types.py index 8225a098f..2a24caf34 100644 --- a/cinderclient/tests/unit/v2/test_types.py +++ b/cinderclient/tests/unit/v2/test_types.py @@ -54,11 +54,12 @@ class TypesTest(utils.TestCase): self.assertIsInstance(t, volume_types.VolumeType) def test_update(self): - t = cs.volume_types.update('1', 'test_type_1', 'test_desc_1') + t = cs.volume_types.update('1', 'test_type_1', 'test_desc_1', False) cs.assert_called('PUT', '/types/1', {'volume_type': {'name': 'test_type_1', - 'description': 'test_desc_1'}}) + 'description': 'test_desc_1', + 'is_public': False}}) self.assertIsInstance(t, volume_types.VolumeType) def test_get(self): diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py index c2ac8bfc9..49bbeb2a8 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -804,10 +804,15 @@ def do_type_default(cs, args): @utils.arg('--description', metavar='', help='Description of the volume type.') +@utils.arg('--is-public', + metavar='', + help='Make type accessible to the public or not.') @utils.service_type('volumev2') def do_type_update(cs, args): - """Updates volume type name and/or description.""" - vtype = cs.volume_types.update(args.id, args.name, args.description) + """Updates volume type name ,description and/or is_public.""" + is_public = strutils.bool_from_string(args.is_public) + vtype = cs.volume_types.update(args.id, args.name, args.description, + is_public) _print_volume_type_list([vtype]) diff --git a/cinderclient/v2/volume_types.py b/cinderclient/v2/volume_types.py index 598004f2d..bcaab4bca 100644 --- a/cinderclient/v2/volume_types.py +++ b/cinderclient/v2/volume_types.py @@ -128,7 +128,7 @@ class VolumeTypeManager(base.ManagerWithFind): return self._create("/types", body, "volume_type") - def update(self, volume_type, name=None, description=None): + def update(self, volume_type, name=None, description=None, is_public=None): """Update the name and/or description for a volume type. :param volume_type: The ID of the :class:`VolumeType` to update. @@ -143,6 +143,8 @@ class VolumeTypeManager(base.ManagerWithFind): "description": description } } + if is_public is not None: + body["volume_type"]["is_public"] = is_public return self._update("/types/%s" % base.getid(volume_type), body, response_key="volume_type")