"Fossies" - the Fresh Open Source Software Archive

Member "cinder-14.0.2/cinder/api/views/qos_specs.py" (4 Oct 2019, 2458 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 "qos_specs.py" see the Fossies "Dox" file reference documentation.

    1 # Copyright (C) 2013 eBay 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 from cinder.api import common
   17 
   18 
   19 class ViewBuilder(common.ViewBuilder):
   20     """Model QoS specs API responses as a python dictionary."""
   21 
   22     _collection_name = "qos-specs"
   23 
   24     def __init__(self):
   25         """Initialize view builder."""
   26         super(ViewBuilder, self).__init__()
   27 
   28     def summary_list(self, request, qos_specs, qos_count=None):
   29         """Show a list of qos_specs without many details."""
   30         return self._list_view(self.detail, request, qos_specs, qos_count)
   31 
   32     def summary(self, request, qos_spec):
   33         """Generic, non-detailed view of a qos_specs."""
   34         return self.detail(request, qos_spec)
   35 
   36     def detail(self, request, qos_spec):
   37         """Detailed view of a single qos_spec."""
   38         # TODO(zhiteng) Add associations to detailed view
   39         return {
   40             'qos_specs': {
   41                 'id': qos_spec.id,
   42                 'name': qos_spec.name,
   43                 'consumer': qos_spec.consumer,
   44                 'specs': qos_spec.specs,
   45             },
   46             'links': self._get_links(request,
   47                                      qos_spec.id),
   48         }
   49 
   50     def associations(self, request, associates):
   51         """View of qos specs associations."""
   52         return {
   53             'qos_associations': associates
   54         }
   55 
   56     def _list_view(self, func, request, qos_specs, qos_count=None):
   57         """Provide a view for a list of qos_specs."""
   58         specs_list = [func(request, specs)['qos_specs'] for specs in qos_specs]
   59         specs_links = self._get_collection_links(request, qos_specs,
   60                                                  self._collection_name,
   61                                                  qos_count)
   62         specs_dict = dict(qos_specs=specs_list)
   63         if specs_links:
   64             specs_dict['qos_specs_links'] = specs_links
   65 
   66         return specs_dict