2019-07-07 02:49:54 -07:00
|
|
|
"""
|
|
|
|
Custom exceptions for hyperglass
|
|
|
|
"""
|
|
|
|
|
2019-08-29 23:05:54 -07:00
|
|
|
from typing import Dict
|
2019-08-25 23:22:20 -07:00
|
|
|
|
|
|
|
from hyperglass.constants import code
|
|
|
|
|
2019-07-07 02:49:54 -07:00
|
|
|
|
|
|
|
class HyperglassError(Exception):
|
|
|
|
"""
|
2019-08-25 23:22:20 -07:00
|
|
|
hyperglass base exception
|
2019-07-07 02:49:54 -07:00
|
|
|
"""
|
|
|
|
|
2019-08-29 23:05:54 -07:00
|
|
|
pass
|
2019-08-25 23:22:20 -07:00
|
|
|
|
2019-07-07 02:49:54 -07:00
|
|
|
|
|
|
|
class ConfigError(HyperglassError):
|
|
|
|
"""
|
2019-08-25 23:22:20 -07:00
|
|
|
Raised for generic user-config issues.
|
2019-07-07 02:49:54 -07:00
|
|
|
"""
|
|
|
|
|
2019-08-29 23:05:54 -07:00
|
|
|
def __init__(self, unformatted_msg, kwargs={}):
|
|
|
|
self.message: unformatted_msg.format(**kwargs)
|
|
|
|
self.keywords: Dict = kwargs
|
|
|
|
super().__init__(self.message, self.keywords)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.message
|
2019-07-07 02:49:54 -07:00
|
|
|
|
|
|
|
|
2019-08-25 23:22:20 -07:00
|
|
|
class ConfigInvalid(HyperglassError):
|
|
|
|
"""Raised when a config item fails type or option validation"""
|
2019-07-07 02:49:54 -07:00
|
|
|
|
2019-08-29 23:05:54 -07:00
|
|
|
def __init__(self, **kwargs):
|
|
|
|
self.message: str = 'The value field "{field}" is invalid: {error_msg}'.format(
|
|
|
|
**kwargs
|
|
|
|
)
|
|
|
|
self.keywords: Dict = kwargs
|
|
|
|
super().__init__(self.message, self.keywords)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.message
|
2019-07-15 02:30:42 -07:00
|
|
|
|
2019-08-25 23:22:20 -07:00
|
|
|
|
|
|
|
class ConfigMissing(HyperglassError):
|
|
|
|
"""
|
|
|
|
Raised when a required config file or item is missing or undefined
|
|
|
|
"""
|
|
|
|
|
2019-08-29 23:05:54 -07:00
|
|
|
def __init__(self, kwargs={}):
|
|
|
|
self.message: str = (
|
|
|
|
"{missing_item} is missing or undefined and is required to start "
|
|
|
|
"hyperglass. Please consult the installation documentation."
|
|
|
|
).format(**kwargs)
|
|
|
|
self.keywords: Dict = kwargs
|
|
|
|
super().__init__(self.message, self.keywords)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.message
|
2019-08-25 23:22:20 -07:00
|
|
|
|
|
|
|
|
|
|
|
class ScrapeError(HyperglassError):
|
|
|
|
"""Raised upon a scrape/netmiko error"""
|
|
|
|
|
2019-08-29 23:05:54 -07:00
|
|
|
def __init__(self, kwargs={}):
|
|
|
|
self.message: str = "".format(**kwargs)
|
|
|
|
self.keywords: Dict = kwargs
|
|
|
|
self.status: int = code.target_error
|
|
|
|
super().__init__(self.message, self.keywords)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.message
|
2019-08-25 23:22:20 -07:00
|
|
|
|
|
|
|
|
|
|
|
class AuthError(HyperglassError):
|
|
|
|
"""Raised when authentication to a device fails"""
|
|
|
|
|
2019-08-29 23:05:54 -07:00
|
|
|
def __init__(self, kwargs={}):
|
|
|
|
self.message: str = "".format(**kwargs)
|
|
|
|
self.keywords: Dict = kwargs
|
|
|
|
self.status: int = code.target_error
|
|
|
|
super().__init__(self.message, self.keywords)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.message
|
2019-08-25 23:22:20 -07:00
|
|
|
|
|
|
|
|
|
|
|
class RestError(HyperglassError):
|
|
|
|
"""Raised upon a rest API client error"""
|
|
|
|
|
2019-08-29 23:05:54 -07:00
|
|
|
def __init__(self, kwargs={}):
|
|
|
|
self.message: str = "".format(**kwargs)
|
|
|
|
self.keywords: Dict = kwargs
|
|
|
|
self.status: int = code.target_error
|
|
|
|
super().__init__(self.message, self.keywords)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.message
|
2019-08-25 23:22:20 -07:00
|
|
|
|
|
|
|
|
|
|
|
class InputInvalid(HyperglassError):
|
|
|
|
"""Raised when input validation fails"""
|
|
|
|
|
2019-08-29 23:05:54 -07:00
|
|
|
def __init__(self, unformatted_msg, **kwargs):
|
|
|
|
self.message: str = unformatted_msg.format(**kwargs)
|
|
|
|
self.keywords: Dict = kwargs
|
2019-08-29 07:10:40 -07:00
|
|
|
self.status: int = code.invalid
|
2019-08-29 23:05:54 -07:00
|
|
|
super().__init__(self.message, self.status)
|
2019-08-29 07:10:40 -07:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.message
|
2019-08-25 23:22:20 -07:00
|
|
|
|
|
|
|
|
|
|
|
class InputNotAllowed(HyperglassError):
|
|
|
|
"""
|
|
|
|
Raised when input validation fails due to a blacklist or
|
|
|
|
requires_ipv6_cidr check
|
|
|
|
"""
|
|
|
|
|
2019-08-29 23:05:54 -07:00
|
|
|
def __init__(self, unformatted_msg, **kwargs):
|
|
|
|
self.message: str = unformatted_msg.format(**kwargs)
|
|
|
|
self.keywords: Dict = kwargs
|
|
|
|
self.status: int = code.invalid
|
|
|
|
super().__init__(self.status, self.message)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.message
|
2019-07-15 02:30:42 -07:00
|
|
|
|
|
|
|
|
|
|
|
class ParseError(HyperglassError):
|
|
|
|
"""
|
|
|
|
Raised when an ouput parser encounters an error.
|
|
|
|
"""
|
|
|
|
|
2019-08-29 23:05:54 -07:00
|
|
|
def __init__(self, kwargs={}):
|
|
|
|
self.message: str = "".format(**kwargs)
|
|
|
|
self.keywords: Dict = kwargs
|
|
|
|
self.status: int = code.target_error
|
|
|
|
super().__init__(self.message, self.keywords)
|
2019-07-15 02:30:42 -07:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.message
|
|
|
|
|
|
|
|
|
2019-07-07 02:49:54 -07:00
|
|
|
class UnsupportedDevice(HyperglassError):
|
|
|
|
"""
|
|
|
|
Raised when an input NOS is not in the supported NOS list.
|
|
|
|
"""
|
|
|
|
|
2019-08-29 23:05:54 -07:00
|
|
|
def __init__(self, kwargs={}):
|
|
|
|
self.message: str = "".format(**kwargs)
|
|
|
|
self.keywords: Dict = kwargs
|
|
|
|
self.status: int = code.target_error
|
|
|
|
super().__init__(self.message, self.keywords)
|
2019-07-07 02:49:54 -07:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.message
|