"Fossies" - the Fresh Open Source Software Archive

Member "cinder-14.0.2/cinder/api/contrib/capabilities.py" (4 Oct 2019, 2656 Bytes) of package /linux/misc/openstack/cinder-14.0.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "capabilities.py" see the Fossies "Dox" file reference documentation.

    1 # Copyright (c) 2015 Hitachi Data Systems, Inc.
    2 # All Rights Reserved.
    3 #
    4 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    5 #    not use this file except in compliance with the License. You may obtain
    6 #    a copy of the License at
    7 #
    8 #         http://www.apache.org/licenses/LICENSE-2.0
    9 #
   10 #    Unless required by applicable law or agreed to in writing, software
   11 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   12 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   13 #    License for the specific language governing permissions and limitations
   14 #    under the License.
   15 
   16 import oslo_messaging
   17 
   18 from cinder.api import extensions
   19 from cinder.api.openstack import wsgi
   20 from cinder.api.views import capabilities as capabilities_view
   21 from cinder.common import constants
   22 from cinder import exception
   23 from cinder.i18n import _
   24 from cinder import objects
   25 from cinder.policies import capabilities as policy
   26 from cinder.volume import rpcapi
   27 
   28 
   29 class CapabilitiesController(wsgi.Controller):
   30     """The Capabilities controller for the OpenStack API."""
   31 
   32     _view_builder_class = capabilities_view.ViewBuilder
   33 
   34     def __init__(self):
   35         # FIXME(jdg):  Is it kosher that this just
   36         # skips the volume.api and goes straight to RPC
   37         # from here?
   38         self.volume_api = rpcapi.VolumeAPI()
   39         super(CapabilitiesController, self).__init__()
   40 
   41     def show(self, req, id):
   42         """Return capabilities list of given backend."""
   43         context = req.environ['cinder.context']
   44         context.authorize(policy.CAPABILITIES_POLICY)
   45         filters = {'host_or_cluster': id, 'binary': constants.VOLUME_BINARY}
   46         services = objects.ServiceList.get_all(context, filters)
   47         if not services:
   48             msg = (_("Can't find service: %s") % id)
   49             raise exception.NotFound(msg)
   50         topic = services[0].service_topic_queue
   51         try:
   52             capabilities = self.volume_api.get_capabilities(context, topic,
   53                                                             False)
   54         except oslo_messaging.MessagingTimeout:
   55             raise exception.RPCTimeout(service=topic)
   56         return self._view_builder.summary(req, capabilities, topic)
   57 
   58 
   59 class Capabilities(extensions.ExtensionDescriptor):
   60     """Capabilities support."""
   61 
   62     name = "Capabilities"
   63     alias = "capabilities"
   64     updated = "2015-08-31T00:00:00+00:00"
   65 
   66     def get_resources(self):
   67         resources = []
   68         res = extensions.ResourceExtension(
   69             Capabilities.alias,
   70             CapabilitiesController())
   71 
   72         resources.append(res)
   73         return resources