"Fossies" - the Fresh Open Source Software Archive

Member "qinling-3.0.0/qinling/api/controllers/root.py" (16 Oct 2019, 2302 Bytes) of package /linux/misc/openstack/qinling-3.0.0.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 "root.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.0.0_vs_3.0.0.

    1 # Copyright 2013 - Mirantis, Inc.
    2 #
    3 #    Licensed under the Apache License, Version 2.0 (the "License");
    4 #    you may not use this file except in compliance with the License.
    5 #    You may obtain a copy of the License at
    6 #
    7 #        http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 #    Unless required by applicable law or agreed to in writing, software
   10 #    distributed under the License is distributed on an "AS IS" BASIS,
   11 #    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   12 #    See the License for the specific language governing permissions and
   13 #    limitations under the License.
   14 
   15 from oslo_log import log as logging
   16 import pecan
   17 from wsme import types as wtypes
   18 import wsmeext.pecan as wsme_pecan
   19 
   20 from qinling.api.controllers.v1 import resources
   21 from qinling.api.controllers.v1 import root as v1_root
   22 
   23 LOG = logging.getLogger(__name__)
   24 
   25 API_STATUS = wtypes.Enum(str, 'SUPPORTED', 'CURRENT', 'DEPRECATED')
   26 
   27 
   28 class APIVersion(resources.Resource):
   29     """An API Version."""
   30 
   31     id = wtypes.text
   32     "The version identifier."
   33 
   34     status = API_STATUS
   35     "The status of the API (SUPPORTED, CURRENT or DEPRECATED)."
   36 
   37     links = wtypes.ArrayType(resources.Link)
   38     "The link to the versioned API."
   39 
   40     @classmethod
   41     def sample(cls):
   42         return cls(
   43             id='v1.0',
   44             status='CURRENT',
   45             links=[
   46                 resources.Link(target_name='v1', rel="self",
   47                                href='http://example.com:7070/v1')
   48             ]
   49         )
   50 
   51 
   52 class APIVersions(resources.Resource):
   53     """API Versions."""
   54     versions = wtypes.ArrayType(APIVersion)
   55 
   56     @classmethod
   57     def sample(cls):
   58         v1 = APIVersion(id='v1.0', status='CURRENT', rel="self",
   59                         href='http://example.com:7070/v1')
   60         return cls(versions=[v1])
   61 
   62 
   63 class RootController(object):
   64     v1 = v1_root.Controller()
   65 
   66     @wsme_pecan.wsexpose(APIVersions)
   67     def index(self):
   68         LOG.info("Fetching API versions.")
   69 
   70         host_url_v1 = '%s/%s' % (pecan.request.application_url, 'v1')
   71         api_v1 = APIVersion(
   72             id='v1.0',
   73             status='CURRENT',
   74             links=[resources.Link(href=host_url_v1, target='v1',
   75                                   rel="self", )]
   76         )
   77 
   78         return APIVersions(versions=[api_v1])