| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
from os_vif.i18n import _ |
| 14 |
|
| 15 |
|
| 16 |
class ExceptionBase(Exception): |
| 17 |
"""Base Exception |
| 18 |
|
| 19 |
To correctly use this class, inherit from it and define |
| 20 |
a 'msg_fmt' property. That msg_fmt will get printf'd |
| 21 |
with the keyword arguments provided to the constructor. |
| 22 |
|
| 23 |
""" |
| 24 |
msg_fmt = _("An unknown exception occurred.") |
| 25 |
|
| 26 |
def __init__(self, message=None, **kwargs): |
| 27 |
self.kwargs = kwargs |
| 28 |
|
| 29 |
if not message: |
| 30 |
try: |
| 31 |
message = self.msg_fmt % kwargs |
| 32 |
except Exception: |
| 33 |
|
| 34 |
message = self.msg_fmt |
| 35 |
|
| 36 |
self.message = message |
| 37 |
super(ExceptionBase, self).__init__(message) |
| 38 |
|
| 39 |
def format_message(self): |
| 40 |
|
| 41 |
|
| 42 |
return self.args[0] |
| 43 |
|
| 44 |
|
| 45 |
class LibraryNotInitialized(ExceptionBase): |
| 46 |
msg_fmt = _("Before using the os_vif library, you need to call " |
| 47 |
"os_vif.initialize()") |
| 48 |
|
| 49 |
|
| 50 |
class NoMatchingPlugin(ExceptionBase): |
| 51 |
msg_fmt = _("No VIF plugin was found with the name %(plugin_name)s") |
| 52 |
|
| 53 |
|
| 54 |
class NoMatchingPortProfileClass(ExceptionBase): |
| 55 |
msg_fmt = _("No PortProfile class was found with the name %(name)s") |
| 56 |
|
| 57 |
|
| 58 |
class NoSupportedPortProfileVersion(ExceptionBase): |
| 59 |
msg_fmt = _("PortProfile class %(name)s " |
| 60 |
"versions %(got_versions)s do not satisfy " |
| 61 |
"min=%(min_version)s max=%(max_version)s") |
| 62 |
|
| 63 |
|
| 64 |
class NoMatchingVIFClass(ExceptionBase): |
| 65 |
msg_fmt = _("No VIF class was found with the name %(name)s") |
| 66 |
|
| 67 |
|
| 68 |
class NoSupportedVIFVersion(ExceptionBase): |
| 69 |
msg_fmt = _("VIF class %(name)s versions %(got_versions)s " |
| 70 |
"do not satisfy min=%(min_version)s max=%(max_version)s") |
| 71 |
|
| 72 |
|
| 73 |
class PlugException(ExceptionBase): |
| 74 |
msg_fmt = _("Failed to plug VIF %(vif)s. Got error: %(err)s") |
| 75 |
|
| 76 |
|
| 77 |
class UnplugException(ExceptionBase): |
| 78 |
msg_fmt = _("Failed to unplug VIF %(vif)s. Got error: %(err)s") |
| 79 |
|
| 80 |
|
| 81 |
class NetworkMissingPhysicalNetwork(ExceptionBase): |
| 82 |
msg_fmt = _("Physical network is missing for network %(network_uuid)s") |
| 83 |
|
| 84 |
|
| 85 |
class NetworkInterfaceNotFound(ExceptionBase): |
| 86 |
msg_fmt = _("Network interface %(interface)s not found") |
| 87 |
|
| 88 |
|
| 89 |
class NetworkInterfaceTypeNotDefined(ExceptionBase): |
| 90 |
msg_fmt = _("Network interface type %(type)s not defined") |
| 91 |
|
| 92 |
|
| 93 |
class ExternalImport(ExceptionBase): |
| 94 |
msg_fmt = _("Use of this module outside of os_vif is not allowed. It must " |
| 95 |
"not be imported in os-vif plugins that are out of tree as it " |
| 96 |
"is not a public interface of os-vif.") |
| 97 |
|
| 98 |
|
| 99 |
class NotImplementedForOS(ExceptionBase): |
| 100 |
msg_fmt = _("Function %(function)s for %(os)s operating system") |