Debian Codegraph @

os_vif/exception.py

raw symbols SCIP
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 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 # at least get the core message out if something happened
34 message = self.msg_fmt
35
36 self.message = message
37 super(ExceptionBase, self).__init__(message)
38
39 def format_message(self):
40 # NOTE(mrodden): use the first argument to the python Exception object
41 # which should be our full NovaException message, (see __init__)
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")