summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRick Harris <rick.harris@rackspace.com>2011-08-05 22:29:28 +0000
committerRick Harris <rick.harris@rackspace.com>2011-08-05 22:29:28 +0000
commitc49e99a7fc590c2dde6125843d904895ca8861a3 (patch)
treee1af55d8622f5ef8ef18278a06c95fb98223580d
parent9633e9877c7836c18c30b51c8494abfb025e64ca (diff)
Disable flag for V1 Openstack API
-rw-r--r--nova/api/openstack/servers.py6
-rw-r--r--nova/tests/api/openstack/test_server_actions.py18
2 files changed, 24 insertions, 0 deletions
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py
index 1051ba571..391c7d644 100644
--- a/nova/api/openstack/servers.py
+++ b/nova/api/openstack/servers.py
@@ -691,6 +691,12 @@ class ControllerV11(Controller):
def _action_create_image(self, input_dict, req, instance_id):
"""Snapshot a server instance."""
+ if not FLAGS.allow_instance_snapshots:
+ LOG.warn(_('Rejecting snapshot request, snapshots currently'
+ ' disabled'))
+ msg = _("Instance Snapshots are not permitted at this time.")
+ raise webob.exc.HTTPBadRequest(explanation=msg)
+
entity = input_dict.get("createImage", {})
try:
diff --git a/nova/tests/api/openstack/test_server_actions.py b/nova/tests/api/openstack/test_server_actions.py
index 7e24d24fd..bf18bc1b0 100644
--- a/nova/tests/api/openstack/test_server_actions.py
+++ b/nova/tests/api/openstack/test_server_actions.py
@@ -458,6 +458,7 @@ class ServerActionsTestV11(test.TestCase):
self.service.delete_all()
self.sent_to_glance = {}
fakes.stub_out_glance_add_image(self.stubs, self.sent_to_glance)
+ self.flags(allow_instance_snapshots=True)
def tearDown(self):
self.stubs.UnsetAll()
@@ -775,6 +776,23 @@ class ServerActionsTestV11(test.TestCase):
location = response.headers['Location']
self.assertEqual('http://localhost/v1.1/images/123', location)
+ def test_create_image_snapshots_disabled(self):
+ """Don't permit a snapshot if the allow_instance_snapshots flag is
+ False
+ """
+ self.flags(allow_instance_snapshots=False)
+ body = {
+ 'createImage': {
+ 'name': 'Snapshot 1',
+ },
+ }
+ req = webob.Request.blank('/v1.1/servers/1/action')
+ req.method = 'POST'
+ req.body = json.dumps(body)
+ req.headers["content-type"] = "application/json"
+ response = req.get_response(fakes.wsgi_app())
+ self.assertEqual(400, response.status_int)
+
def test_create_image_with_metadata(self):
body = {
'createImage': {