"Fossies" - the Fresh Open Source Software Archive

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

    1 #  Copyright (c) 2016 Stratoscale, Ltd.
    2 #
    3 #  Licensed under the Apache License, Version 2.0 (the "License"); you may
    4 #  not use this file except in compliance with the License. You may obtain
    5 #  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, WITHOUT
   11 #  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   12 #  License for the specific language governing permissions and limitations
   13 #  under the License.
   14 
   15 import oslo_messaging as messaging
   16 
   17 from cinder.api import common
   18 from cinder.api import microversions as mv
   19 from cinder import exception
   20 from cinder.i18n import _
   21 
   22 
   23 def get_manageable_resources(req, is_detail, function_get_manageable,
   24                              view_builder):
   25     context = req.environ['cinder.context']
   26     params = req.params.copy()
   27     cluster_name, host = common.get_cluster_host(
   28         req, params, mv.MANAGE_EXISTING_CLUSTER)
   29     marker, limit, offset = common.get_pagination_params(params)
   30     sort_keys, sort_dirs = common.get_sort_params(params,
   31                                                   default_key='reference')
   32 
   33     # These parameters are generally validated at the DB layer, but in this
   34     # case sorting is not done by the DB
   35     valid_sort_keys = ('reference', 'size')
   36     invalid_keys = [key for key in sort_keys if key not in valid_sort_keys]
   37     if invalid_keys:
   38         msg = _("Invalid sort keys passed: %s") % ', '.join(invalid_keys)
   39         raise exception.InvalidParameterValue(err=msg)
   40     valid_sort_dirs = ('asc', 'desc')
   41     invalid_dirs = [d for d in sort_dirs if d not in valid_sort_dirs]
   42     if invalid_dirs:
   43         msg = _("Invalid sort dirs passed: %s") % ', '.join(invalid_dirs)
   44         raise exception.InvalidParameterValue(err=msg)
   45 
   46     try:
   47         resources = function_get_manageable(context, host, cluster_name,
   48                                             marker=marker, limit=limit,
   49                                             offset=offset, sort_keys=sort_keys,
   50                                             sort_dirs=sort_dirs)
   51     except messaging.RemoteError as err:
   52         if err.exc_type == "InvalidInput":
   53             raise exception.InvalidInput(err.value)
   54         raise
   55 
   56     resource_count = len(resources)
   57 
   58     if is_detail:
   59         resources = view_builder.detail_list(req, resources, resource_count)
   60     else:
   61         resources = view_builder.summary_list(req, resources, resource_count)
   62     return resources