summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorRick Harris <rick.harris@rackspace.com>2011-08-08 01:52:36 +0000
committerTarmac <>2011-08-08 01:52:36 +0000
commitec57e2a27ebfc8eba84d82f5372408e3d85a9272 (patch)
tree57cd78fcb99565961ddcd30e2ed2c61677a24cf8 /nova/api
parentc911c6d737e9794cb6e4a64d530bc98056c005a0 (diff)
parent7a5bb39ef11d630df26f2fcfbf249f0c34e9fa55 (diff)
downloadnova-ec57e2a27ebfc8eba84d82f5372408e3d85a9272.tar.gz
nova-ec57e2a27ebfc8eba84d82f5372408e3d85a9272.tar.xz
nova-ec57e2a27ebfc8eba84d82f5372408e3d85a9272.zip
Adds ability to disable snapshots in the Openstack API.
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/__init__.py3
-rw-r--r--nova/api/openstack/common.py13
-rw-r--r--nova/api/openstack/images.py1
-rw-r--r--nova/api/openstack/servers.py2
4 files changed, 19 insertions, 0 deletions
diff --git a/nova/api/openstack/__init__.py b/nova/api/openstack/__init__.py
index d6a98c2cd..4d49df2ad 100644
--- a/nova/api/openstack/__init__.py
+++ b/nova/api/openstack/__init__.py
@@ -50,6 +50,9 @@ FLAGS = flags.FLAGS
flags.DEFINE_bool('allow_admin_api',
False,
'When True, this API service will accept admin operations.')
+flags.DEFINE_bool('allow_instance_snapshots',
+ True,
+ 'When True, this API service will permit instance snapshot operations.')
class FaultWrapper(base_wsgi.Middleware):
diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py
index 4548c2c75..5226cdf9a 100644
--- a/nova/api/openstack/common.py
+++ b/nova/api/openstack/common.py
@@ -15,6 +15,7 @@
# License for the specific language governing permissions and limitations
# under the License.
+import functools
import re
import urlparse
from xml.dom import minidom
@@ -280,3 +281,15 @@ class MetadataXMLSerializer(wsgi.XMLDictSerializer):
def default(self, *args, **kwargs):
return ''
+
+
+def check_snapshots_enabled(f):
+ @functools.wraps(f)
+ def inner(*args, **kwargs):
+ 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)
+ return f(*args, **kwargs)
+ return inner
diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py
index b9bc83fde..0aabb9e56 100644
--- a/nova/api/openstack/images.py
+++ b/nova/api/openstack/images.py
@@ -106,6 +106,7 @@ class Controller(object):
class ControllerV10(Controller):
"""Version 1.0 specific controller logic."""
+ @common.check_snapshots_enabled
def create(self, req, body):
"""Snapshot a server instance and save the image."""
try:
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py
index 1051ba571..f1a27a98c 100644
--- a/nova/api/openstack/servers.py
+++ b/nova/api/openstack/servers.py
@@ -240,6 +240,7 @@ class Controller(object):
resp.headers['Location'] = image_ref
return resp
+ @common.check_snapshots_enabled
def _action_create_image(self, input_dict, req, id):
return exc.HTTPNotImplemented()
@@ -689,6 +690,7 @@ class ControllerV11(Controller):
return webob.Response(status_int=202)
+ @common.check_snapshots_enabled
def _action_create_image(self, input_dict, req, instance_id):
"""Snapshot a server instance."""
entity = input_dict.get("createImage", {})