blob: e2c08690472bb0fc4b5b9c5f75bc00fa758e6eca (
plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# Copyright 2015 Infoblox Inc.
# 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.
import gettext
import six
from designate import exceptions
_ = gettext.gettext
class InfobloxExceptionBase(exceptions.Backend):
"""Base IB Exception.
To correctly use this class, inherit from it and define
a 'message' property. That message will get printf'd
with the keyword arguments provided to the constructor.
"""
message = _("An unknown exception occurred.")
def __init__(self, **kwargs):
try:
super(InfobloxExceptionBase, self).__init__(self.message % kwargs)
self.msg = self.message % kwargs
except Exception:
if self.use_fatal_exceptions():
raise
else:
# at least get the core message out if something happened
super(InfobloxExceptionBase, self).__init__(self.message)
def __unicode__(self):
return six.text_type(self.msg)
def use_fatal_exceptions(self):
return False
class ServiceUnavailable(InfobloxExceptionBase):
message = _("The service is unavailable")
class ResourceExhausted(ServiceUnavailable):
pass
class InfobloxException(InfobloxExceptionBase):
"""Generic Infoblox Exception."""
def __init__(self, response, **kwargs):
self.response = response
super(InfobloxException, self).__init__(**kwargs)
class InfobloxIsMisconfigured(InfobloxExceptionBase):
message = _(
"Infoblox backend is misconfigured: '%(option)s' must be defined.")
class InfobloxSearchError(InfobloxException):
message = _("Cannot search '%(objtype)s' object(s): "
"%(content)s [code %(code)s]")
class InfobloxCannotCreateObject(InfobloxException):
message = _("Cannot create '%(objtype)s' object(s): "
"%(content)s [code %(code)s]")
class InfobloxCannotDeleteObject(InfobloxException):
message = _("Cannot delete object with ref %(ref)s: "
"%(content)s [code %(code)s]")
class InfobloxCannotUpdateObject(InfobloxException):
message = _("Cannot update object with ref %(ref)s: "
"%(content)s [code %(code)s]")
class InfobloxFuncException(InfobloxException):
message = _("Error occurred during function's '%(func_name)s' call: "
"ref %(ref)s: %(content)s [code %(code)s]")
class NoInfobloxMemberAvailable(ResourceExhausted):
message = _("No Infoblox Member is available.")
class InfobloxObjectParsingError(InfobloxExceptionBase):
message = _("Infoblox object cannot be parsed from dict: %(data)s")
|