Skip to content

Commit

Permalink
Adding flag around image-create for v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rconradharris committed Aug 5, 2011
1 parent 429b42f commit 9633e98
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions nova/api/openstack/__init__.py
Expand Up @@ -50,6 +50,9 @@
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):
Expand Down
6 changes: 6 additions & 0 deletions nova/api/openstack/images.py
Expand Up @@ -108,6 +108,12 @@ class ControllerV10(Controller):

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):
Expand Down
10 changes: 10 additions & 0 deletions nova/tests/api/openstack/test_images.py
Expand Up @@ -1049,6 +1049,16 @@ def test_create_image_no_server_id(self):
response = req.get_response(fakes.wsgi_app())
self.assertEqual(400, response.status_int)

def test_create_image_snapshots_disabled(self):
self.flags(allow_instance_snapshots=False)
body = dict(image=dict(serverId='123', name='Snapshot 1'))
req = webob.Request.blank('/v1.0/images')
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)

@classmethod
def _make_image_fixtures(cls):
image_id = 123
Expand Down

0 comments on commit 9633e98

Please sign in to comment.