From 1a253971c241bcea339cb6281e2958184a5eb269 Mon Sep 17 00:00:00 2001 From: Yulia Portnova Date: Tue, 10 Sep 2013 13:25:30 +0300 Subject: [PATCH] Removed v2 api. Moved shares and snapshots from contrib to v1 --- manila/api/contrib/share_actions.py | 7 ++ manila/api/v1/router.py | 26 ++++++ manila/api/v1/share_actions.py | 84 +++++++++++++++++++ manila/api/{contrib => v1}/share_snapshots.py | 30 ++++--- manila/api/{contrib => v1}/shares.py | 27 +++--- 5 files changed, 149 insertions(+), 25 deletions(-) create mode 100644 manila/api/v1/share_actions.py rename manila/api/{contrib => v1}/share_snapshots.py (90%) rename manila/api/{contrib => v1}/shares.py (92%) diff --git a/manila/api/contrib/share_actions.py b/manila/api/contrib/share_actions.py index 221d7f0798..9786ab33a8 100644 --- a/manila/api/contrib/share_actions.py +++ b/manila/api/contrib/share_actions.py @@ -20,6 +20,9 @@ from manila import exception from manila import share +authorize = extensions.extension_authorizer('share', 'services') + + class ShareActionsController(wsgi.Controller): def __init__(self, *args, **kwargs): super(ShareActionsController, self).__init__(*args, **kwargs) @@ -65,6 +68,10 @@ class ShareActionsController(wsgi.Controller): return {'access_list': access_list} +# def create_resource(): +# return wsgi.Resource(ShareActionsController()) + + class Share_actions(extensions.ExtensionDescriptor): """Enable share actions.""" diff --git a/manila/api/v1/router.py b/manila/api/v1/router.py index fd59287bd5..debcea9923 100644 --- a/manila/api/v1/router.py +++ b/manila/api/v1/router.py @@ -25,6 +25,11 @@ from manila.api import extensions import manila.api.openstack from manila.api.v1 import limits from manila.api import versions + +from manila.api.v1 import shares +from manila.api.v1 import share_actions +from manila.api.v1 import share_snapshots + from manila.openstack.common import log as logging @@ -45,3 +50,24 @@ class APIRouter(manila.api.openstack.APIRouter): action='show') mapper.redirect("", "/") + + self.resources['shares'] = shares.create_resource() + mapper.resource("share", "shares", + controller=self.resources['shares'], + collection={'detail': 'GET'}, + member={'action': 'POST'}) + + self.resources['share-snapshots'] = share_snapshots.create_resource() + mapper.resource("share-snapshot", "share-snapshots", + controller=self.resources['share-snapshots'], + collection={'detail': 'GET'}, + member={'action': 'POST'}) + # + # self.resources['shares'] = share_actions.create_resource() + # mapper.resource("share", "shares", + # controller=self.resources['shares']) + + self.resources['limits'] = limits.create_resource() + mapper.resource("limit", "limits", + controller=self.resources['limits']) + diff --git a/manila/api/v1/share_actions.py b/manila/api/v1/share_actions.py new file mode 100644 index 0000000000..1e04271fd7 --- /dev/null +++ b/manila/api/v1/share_actions.py @@ -0,0 +1,84 @@ +# Copyright 2013 NetApp. +# +# 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 webob + +from manila.api import extensions +from manila.api.openstack import wsgi +from manila import exception +from manila import share + + +class ShareActionsController(wsgi.Controller): + def __init__(self, *args, **kwargs): + super(ShareActionsController, self).__init__(*args, **kwargs) + self.share_api = share.API() + + @wsgi.action('os-allow_access') + def _allow_access(self, req, id, body): + """Add share access rule.""" + context = req.environ['manila.context'] + + share = self.share_api.get(context, id) + + access_type = body['os-allow_access']['access_type'] + access_to = body['os-allow_access']['access_to'] + + self.share_api.allow_access(context, share, access_type, access_to) + return webob.Response(status_int=202) + + @wsgi.action('os-deny_access') + def _deny_access(self, req, id, body): + """Remove access rule.""" + context = req.environ['manila.context'] + + access_id = body['os-deny_access']['access_id'] + + try: + access = self.share_api.access_get(context, access_id) + if access.share_id != id: + raise exception.NotFound() + share = self.share_api.get(context, id) + except exception.NotFound, error: + raise webob.exc.HTTPNotFound(explanation=unicode(error)) + self.share_api.deny_access(context, share, access) + return webob.Response(status_int=202) + + @wsgi.action('os-access_list') + def _access_list(self, req, id, body): + """list access rules.""" + context = req.environ['manila.context'] + + share = self.share_api.get(context, id) + access_list = self.share_api.access_get_all(context, share) + return {'access_list': access_list} + + +def create_resource(): + return wsgi.Resource(ShareActionsController()) +# +# +# class Share_actions(extensions.ExtensionDescriptor): +# """Enable share actions.""" +# +# name = 'ShareActions' +# alias = 'share-actions' +# namespace = '' +# updated = '2012-08-14T00:00:00+00:00' +# +# def get_controller_extensions(self): +# controller = ShareActionsController() +# extension = extensions.ControllerExtension(self, 'shares', +# controller) +# return [extension] diff --git a/manila/api/contrib/share_snapshots.py b/manila/api/v1/share_snapshots.py similarity index 90% rename from manila/api/contrib/share_snapshots.py rename to manila/api/v1/share_snapshots.py index cc1bed968b..a879fbf75a 100644 --- a/manila/api/contrib/share_snapshots.py +++ b/manila/api/v1/share_snapshots.py @@ -19,7 +19,7 @@ import webob from webob import exc from manila.api import common -from manila.api.contrib import shares +from manila.api.v1 import shares from manila.api import extensions from manila.api.openstack import wsgi from manila.api.views import share_snapshots as snapshot_views @@ -166,16 +166,20 @@ class ShareSnapshotsController(wsgi.Controller): return self._view_builder.summary(req, dict(new_snapshot.iteritems())) -class Share_snapshots(extensions.ExtensionDescriptor): - """Enable share snapshtos API.""" - name = 'ShareSnapshots' - alias = 'share-snapshots' - namespace = '' - updated = '2013-03-01T00:00:00+00:00' +def create_resource(): + return wsgi.Resource(ShareSnapshotsController()) - def get_resources(self): - controller = ShareSnapshotsController() - resource = extensions.ResourceExtension( - 'share-snapshots', controller, - collection_actions={'detail': 'GET'}) - return [resource] +# +# class Share_snapshots(extensions.ExtensionDescriptor): +# """Enable share snapshtos API.""" +# name = 'ShareSnapshots' +# alias = 'share-snapshots' +# namespace = '' +# updated = '2013-03-01T00:00:00+00:00' +# +# def get_resources(self): +# controller = ShareSnapshotsController() +# resource = extensions.ResourceExtension( +# 'share-snapshots', controller, +# collection_actions={'detail': 'GET'}) +# return [resource] diff --git a/manila/api/contrib/shares.py b/manila/api/v1/shares.py similarity index 92% rename from manila/api/contrib/shares.py rename to manila/api/v1/shares.py index f8ba9b6550..d0a5a3d07d 100644 --- a/manila/api/contrib/shares.py +++ b/manila/api/v1/shares.py @@ -200,16 +200,19 @@ class ShareController(wsgi.Controller): return self._view_builder.summary(req, dict(new_share.iteritems())) -class Shares(extensions.ExtensionDescriptor): - """Enable share API.""" - name = 'Shares' - alias = 'shares' - namespace = '' - updated = '2013-01-29T00:00:00+00:00' +def create_resource(): + return wsgi.Resource(ShareController()) - def get_resources(self): - controller = ShareController() - resource = extensions.ResourceExtension( - 'shares', controller, collection_actions={'detail': 'GET'}, - member_actions={'action': 'POST'}) - return [resource] +# class Shares(extensions.ExtensionDescriptor): +# """Enable share API.""" +# name = 'Shares' +# alias = 'shares' +# namespace = '' +# updated = '2013-01-29T00:00:00+00:00' +# +# def get_resources(self): +# controller = ShareController() +# resource = extensions.ResourceExtension( +# 'shares', controller, collection_actions={'detail': 'GET'}, +# member_actions={'action': 'POST'}) +# return [resource]