From c364372477f7b9f6ddc53c9c13d08f8e459ff74e Mon Sep 17 00:00:00 2001 From: HiroyukiEguchi Date: Wed, 2 Apr 2014 09:48:32 +0900 Subject: [PATCH] Add set-bootable command Bootable Status is set to "True" automatically when user create a volume from a image. But user have to set bootable status manually when creating a bootable volume manually. blueprint add-bootable-option this commit is related to https://review.openstack.org/#/c/84057/ Change-Id: Ib4a44334001b7b9e3b896c2e44607c414e75e952 --- cinderclient/tests/v1/fakes.py | 2 ++ cinderclient/tests/v1/test_volumes.py | 5 +++++ cinderclient/tests/v2/fakes.py | 2 ++ cinderclient/tests/v2/test_volumes.py | 5 +++++ cinderclient/v1/shell.py | 13 +++++++++++++ cinderclient/v1/volumes.py | 5 +++++ cinderclient/v2/shell.py | 13 +++++++++++++ cinderclient/v2/volumes.py | 5 +++++ 8 files changed, 50 insertions(+) diff --git a/cinderclient/tests/v1/fakes.py b/cinderclient/tests/v1/fakes.py index d24cf053f..fa039a1ba 100644 --- a/cinderclient/tests/v1/fakes.py +++ b/cinderclient/tests/v1/fakes.py @@ -354,6 +354,8 @@ class FakeHTTPClient(base_client.HTTPClient): assert 'force_host_copy' in body[action] elif action == 'os-update_readonly_flag': assert list(body[action]) == ['readonly'] + elif action == 'os-set_bootable': + assert list(body[action]) == ['bootable'] 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 571fa79c4..1b59f7f03 100644 --- a/cinderclient/tests/v1/test_volumes.py +++ b/cinderclient/tests/v1/test_volumes.py @@ -106,3 +106,8 @@ class VolumesTest(utils.TestCase): v = cs.volumes.get('1234') cs.volumes.update_readonly_flag(v, True) cs.assert_called('POST', '/volumes/1234/action') + + def test_set_bootable(self): + v = cs.volumes.get('1234') + cs.volumes.set_bootable(v, True) + cs.assert_called('POST', '/volumes/1234/action') diff --git a/cinderclient/tests/v2/fakes.py b/cinderclient/tests/v2/fakes.py index eebc58610..968afc9ae 100644 --- a/cinderclient/tests/v2/fakes.py +++ b/cinderclient/tests/v2/fakes.py @@ -365,6 +365,8 @@ class FakeHTTPClient(base_client.HTTPClient): assert list(body[action]) == ['readonly'] elif action == 'os-retype': assert 'new_type' in body[action] + elif action == 'os-set_bootable': + assert list(body[action]) == ['bootable'] 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 5e128123f..21659711c 100644 --- a/cinderclient/tests/v2/test_volumes.py +++ b/cinderclient/tests/v2/test_volumes.py @@ -116,3 +116,8 @@ class VolumesTest(utils.TestCase): cs.assert_called('POST', '/volumes/1234/action', {'os-retype': {'new_type': 'foo', 'migration_policy': 'on-demand'}}) + + def test_set_bootable(self): + v = cs.volumes.get('1234') + cs.volumes.set_bootable(v, True) + cs.assert_called('POST', '/volumes/1234/action') diff --git a/cinderclient/v1/shell.py b/cinderclient/v1/shell.py index 6a11c2a9f..048e4f269 100644 --- a/cinderclient/v1/shell.py +++ b/cinderclient/v1/shell.py @@ -1399,3 +1399,16 @@ def do_readonly_mode_update(cs, args): volume = utils.find_volume(cs, args.volume) cs.volumes.update_readonly_flag(volume, strutils.bool_from_string(args.read_only)) + + +@utils.arg('volume', metavar='', help='ID of the volume to update.') +@utils.arg('bootable', + metavar='', + choices=['True', 'true', 'False', 'false'], + help='Flag to indicate whether volume is bootable.') +@utils.service_type('volume') +def do_set_bootable(cs, args): + """Update bootable status of a volume.""" + volume = utils.find_volume(cs, args.volume) + cs.volumes.set_bootable(volume, + strutils.bool_from_string(args.bootable)) diff --git a/cinderclient/v1/volumes.py b/cinderclient/v1/volumes.py index 96ad94de5..b0ad6128c 100644 --- a/cinderclient/v1/volumes.py +++ b/cinderclient/v1/volumes.py @@ -425,3 +425,8 @@ class VolumeManager(base.ManagerWithFind): return self._action('os-update_readonly_flag', base.getid(volume), {'readonly': flag}) + + def set_bootable(self, volume, flag): + return self._action('os-set_bootable', + base.getid(volume), + {'bootable': flag}) diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py index e4c3da322..e81327572 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -1516,3 +1516,16 @@ def do_readonly_mode_update(cs, args): volume = utils.find_volume(cs, args.volume) cs.volumes.update_readonly_flag(volume, strutils.bool_from_string(args.read_only)) + + +@utils.arg('volume', metavar='', help='ID of the volume to update.') +@utils.arg('bootable', + metavar='', + choices=['True', 'true', 'False', 'false'], + help='Flag to indicate whether volume is bootable.') +@utils.service_type('volumev2') +def do_set_bootable(cs, args): + """Update bootable status of a volume.""" + volume = utils.find_volume(cs, args.volume) + cs.volumes.set_bootable(volume, + strutils.bool_from_string(args.bootable)) diff --git a/cinderclient/v2/volumes.py b/cinderclient/v2/volumes.py index 7f77bb96e..960001869 100644 --- a/cinderclient/v2/volumes.py +++ b/cinderclient/v2/volumes.py @@ -419,3 +419,8 @@ class VolumeManager(base.ManagerWithFind): volume, {'new_type': volume_type, 'migration_policy': policy}) + + def set_bootable(self, volume, flag): + return self._action('os-set_bootable', + base.getid(volume), + {'bootable': flag})