python-redfish/redfish/exception.py
Uggla 466534359c Improve error management
- Better handle connection errors.
- Better handle login errors.
- Improve exception process.
- Update examples.
	- Make examples compatible with new configuration file.
	- Show exception handling.
- Validate trusted SSL connection.
- Various PEP8 corrections.
2016-01-02 11:33:58 +01:00

53 lines
1.9 KiB
Python

# -*- coding: utf-8 -*-
import config
class RedfishException(Exception):
"""Base class for redfish exceptions"""
def __init__(self, message, **kwargs):
self.kwargs = kwargs
self.message = message
self.advices = None
config.logger.error(message)
class ConnectionFailureException(RedfishException):
def __init__(self, message, **kwargs):
super(ConnectionFailureException, self).__init__(message, **kwargs)
self.advices = '1- Check if the url is the correct one\n' + \
'2- Check if your device is answering on the network\n'
class InvalidRedfishContentException(RedfishException):
def __init__(self, message, **kwargs):
super(InvalidRedfishContentException, self).__init__(message, **kwargs)
self.advices = \
'1- Check if the url is the correct one\n' + \
' Most of the time you are not pointing to the rest API\n'
class NonTrustedCertificatException(RedfishException):
def __init__(self, message, **kwargs):
super(NonTrustedCertificatException, self).__init__(message, **kwargs)
self.advices = \
'1- Check if the url is the correct one\n' + \
'2- Check if your device has a valid trusted certificat\n' + \
' You can use openssl to validate it using the command :\n' + \
' openssl s_client -showcerts -connect <server>:443\n'
class AuthenticationFailureException(RedfishException):
def __init__(self, message, **kwargs):
super(AuthenticationFailureException, self).__init__(message, **kwargs)
self.message += str(kwargs['code'])
self.queryAnswer = kwargs['queryAnswer']
if kwargs['code'] == 400:
self.message += ': ' + self.queryAnswer['Messages'][0]['MessageID']
self.advices = '1- Check your credentials\n'
self.message += '\n'
class LogoutFailureException(RedfishException):
pass