Remove EntityType from juju watcher and workaround juju bug for retrieving the status
[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 JujuLeaderUnitNotFound(Exception):
37 """The Application cannot be found."""
38
39
40 class JujuActionNotFound(Exception):
41 """The Action cannot be found."""
42
43
44 class JujuMachineNotFound(Exception):
45 """The machine cannot be found."""
46
47
48 class JujuK8sProxycharmNotSupported(Exception):
49 """K8s Proxy Charms not supported in this installation."""
50
51
52 class N2VCPrimitiveExecutionFailed(Exception):
53 """Something failed while attempting to execute a primitive."""
54
55
56 class NetworkServiceDoesNotExist(Exception):
57 """The Network Service being acted against does not exist."""
58
59
60 class PrimitiveDoesNotExist(Exception):
61 """The Primitive being executed does not exist."""
62
63
64 class NoRouteToHost(Exception):
65 """There was no route to the specified host."""
66
67
68 class AuthenticationFailed(Exception):
69 """The authentication for the specified user failed."""
70
71
72 class MethodNotImplemented(Exception):
73 """The method is not implemented."""
74
75
76 class N2VCException(Exception):
77 """
78 N2VC exception base class
79 """
80
81 def __init__(self, message: str = ""):
82 Exception.__init__(self, message)
83 self.message = message
84
85 def __str__(self):
86 return self.message
87
88 def __repr__(self):
89 return "{}({})".format(type(self), self.message)
90
91
92 class N2VCBadArgumentsException(N2VCException):
93 """
94 Bad argument values exception
95 """
96
97 def __init__(self, message: str = "", bad_args: list = None):
98 N2VCException.__init__(self, message=message)
99 self.bad_args = bad_args
100
101 def __str__(self):
102 return "<{}> Bad arguments: {} -> {}".format(
103 type(self), super().__str__(), self.bad_args
104 )
105
106
107 class N2VCConnectionException(N2VCException):
108 """
109 Error connecting to VCA
110 """
111
112 def __init__(self, message: str = "", url: str = None):
113 N2VCException.__init__(self, message=message)
114 self.url = url
115
116 def __str__(self):
117 return "<{}> Connection to {} failed: {}".format(
118 type(self), self.url, super().__str__()
119 )
120
121
122 class N2VCTimeoutException(N2VCException):
123 """
124 Timeout
125 """
126
127 def __init__(self, message: str = "", timeout: str = ""):
128 N2VCException.__init__(self, message=message)
129 self.timeout = timeout
130
131 def __str__(self):
132 return "<{}> {} timeout: {}".format(type(self), self.timeout, super().__str__())
133
134
135 class N2VCExecutionException(N2VCException):
136 """
137 Error executing primitive
138 """
139
140 def __init__(self, message: str = "", primitive_name: str = ""):
141 N2VCException.__init__(self, message=message)
142 self.primitive_name = primitive_name
143
144 def __str__(self):
145 return "<{}> Error executing primitive {} failed: {}".format(
146 type(self), self.primitive_name, super().__str__()
147 )
148
149
150 class N2VCInvalidCertificate(N2VCException):
151 """
152 Invalid certificate
153 """
154
155 def __init__(self, message: str = ""):
156 N2VCException.__init__(self, message=message)
157
158 def __str__(self):
159 return "<{}> Invalid certificate: {}".format(type(self), super().__str__())
160
161
162 class N2VCNotFound(N2VCException):
163 """
164 Not found
165 """
166
167 def __init__(self, message: str = ""):
168 N2VCException.__init__(self, message=message)
169
170 def __str__(self):
171 return "<{}> Not found: {}".format(type(self), super().__str__())
172
173
174 class K8sException(Exception):
175 """
176 K8s exception
177 """
178
179 def __init__(self, message: str):
180 Exception.__init__(self, message)
181 self._message = message
182
183 def __str__(self):
184 return self._message
185
186 def __repr__(self):
187 return self._message
188
189
190 class EntityInvalidException(Exception):
191 """Entity is not valid, the type does not match any EntityType."""