File: exceptions.py

package info (click to toggle)
python-infoblox-client 0.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,540 kB
  • sloc: python: 9,572; makefile: 213
file content (138 lines) | stat: -rw-r--r-- 4,357 bytes parent folder | download
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# 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.


class BaseExc(Exception):
    """Base 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):
        super(BaseExc, self).__init__(self.message % kwargs)
        self.msg = self.message % kwargs
        self.kwargs = kwargs


class InfobloxException(BaseExc):
    """Generic Infoblox Exception."""

    def __init__(self, response, **kwargs):
        self.response = response
        super(InfobloxException, self).__init__(**kwargs)


class InfobloxSearchError(InfobloxException):
    message = "Cannot search '%(obj_type)s' object(s): " \
              "%(content)s [code %(code)s]"


class InfobloxFileDownloadFailed(InfobloxException):
    message = "Unable to download file from '%(url)s'" \
              "\n '%(content)s' [code %(code)s]"


class InfobloxFileUploadFailed(InfobloxException):
    message = "Unable to upload file to '%(url)s '\n %(content)s' '%(code)s'"


class InfobloxCannotCreateObject(InfobloxException):
    message = "Cannot create '%(obj_type)s' object(s): " \
              "%(content)s [code %(code)s]"


class InfobloxMemberAlreadyAssigned(InfobloxCannotCreateObject):
    pass


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 InfobloxHostRecordIpAddrNotCreated(BaseExc):
    message = "Infoblox host record ipv4addr/ipv6addr has not been " \
              "created for IP %(ip)s, mac %(mac)s"


class InfobloxCannotAllocateIp(BaseExc):
    message = "Cannot allocate IP %(ip_data)s"


class InfobloxDidNotReturnCreatedIPBack(BaseExc):
    message = "Infoblox did not return created IP back"


class InfobloxNetworkNotAvailable(BaseExc):
    message = "No network view %(network_view)s for %(cidr)s"


class InfobloxObjectParsingError(BaseExc):
    message = "Infoblox object cannot be parsed from dict: %(data)s"


class HostRecordNotPresent(InfobloxObjectParsingError):
    message = "Cannot parse Host Record object from dict because " \
              "'ipv4addrs'/'ipv6addrs' is absent."


class InfobloxInvalidIp(InfobloxObjectParsingError):
    message = "Bad IP address: %(ip)s"


class InfobloxConnectionError(BaseExc):
    message = "Infoblox HTTP request failed with: %(reason)s"


class InfobloxConfigException(BaseExc):
    """Generic Infoblox Config Exception."""
    message = "Config error: %(msg)s"


class InfobloxBadWAPICredential(InfobloxException):
    message = "Infoblox IPAM is misconfigured: " \
              "infoblox_username and infoblox_password are incorrect." \
              "\n %(content)s [code %(code)s]"


class InfobloxTimeoutError(InfobloxException):
    message = "Connection to NIOS timed out: %(reason)s"


class InfobloxGridTemporaryUnavailable(InfobloxException):
    message = "Cannot perform operation %(operation)s with ref %(ref)s: " \
              "%(content)s [code %(code)s]"


class InfobloxFetchGotMultipleObjects(BaseExc):
    message = "Fetch got multiple objects from the API. Unable to " \
              "deserialize multiple API objects into one InfobloxObject."


class InfobloxFieldNotSearchable(BaseExc):
    message = "Field is not searchable: %(field)s"