"Fossies" - the Fresh Open Source Software Archive

Member "manila-8.1.3/manila/message/message_field.py" (20 Jul 2020, 5607 Bytes) of package /linux/misc/openstack/manila-8.1.3.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 "message_field.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 8.1.2_vs_8.1.3.

    1 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    2 #    not use this file except in compliance with the License. You may obtain
    3 #    a copy of the License at
    4 #
    5 #         http://www.apache.org/licenses/LICENSE-2.0
    6 #
    7 #    Unless required by applicable law or agreed to in writing, software
    8 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    9 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   10 #    License for the specific language governing permissions and limitations
   11 #    under the License.
   12 
   13 from manila import exception
   14 from manila.i18n import _
   15 
   16 
   17 class Resource(object):
   18 
   19     SHARE = 'SHARE'
   20     SHARE_GROUP = 'SHARE_GROUP'
   21     SHARE_REPLICA = 'SHARE_REPLICA'
   22     SHARE_SNAPSHOT = 'SHARE_SNAPSHOT'
   23 
   24 
   25 class Action(object):
   26 
   27     ALLOCATE_HOST = ('001', _('allocate host'))
   28     CREATE = ('002', _('create'))
   29     DELETE_ACCESS_RULES = ('003', _('delete access rules'))
   30     PROMOTE = ('004', _('promote'))
   31     UPDATE = ('005', _('update'))
   32     REVERT_TO_SNAPSHOT = ('006', _('revert to snapshot'))
   33     DELETE = ('007', _('delete'))
   34     EXTEND = ('008', _('extend'))
   35     ALL = (ALLOCATE_HOST,
   36            CREATE,
   37            DELETE_ACCESS_RULES,
   38            PROMOTE,
   39            UPDATE,
   40            REVERT_TO_SNAPSHOT,
   41            DELETE,
   42            EXTEND)
   43 
   44 
   45 class Detail(object):
   46 
   47     UNKNOWN_ERROR = ('001', _('An unknown error occurred.'))
   48     NO_VALID_HOST = (
   49         '002', _("No storage could be allocated for this share request. "
   50                  "Trying again with a different size or share type may "
   51                  "succeed."))
   52     UNEXPECTED_NETWORK = (
   53         '003', _("Driver does not expect share-network to be provided with "
   54                  "current configuration."))
   55     NO_SHARE_SERVER = (
   56         '004', _("Could not find an existing share server or allocate one on "
   57                  "the share network provided. You may use a different share "
   58                  "network, or verify the network details in the share network "
   59                  "and retry your request. If this doesn't work, contact your "
   60                  "administrator to troubleshoot issues with your network."))
   61     NO_ACTIVE_AVAILABLE_REPLICA = (
   62         '005', _("An 'active' replica must exist in 'available' state to "
   63                  "create a new replica for share."))
   64     NO_ACTIVE_REPLICA = (
   65         '006', _("Share has no replica with 'replica_state' set to 'active'."))
   66 
   67     FILTER_MSG = _("No storage could be allocated for this share request, "
   68                    "%s filter didn't succeed.")
   69     FILTER_AVAILABILITY = ('007', FILTER_MSG % 'AvailabilityZone')
   70     FILTER_CAPABILITIES = ('008', FILTER_MSG % 'Capabilities')
   71     FILTER_CAPACITY = ('009', FILTER_MSG % 'Capacity')
   72     FILTER_DRIVER = ('010', FILTER_MSG % 'Driver')
   73     FILTER_IGNORE = ('011', FILTER_MSG % 'IgnoreAttemptedHosts')
   74     FILTER_JSON = ('012', FILTER_MSG % 'Json')
   75     FILTER_RETRY = ('013', FILTER_MSG % 'Retry')
   76     FILTER_REPLICATION = ('014', FILTER_MSG % 'ShareReplication')
   77     DRIVER_FAILED_EXTEND = (
   78         '015',
   79         _("Share Driver failed to extend share, The share status has been "
   80           "set to extending_error. This action cannot be re-attempted until "
   81           "the status has been rectified. Contact your administrator to "
   82           "determine the cause of this failure."))
   83 
   84     ALL = (UNKNOWN_ERROR,
   85            NO_VALID_HOST,
   86            UNEXPECTED_NETWORK,
   87            NO_SHARE_SERVER,
   88            NO_ACTIVE_AVAILABLE_REPLICA,
   89            NO_ACTIVE_REPLICA,
   90            FILTER_AVAILABILITY,
   91            FILTER_CAPABILITIES,
   92            FILTER_CAPACITY,
   93            FILTER_DRIVER,
   94            FILTER_IGNORE,
   95            FILTER_JSON,
   96            FILTER_RETRY,
   97            FILTER_REPLICATION,
   98            DRIVER_FAILED_EXTEND)
   99 
  100     # Exception and detail mappings
  101     EXCEPTION_DETAIL_MAPPINGS = {
  102         NO_VALID_HOST: ['NoValidHost'],
  103     }
  104 
  105     # Use special code for each filter rather then categorize all as
  106     # NO_VALID_HOST
  107     FILTER_DETAIL_MAPPINGS = {
  108         'AvailabilityZoneFilter': FILTER_AVAILABILITY,
  109         'CapabilitiesFilter': FILTER_CAPABILITIES,
  110         'CapacityFilter': FILTER_CAPACITY,
  111         'DriverFilter': FILTER_DRIVER,
  112         'IgnoreAttemptedHostsFilter': FILTER_IGNORE,
  113         'JsonFilter': FILTER_JSON,
  114         'RetryFilter': FILTER_RETRY,
  115         'ShareReplicationFilter': FILTER_REPLICATION,
  116     }
  117 
  118 
  119 def translate_action(action_id):
  120     action_message = next((action[1] for action in Action.ALL
  121                            if action[0] == action_id), None)
  122     return action_message or 'unknown action'
  123 
  124 
  125 def translate_detail(detail_id):
  126     detail_message = next((action[1] for action in Detail.ALL
  127                            if action[0] == detail_id), None)
  128     return detail_message or Detail.UNKNOWN_ERROR[1]
  129 
  130 
  131 def translate_detail_id(excep, detail):
  132     if excep is not None:
  133         detail = _translate_exception_to_detail(excep)
  134     if detail in Detail.ALL:
  135         return detail[0]
  136     return Detail.UNKNOWN_ERROR[0]
  137 
  138 
  139 def _translate_exception_to_detail(ex):
  140     if isinstance(ex, exception.NoValidHost):
  141         # if NoValidHost was raised because a filter failed (a filter
  142         # didn't return any hosts), use a filter-specific detail
  143         details = getattr(ex, 'detail_data', {})
  144         last_filter = details.get('last_filter')
  145         return Detail.FILTER_DETAIL_MAPPINGS.get(
  146             last_filter, Detail.NO_VALID_HOST)
  147     else:
  148         for key, value in Detail.EXCEPTION_DETAIL_MAPPINGS.items():
  149             if ex.__class__.__name__ in value:
  150                 return key