59bcc1adbaf262040ea6b6d7dd4d5f860b370554
[osm/N2VC.git] / n2vc / exceptions.py
1 # Copyright 2019 Canonical Ltd.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15
16 class JujuCharmNotFound(Exception):
17 """The Charm can't be found or is not readable."""
18
19
20 class JujuControllerFailedConnecting(Exception):
21 """Failed connecting to juju controller."""
22
23
24 class JujuModelAlreadyExists(Exception):
25 """The model already exists."""
26
27
28 class JujuApplicationExists(Exception):
29 """The Application already exists."""
30
31
32 class JujuApplicationNotFound(Exception):
33 """The Application cannot be found."""
34
35
36 class JujuMachineNotFound(Exception):
37 """The machine cannot be found."""
38
39
40 class JujuK8sProxycharmNotSupported(Exception):
41 """K8s Proxy Charms not supported in this installation."""
42
43
44 class N2VCPrimitiveExecutionFailed(Exception):
45 """Something failed while attempting to execute a primitive."""
46
47
48 class NetworkServiceDoesNotExist(Exception):
49 """The Network Service being acted against does not exist."""
50
51
52 class PrimitiveDoesNotExist(Exception):
53 """The Primitive being executed does not exist."""
54
55
56 class NoRouteToHost(Exception):
57 """There was no route to the specified host."""
58
59
60 class AuthenticationFailed(Exception):
61 """The authentication for the specified user failed."""
62
63
64 class MethodNotImplemented(Exception):
65 """The method is not implemented."""
66
67
68 class N2VCException(Exception):
69 """
70 N2VC exception base class
71 """
72
73 def __init__(self, message: str = ""):
74 Exception.__init__(self, message)
75 self.message = message
76
77 def __str__(self):
78 return self.message
79
80 def __repr__(self):
81 return "{}({})".format(type(self), self.message)
82
83
84 class N2VCBadArgumentsException(N2VCException):
85 """
86 Bad argument values exception
87 """
88
89 def __init__(self, message: str = "", bad_args: list = None):
90 N2VCException.__init__(self, message=message)
91 self.bad_args = bad_args
92
93 def __str__(self):
94 return "<{}> Bad arguments: {} -> {}".format(
95 type(self), super().__str__(), self.bad_args
96 )
97
98
99 class N2VCConnectionException(N2VCException):
100 """
101 Error connecting to VCA
102 """
103
104 def __init__(self, message: str = "", url: str = None):
105 N2VCException.__init__(self, message=message)
106 self.url = url
107
108 def __str__(self):
109 return "<{}> Connection to {} failed: {}".format(
110 type(self), self.url, super().__str__()
111 )
112
113
114 class N2VCTimeoutException(N2VCException):
115 """
116 Timeout
117 """
118
119 def __init__(self, message: str = "", timeout: str = ""):
120 N2VCException.__init__(self, message=message)
121 self.timeout = timeout
122
123 def __str__(self):
124 return "<{}> {} timeout: {}".format(type(self), self.timeout, super().__str__())
125
126
127 class N2VCExecutionException(N2VCException):
128 """
129 Error executing primitive
130 """
131
132 def __init__(self, message: str = "", primitive_name: str = ""):
133 N2VCException.__init__(self, message=message)
134 self.primitive_name = primitive_name
135
136 def __str__(self):
137 return "<{}> Error executing primitive {} failed: {}".format(
138 type(self), self.primitive_name, super().__str__()
139 )
140
141
142 class N2VCInvalidCertificate(N2VCException):
143 """
144 Invalid certificate
145 """
146
147 def __init__(self, message: str = ""):
148 N2VCException.__init__(self, message=message)
149
150 def __str__(self):
151 return "<{}> Invalid certificate: {}".format(type(self), super().__str__())
152
153
154 class N2VCNotFound(N2VCException):
155 """
156 Not found
157 """
158
159 def __init__(self, message: str = ""):
160 N2VCException.__init__(self, message=message)
161
162 def __str__(self):
163 return "<{}> Not found: {}".format(type(self), super().__str__())
164
165
166 class K8sException(Exception):
167 """
168 K8s exception
169 """
170
171 def __init__(self, message: str):
172 Exception.__init__(self, message)
173 self._message = message
174
175 def __str__(self):
176 return self._message
177
178 def __repr__(self):
179 return self._message
180
181
182 class EntityInvalidException(Exception):
183 """Entity is not valid, the type does not match any EntityType."""