Merge "Port services to core API"

This commit is contained in:
Jenkins 2015-11-11 09:00:38 +00:00 committed by Gerrit Code Review
commit f15e0bf123
6 changed files with 71 additions and 36 deletions

View File

@ -7,6 +7,9 @@
"availability_zone:index": "rule:default",
"service:index": "rule:admin_api",
"service:update": "rule:admin_api",
"share:create": "",
"share:delete": "rule:default",
"share:get": "rule:default",
@ -54,7 +57,6 @@
"share_extension:cgsnapshot_admin_actions:force_delete": "rule:admin_api",
"share_extension:cgsnapshot_admin_actions:reset_status": "rule:admin_api",
"share_extension:services": "rule:admin_api",
"share_extension:availability_zones": "",
"share_extension:types_manage": "rule:admin_api",

View File

@ -29,6 +29,7 @@ from manila.api.v1 import consistency_groups
from manila.api.v1 import limits
from manila.api.v1 import scheduler_stats
from manila.api.v1 import security_service
from manila.api.v1 import services
from manila.api.v1 import share_instances
from manila.api.v1 import share_manage
from manila.api.v1 import share_metadata
@ -67,6 +68,13 @@ class APIRouter(manila.api.openstack.APIRouter):
"os-availability-zone",
controller=self.resources["availability_zones"])
self.resources["services"] = services.create_resource()
mapper.resource("service",
# TODO(vponomaryov): rename 'os-services' to
# 'services' when API urls rename happens.
"os-services",
controller=self.resources["services"])
self.resources["share_manage"] = share_manage.create_resource()
mapper.resource("share_manage",
# TODO(vponomaryov): remove it when it is ported

View File

@ -1,4 +1,5 @@
# Copyright 2012 IBM Corp.
# Copyright (c) 2015 Mirantis inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@ -16,20 +17,25 @@
from oslo_log import log
import webob.exc
from manila.api import extensions
from manila.api.openstack import wsgi
from manila.api.views import services as services_views
from manila import db
from manila import exception
from manila import utils
LOG = log.getLogger(__name__)
authorize = extensions.extension_authorizer('share', 'services')
class ServiceController(object):
class ServiceController(wsgi.Controller):
"""The Services API controller for the OpenStack API."""
resource_name = "service"
_view_builder_class = services_views.ViewBuilder
def index(self, req):
"""Return a list of all running services."""
context = req.environ['manila.context']
authorize(context)
self.authorize(context, 'index')
all_services = db.service_get_all(context)
services = []
@ -60,48 +66,32 @@ class ServiceController(object):
if len(services) == 0:
break
return {'services': services}
return self._view_builder.detail_list(services)
def update(self, req, id, body):
"""Enable/Disable scheduling for a service."""
context = req.environ['manila.context']
authorize(context)
self.authorize(context, 'update')
if id == "enable":
disabled = False
data = {'disabled': False}
elif id == "disable":
disabled = True
data = {'disabled': True}
else:
raise webob.exc.HTTPNotFound("Unknown action")
raise webob.exc.HTTPNotFound("Unknown action '%s'" % id)
try:
host = body['host']
binary = body['binary']
data['host'] = body['host']
data['binary'] = body['binary']
except (TypeError, KeyError):
raise webob.exc.HTTPBadRequest()
try:
svc = db.service_get_by_args(context, host, binary)
if not svc:
raise webob.exc.HTTPNotFound('Unknown service')
svc = db.service_get_by_args(context, data['host'], data['binary'])
db.service_update(
context, svc['id'], {'disabled': data['disabled']})
db.service_update(context, svc['id'], {'disabled': disabled})
except exception.ServiceNotFound:
raise webob.exc.HTTPNotFound("service not found")
return {'host': host, 'binary': binary, 'disabled': disabled}
return self._view_builder.summary(data)
class Services(extensions.ExtensionDescriptor):
"""Services support."""
name = "Services"
alias = "os-services"
updated = "2012-10-28T00:00:00-00:00"
def get_resources(self):
resources = []
resource = extensions.ResourceExtension('os-services',
ServiceController())
resources.append(resource)
return resources
def create_resource():
return wsgi.Resource(ServiceController())

View File

@ -0,0 +1,32 @@
# Copyright (c) 2015 Mirantis inc.
# 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.
from manila.api import common
class ViewBuilder(common.ViewBuilder):
_collection_name = "services"
def summary(self, service):
"""Summary view of a single service."""
keys = 'host', 'binary', 'disabled'
return {key: service.get(key) for key in keys}
def detail_list(self, services):
"""Detailed view of a list of services."""
keys = 'id', 'binary', 'host', 'zone', 'status', 'state', 'updated_at'
views = [{key: s.get(key) for key in keys} for s in services]
return {self._collection_name: views}

View File

@ -19,7 +19,7 @@ import datetime
from oslo_utils import timeutils
from manila.api.contrib import services
from manila.api.v1 import services
from manila import context
from manila import db
from manila import exception

View File

@ -6,6 +6,9 @@
"availability_zone:index": "rule:default",
"service:index": "rule:admin_api",
"service:update": "rule:admin_api",
"share:create": "",
"share:list_by_share_server_id": "rule:admin_api",
"share:get": "",