1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
# Copyright 2015 IBM Corp.
#
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""HttpError, the EntryWrapper for HttpErrorResponse ('web' namespace)."""
from oslo_log import log as logging
import pypowervm.const as pc
import pypowervm.wrappers.entry_wrapper as ewrap
LOG = logging.getLogger(__name__)
_REASON_CODE = 'ReasonCode'
_MESSAGE = 'Message'
_HTTP_STATUS = 'HTTPStatus'
# Error codes that indicate the VIOS is busy
_VIOS_BUSY_ERR_CODES = ['HSCL3205', 'VIOS0014']
@ewrap.EntryWrapper.pvm_type('HttpErrorResponse', ns=pc.WEB_NS)
class HttpError(ewrap.EntryWrapper):
@property
def status(self):
return self._get_val_int(_HTTP_STATUS)
@property
def reason_code(self):
return self._get_val_str(_REASON_CODE)
@property
def message(self):
return self._get_val_str(_MESSAGE)
def is_vios_busy(self):
try:
msg = self.message
if any(code in msg for code in _VIOS_BUSY_ERR_CODES):
return True
return self._legacy_message_check(msg)
except Exception:
return False
def _legacy_message_check(self, msg):
# This logic is...unfortunate. We have to parse messages for strings
# (instead of keys). But we will only do that if it is marked an
# internal error.
if self.status != pc.HTTPStatus.INTERNAL_ERROR:
return False
# The old message met the following criteria
if ('VIOS' in msg and
'is busy processing some other request' in msg):
return True
# The new message format is the following
if 'The system is currently too busy' in msg:
return True
# All others, assume not busy
return False
|