Merge "Add set-bootable command"
This commit is contained in:
commit
6e82a6dccb
@ -332,6 +332,38 @@ class VolumeActionsController(wsgi.Controller):
|
|||||||
self.volume_api.retype(context, volume, new_type, policy)
|
self.volume_api.retype(context, volume, new_type, policy)
|
||||||
return webob.Response(status_int=202)
|
return webob.Response(status_int=202)
|
||||||
|
|
||||||
|
@wsgi.action('os-set_bootable')
|
||||||
|
def _set_bootable(self, req, id, body):
|
||||||
|
"""Update bootable status of a volume."""
|
||||||
|
context = req.environ['cinder.context']
|
||||||
|
try:
|
||||||
|
volume = self.volume_api.get(context, id)
|
||||||
|
except exception.VolumeNotFound as error:
|
||||||
|
raise webob.exc.HTTPNotFound(explanation=error.msg)
|
||||||
|
|
||||||
|
try:
|
||||||
|
bootable = body['os-set_bootable']['bootable']
|
||||||
|
except KeyError:
|
||||||
|
msg = _("Must specify bootable in request.")
|
||||||
|
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||||
|
|
||||||
|
if isinstance(bootable, basestring):
|
||||||
|
try:
|
||||||
|
bootable = strutils.bool_from_string(bootable,
|
||||||
|
strict=True)
|
||||||
|
except ValueError:
|
||||||
|
msg = _("Bad value for 'bootable'")
|
||||||
|
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||||
|
|
||||||
|
elif not isinstance(bootable, bool):
|
||||||
|
msg = _("'bootable' not string or bool")
|
||||||
|
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||||
|
|
||||||
|
update_dict = {'bootable': bootable}
|
||||||
|
|
||||||
|
self.volume_api.update(context, volume, update_dict)
|
||||||
|
return webob.Response(status_int=200)
|
||||||
|
|
||||||
|
|
||||||
class Volume_actions(extensions.ExtensionDescriptor):
|
class Volume_actions(extensions.ExtensionDescriptor):
|
||||||
"""Enable volume actions
|
"""Enable volume actions
|
||||||
|
@ -287,6 +287,29 @@ class VolumeActionsTest(test.TestCase):
|
|||||||
make_update_readonly_flag_test(self, 11, 400)
|
make_update_readonly_flag_test(self, 11, 400)
|
||||||
make_update_readonly_flag_test(self, None, 400)
|
make_update_readonly_flag_test(self, None, 400)
|
||||||
|
|
||||||
|
def test_set_bootable(self):
|
||||||
|
|
||||||
|
def make_set_bootable_test(self, bootable, return_code):
|
||||||
|
body = {"os-set_bootable": {"bootable": bootable}}
|
||||||
|
if bootable is None:
|
||||||
|
body = {"os-set_bootable": {}}
|
||||||
|
req = webob.Request.blank('/v2/fake/volumes/1/action')
|
||||||
|
req.method = "POST"
|
||||||
|
req.body = jsonutils.dumps(body)
|
||||||
|
req.headers["content-type"] = "application/json"
|
||||||
|
res = req.get_response(fakes.wsgi_app())
|
||||||
|
self.assertEqual(res.status_int, return_code)
|
||||||
|
|
||||||
|
make_set_bootable_test(self, True, 200)
|
||||||
|
make_set_bootable_test(self, False, 200)
|
||||||
|
make_set_bootable_test(self, '1', 200)
|
||||||
|
make_set_bootable_test(self, '0', 200)
|
||||||
|
make_set_bootable_test(self, 'true', 200)
|
||||||
|
make_set_bootable_test(self, 'false', 200)
|
||||||
|
make_set_bootable_test(self, 'tt', 400)
|
||||||
|
make_set_bootable_test(self, 11, 400)
|
||||||
|
make_set_bootable_test(self, None, 400)
|
||||||
|
|
||||||
|
|
||||||
class VolumeRetypeActionsTest(VolumeActionsTest):
|
class VolumeRetypeActionsTest(VolumeActionsTest):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user