Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch provides the ability to 'deactivate' an image by providing two new API calls and a new image status 'deactivated'. Attempting to download a deactivated image will result in a 403 'Forbidden' return code. Also, image locations won't be visible for deactivated images unless the user is admin. All other image operations should remain unaffected. The two new API calls are: - POST /images/{image_id}/actions/deactivate - POST /images/{image_id}/actions/reactivate DocImpact UpgradeImpact Change-Id: I32b7cc7ce8404457a87c8c05041aa2a30152b930 Implements: bp deactivate-image
- Loading branch information
Eddie Sheffield
authored and
Hemanth Makkapati
committed
Mar 13, 2015
1 parent
15fea34
commit b000c85
Showing
21 changed files
with
568 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Copyright 2015 OpenStack Foundation. | ||
# All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
import glance_store | ||
from oslo_log import log as logging | ||
import webob.exc | ||
|
||
from glance.api import policy | ||
from glance.common import exception | ||
from glance.common import utils | ||
from glance.common import wsgi | ||
import glance.db | ||
import glance.gateway | ||
from glance import i18n | ||
import glance.notifier | ||
|
||
|
||
LOG = logging.getLogger(__name__) | ||
_ = i18n._ | ||
_LI = i18n._LI | ||
|
||
|
||
class ImageActionsController(object): | ||
def __init__(self, db_api=None, policy_enforcer=None, notifier=None, | ||
store_api=None): | ||
self.db_api = db_api or glance.db.get_api() | ||
self.policy = policy_enforcer or policy.Enforcer() | ||
self.notifier = notifier or glance.notifier.Notifier() | ||
self.store_api = store_api or glance_store | ||
self.gateway = glance.gateway.Gateway(self.db_api, self.store_api, | ||
self.notifier, self.policy) | ||
|
||
@utils.mutating | ||
def deactivate(self, req, image_id): | ||
image_repo = self.gateway.get_repo(req.context) | ||
try: | ||
image = image_repo.get(image_id) | ||
image.deactivate() | ||
image_repo.save(image) | ||
LOG.info(_LI("Image %s is deactivated") % image_id) | ||
except exception.NotFound as e: | ||
raise webob.exc.HTTPNotFound(explanation=e.msg) | ||
except exception.Forbidden as e: | ||
raise webob.exc.HTTPForbidden(explanation=e.msg) | ||
except exception.InvalidImageStatusTransition as e: | ||
raise webob.exc.HTTPBadRequest(explanation=e.msg) | ||
|
||
@utils.mutating | ||
def reactivate(self, req, image_id): | ||
image_repo = self.gateway.get_repo(req.context) | ||
try: | ||
image = image_repo.get(image_id) | ||
image.reactivate() | ||
image_repo.save(image) | ||
LOG.info(_LI("Image %s is reactivated") % image_id) | ||
except exception.NotFound as e: | ||
raise webob.exc.HTTPNotFound(explanation=e.msg) | ||
except exception.Forbidden as e: | ||
raise webob.exc.HTTPForbidden(explanation=e.msg) | ||
except exception.InvalidImageStatusTransition as e: | ||
raise webob.exc.HTTPBadRequest(explanation=e.msg) | ||
|
||
|
||
class ResponseSerializer(wsgi.JSONResponseSerializer): | ||
|
||
def deactivate(self, response, result): | ||
response.status_int = 204 | ||
|
||
def reactivate(self, response, result): | ||
response.status_int = 204 | ||
|
||
|
||
def create_resource(): | ||
"""Image data resource factory method""" | ||
deserializer = None | ||
serializer = ResponseSerializer() | ||
controller = ImageActionsController() | ||
return wsgi.Resource(controller, deserializer, serializer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.