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