| Adam Israel | 0cd1c02 | 2019-09-03 18:26:08 -0400 | [diff] [blame] | 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 | |
| quilesj | a674841 | 2019-12-04 07:51:26 +0000 | [diff] [blame] | 15 | |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 16 | class N2VCException(Exception): |
| 17 | """ |
| 18 | N2VC exception base class |
| 19 | """ |
| 20 | |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 21 | def __init__(self, message: str = ""): |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 22 | Exception.__init__(self, message) |
| 23 | self.message = message |
| 24 | |
| 25 | def __str__(self): |
| 26 | return self.message |
| 27 | |
| 28 | def __repr__(self): |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 29 | return "{}({})".format(type(self), self.message) |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 30 | |
| 31 | |
| 32 | class N2VCBadArgumentsException(N2VCException): |
| 33 | """ |
| 34 | Bad argument values exception |
| 35 | """ |
| 36 | |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 37 | def __init__(self, message: str = "", bad_args: list = None): |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 38 | N2VCException.__init__(self, message=message) |
| 39 | self.bad_args = bad_args |
| 40 | |
| 41 | def __str__(self): |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 42 | return "<{}> Bad arguments: {} -> {}".format( |
| 43 | type(self), super().__str__(), self.bad_args |
| 44 | ) |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 45 | |
| 46 | |
| 47 | class N2VCConnectionException(N2VCException): |
| 48 | """ |
| 49 | Error connecting to VCA |
| 50 | """ |
| 51 | |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 52 | def __init__(self, message: str = "", url: str = None): |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 53 | N2VCException.__init__(self, message=message) |
| 54 | self.url = url |
| 55 | |
| 56 | def __str__(self): |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 57 | return "<{}> Connection to {} failed: {}".format( |
| 58 | type(self), self.url, super().__str__() |
| 59 | ) |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 60 | |
| 61 | |
| 62 | class N2VCTimeoutException(N2VCException): |
| 63 | """ |
| 64 | Timeout |
| 65 | """ |
| 66 | |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 67 | def __init__(self, message: str = "", timeout: str = ""): |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 68 | N2VCException.__init__(self, message=message) |
| 69 | self.timeout = timeout |
| 70 | |
| 71 | def __str__(self): |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 72 | return "<{}> {} timeout: {}".format(type(self), self.timeout, super().__str__()) |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 73 | |
| 74 | |
| 75 | class N2VCExecutionException(N2VCException): |
| 76 | """ |
| 77 | Error executing primitive |
| 78 | """ |
| 79 | |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 80 | def __init__(self, message: str = "", primitive_name: str = ""): |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 81 | N2VCException.__init__(self, message=message) |
| 82 | self.primitive_name = primitive_name |
| 83 | |
| 84 | def __str__(self): |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 85 | return "<{}> Error executing primitive {} failed: {}".format( |
| 86 | type(self), self.primitive_name, super().__str__() |
| 87 | ) |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 88 | |
| Adam Israel | 9e5eddb | 2019-12-01 12:55:09 -0500 | [diff] [blame] | 89 | |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 90 | class N2VCInvalidCertificate(N2VCException): |
| 91 | """ |
| 92 | Invalid certificate |
| 93 | """ |
| 94 | |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 95 | def __init__(self, message: str = ""): |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 96 | N2VCException.__init__(self, message=message) |
| 97 | |
| 98 | def __str__(self): |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 99 | return "<{}> Invalid certificate: {}".format(type(self), super().__str__()) |
| quilesj | a674841 | 2019-12-04 07:51:26 +0000 | [diff] [blame] | 100 | |
| 101 | |
| David Garcia | c6b1926 | 2020-04-08 09:48:21 +0200 | [diff] [blame] | 102 | class N2VCNotFound(N2VCException): |
| 103 | """ |
| 104 | Not found |
| 105 | """ |
| 106 | |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 107 | def __init__(self, message: str = ""): |
| David Garcia | c6b1926 | 2020-04-08 09:48:21 +0200 | [diff] [blame] | 108 | N2VCException.__init__(self, message=message) |
| 109 | |
| 110 | def __str__(self): |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 111 | return "<{}> Not found: {}".format(type(self), super().__str__()) |
| David Garcia | c6b1926 | 2020-04-08 09:48:21 +0200 | [diff] [blame] | 112 | |
| 113 | |
| aktas | fa02f8a | 2021-07-29 17:41:40 +0300 | [diff] [blame] | 114 | class N2VCApplicationExists(N2VCException): |
| 115 | """ |
| 116 | Application Exists |
| 117 | """ |
| 118 | |
| 119 | def __init__(self, message: str = ""): |
| 120 | N2VCException.__init__(self, message=message) |
| 121 | |
| 122 | def __str__(self): |
| 123 | return "<{}> Application Exists: {}".format(type(self), super().__str__()) |
| 124 | |
| 125 | |
| ksaikiranr | cdf0b8e | 2021-03-17 12:50:00 +0530 | [diff] [blame] | 126 | class JujuError(N2VCException): |
| 127 | """ |
| 128 | Juju Error |
| 129 | """ |
| 130 | |
| 131 | def __init__(self, message: str = ""): |
| 132 | N2VCException.__init__(self, message=message) |
| 133 | |
| 134 | def __str__(self): |
| 135 | return "<{}> Juju Error: {}".format(type(self), super().__str__()) |
| 136 | |
| 137 | |
| quilesj | a674841 | 2019-12-04 07:51:26 +0000 | [diff] [blame] | 138 | class K8sException(Exception): |
| 139 | """ |
| 140 | K8s exception |
| 141 | """ |
| 142 | |
| 143 | def __init__(self, message: str): |
| 144 | Exception.__init__(self, message) |
| 145 | self._message = message |
| 146 | |
| 147 | def __str__(self): |
| 148 | return self._message |
| 149 | |
| 150 | def __repr__(self): |
| 151 | return self._message |
| David Garcia | 4fee80e | 2020-05-13 12:18:38 +0200 | [diff] [blame] | 152 | |
| 153 | |
| 154 | class EntityInvalidException(Exception): |
| 155 | """Entity is not valid, the type does not match any EntityType.""" |
| David Garcia | 475a722 | 2020-09-21 16:19:15 +0200 | [diff] [blame] | 156 | |
| 157 | |
| 158 | class JujuInvalidK8sConfiguration(N2VCException): |
| 159 | """Invalid K8s configuration.""" |
| 160 | |
| 161 | |
| 162 | class JujuCharmNotFound(N2VCException): |
| 163 | """The Charm can't be found or is not readable.""" |
| 164 | |
| 165 | |
| 166 | class JujuControllerFailedConnecting(N2VCException): |
| 167 | """Failed connecting to juju controller.""" |
| 168 | |
| 169 | |
| 170 | class JujuModelAlreadyExists(N2VCException): |
| 171 | """The model already exists.""" |
| 172 | |
| 173 | |
| 174 | class JujuApplicationExists(N2VCException): |
| 175 | """The Application already exists.""" |
| 176 | |
| 177 | |
| 178 | class JujuApplicationNotFound(N2VCException): |
| 179 | """The Application cannot be found.""" |
| 180 | |
| 181 | |
| 182 | class JujuLeaderUnitNotFound(N2VCException): |
| 183 | """The Application cannot be found.""" |
| 184 | |
| 185 | |
| 186 | class JujuActionNotFound(N2VCException): |
| 187 | """The Action cannot be found.""" |
| 188 | |
| 189 | |
| 190 | class JujuMachineNotFound(N2VCException): |
| 191 | """The machine cannot be found.""" |
| 192 | |
| 193 | |
| 194 | class JujuK8sProxycharmNotSupported(N2VCException): |
| 195 | """K8s Proxy Charms not supported in this installation.""" |
| 196 | |
| 197 | |
| 198 | class N2VCPrimitiveExecutionFailed(N2VCException): |
| 199 | """Something failed while attempting to execute a primitive.""" |
| 200 | |
| 201 | |
| 202 | class NetworkServiceDoesNotExist(N2VCException): |
| 203 | """The Network Service being acted against does not exist.""" |
| 204 | |
| 205 | |
| 206 | class PrimitiveDoesNotExist(N2VCException): |
| 207 | """The Primitive being executed does not exist.""" |
| 208 | |
| 209 | |
| 210 | class NoRouteToHost(N2VCException): |
| 211 | """There was no route to the specified host.""" |
| 212 | |
| 213 | |
| 214 | class AuthenticationFailed(N2VCException): |
| 215 | """The authentication for the specified user failed.""" |
| 216 | |
| 217 | |
| 218 | class MethodNotImplemented(N2VCException): |
| 219 | """The method is not implemented.""" |