diff options
| author | Rick Harris <rick.harris@rackspace.com> | 2011-08-05 22:56:08 +0000 |
|---|---|---|
| committer | Rick Harris <rick.harris@rackspace.com> | 2011-08-05 22:56:08 +0000 |
| commit | bdabdd50845279cbca11f510dd5da6a5aa110528 (patch) | |
| tree | 618cd181a0bef885b4738c14f4edc41b3a0df7e4 /nova/api | |
| parent | c49e99a7fc590c2dde6125843d904895ca8861a3 (diff) | |
| download | nova-bdabdd50845279cbca11f510dd5da6a5aa110528.tar.gz nova-bdabdd50845279cbca11f510dd5da6a5aa110528.tar.xz nova-bdabdd50845279cbca11f510dd5da6a5aa110528.zip | |
Using decorator for snapshots enabled check
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/common.py | 14 | ||||
| -rw-r--r-- | nova/api/openstack/images.py | 7 | ||||
| -rw-r--r-- | nova/api/openstack/servers.py | 7 |
3 files changed, 16 insertions, 12 deletions
diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 4548c2c75..ec9368140 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,16 @@ 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 7b738e1f3..0aabb9e56 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -106,14 +106,9 @@ 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.""" - 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) - try: image = body["image"] except (KeyError, TypeError): diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index 391c7d644..4d6518598 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -689,14 +689,9 @@ 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.""" - 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: |
