1 # Copyright 2019 Canonical Ltd.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 class N2VCException(Exception):
18 N2VC exception base class
21 def __init__(self
, message
: str = ""):
22 Exception.__init
__(self
, message
)
23 self
.message
= message
29 return "{}({})".format(type(self
), self
.message
)
32 class N2VCBadArgumentsException(N2VCException
):
34 Bad argument values exception
37 def __init__(self
, message
: str = "", bad_args
: list = None):
38 N2VCException
.__init
__(self
, message
=message
)
39 self
.bad_args
= bad_args
42 return "<{}> Bad arguments: {} -> {}".format(
43 type(self
), super().__str
__(), self
.bad_args
47 class N2VCConnectionException(N2VCException
):
49 Error connecting to VCA
52 def __init__(self
, message
: str = "", url
: str = None):
53 N2VCException
.__init
__(self
, message
=message
)
57 return "<{}> Connection to {} failed: {}".format(
58 type(self
), self
.url
, super().__str
__()
62 class N2VCTimeoutException(N2VCException
):
67 def __init__(self
, message
: str = "", timeout
: str = ""):
68 N2VCException
.__init
__(self
, message
=message
)
69 self
.timeout
= timeout
72 return "<{}> {} timeout: {}".format(type(self
), self
.timeout
, super().__str
__())
75 class N2VCExecutionException(N2VCException
):
77 Error executing primitive
80 def __init__(self
, message
: str = "", primitive_name
: str = ""):
81 N2VCException
.__init
__(self
, message
=message
)
82 self
.primitive_name
= primitive_name
85 return "<{}> Error executing primitive {} failed: {}".format(
86 type(self
), self
.primitive_name
, super().__str
__()
90 class N2VCInvalidCertificate(N2VCException
):
95 def __init__(self
, message
: str = ""):
96 N2VCException
.__init
__(self
, message
=message
)
99 return "<{}> Invalid certificate: {}".format(type(self
), super().__str
__())
102 class N2VCNotFound(N2VCException
):
107 def __init__(self
, message
: str = ""):
108 N2VCException
.__init
__(self
, message
=message
)
111 return "<{}> Not found: {}".format(type(self
), super().__str
__())
114 class K8sException(Exception):
119 def __init__(self
, message
: str):
120 Exception.__init
__(self
, message
)
121 self
._message
= message
130 class EntityInvalidException(Exception):
131 """Entity is not valid, the type does not match any EntityType."""
134 class JujuInvalidK8sConfiguration(N2VCException
):
135 """Invalid K8s configuration."""
138 class JujuCharmNotFound(N2VCException
):
139 """The Charm can't be found or is not readable."""
142 class JujuControllerFailedConnecting(N2VCException
):
143 """Failed connecting to juju controller."""
146 class JujuModelAlreadyExists(N2VCException
):
147 """The model already exists."""
150 class JujuApplicationExists(N2VCException
):
151 """The Application already exists."""
154 class JujuApplicationNotFound(N2VCException
):
155 """The Application cannot be found."""
158 class JujuLeaderUnitNotFound(N2VCException
):
159 """The Application cannot be found."""
162 class JujuActionNotFound(N2VCException
):
163 """The Action cannot be found."""
166 class JujuMachineNotFound(N2VCException
):
167 """The machine cannot be found."""
170 class JujuK8sProxycharmNotSupported(N2VCException
):
171 """K8s Proxy Charms not supported in this installation."""
174 class N2VCPrimitiveExecutionFailed(N2VCException
):
175 """Something failed while attempting to execute a primitive."""
178 class NetworkServiceDoesNotExist(N2VCException
):
179 """The Network Service being acted against does not exist."""
182 class PrimitiveDoesNotExist(N2VCException
):
183 """The Primitive being executed does not exist."""
186 class NoRouteToHost(N2VCException
):
187 """There was no route to the specified host."""
190 class AuthenticationFailed(N2VCException
):
191 """The authentication for the specified user failed."""
194 class MethodNotImplemented(N2VCException
):
195 """The method is not implemented."""