| 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 | |
| Adam Israel | 0cd1c02 | 2019-09-03 18:26:08 -0400 | [diff] [blame] | 16 | class JujuCharmNotFound(Exception): |
| 17 | """The Charm can't be found or is not readable.""" |
| 18 | |
| 19 | |
| David Garcia | 4fee80e | 2020-05-13 12:18:38 +0200 | [diff] [blame] | 20 | class JujuControllerFailedConnecting(Exception): |
| 21 | """Failed connecting to juju controller.""" |
| 22 | |
| 23 | |
| 24 | class JujuModelAlreadyExists(Exception): |
| 25 | """The model already exists.""" |
| 26 | |
| 27 | |
| Adam Israel | 0cd1c02 | 2019-09-03 18:26:08 -0400 | [diff] [blame] | 28 | class JujuApplicationExists(Exception): |
| 29 | """The Application already exists.""" |
| 30 | |
| 31 | |
| David Garcia | 4fee80e | 2020-05-13 12:18:38 +0200 | [diff] [blame] | 32 | class JujuApplicationNotFound(Exception): |
| 33 | """The Application cannot be found.""" |
| 34 | |
| 35 | |
| 36 | class JujuMachineNotFound(Exception): |
| 37 | """The machine cannot be found.""" |
| 38 | |
| 39 | |
| Dominik Fleischmann | bd808f2 | 2020-06-09 11:57:14 +0200 | [diff] [blame] | 40 | class JujuK8sProxycharmNotSupported(Exception): |
| 41 | """K8s Proxy Charms not supported in this installation.""" |
| 42 | |
| 43 | |
| Adam Israel | 0cd1c02 | 2019-09-03 18:26:08 -0400 | [diff] [blame] | 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.""" |
| Adam Israel | 19c5cfc | 2019-10-03 12:35:38 -0400 | [diff] [blame] | 62 | |
| Adam Israel | d238b03 | 2019-11-11 16:42:02 -0800 | [diff] [blame] | 63 | |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 64 | class MethodNotImplemented(Exception): |
| Adam Israel | 9e5eddb | 2019-12-01 12:55:09 -0500 | [diff] [blame] | 65 | """The method is not implemented.""" |
| 66 | |
| 67 | |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 68 | class N2VCException(Exception): |
| 69 | """ |
| 70 | N2VC exception base class |
| 71 | """ |
| 72 | |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 73 | def __init__(self, message: str = ""): |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 74 | Exception.__init__(self, message) |
| 75 | self.message = message |
| 76 | |
| 77 | def __str__(self): |
| 78 | return self.message |
| 79 | |
| 80 | def __repr__(self): |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 81 | return "{}({})".format(type(self), self.message) |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 82 | |
| 83 | |
| 84 | class N2VCBadArgumentsException(N2VCException): |
| 85 | """ |
| 86 | Bad argument values exception |
| 87 | """ |
| 88 | |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 89 | def __init__(self, message: str = "", bad_args: list = None): |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 90 | N2VCException.__init__(self, message=message) |
| 91 | self.bad_args = bad_args |
| 92 | |
| 93 | def __str__(self): |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 94 | return "<{}> Bad arguments: {} -> {}".format( |
| 95 | type(self), super().__str__(), self.bad_args |
| 96 | ) |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 97 | |
| 98 | |
| 99 | class N2VCConnectionException(N2VCException): |
| 100 | """ |
| 101 | Error connecting to VCA |
| 102 | """ |
| 103 | |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 104 | def __init__(self, message: str = "", url: str = None): |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 105 | N2VCException.__init__(self, message=message) |
| 106 | self.url = url |
| 107 | |
| 108 | def __str__(self): |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 109 | return "<{}> Connection to {} failed: {}".format( |
| 110 | type(self), self.url, super().__str__() |
| 111 | ) |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 112 | |
| 113 | |
| 114 | class N2VCTimeoutException(N2VCException): |
| 115 | """ |
| 116 | Timeout |
| 117 | """ |
| 118 | |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 119 | def __init__(self, message: str = "", timeout: str = ""): |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 120 | N2VCException.__init__(self, message=message) |
| 121 | self.timeout = timeout |
| 122 | |
| 123 | def __str__(self): |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 124 | return "<{}> {} timeout: {}".format(type(self), self.timeout, super().__str__()) |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 125 | |
| 126 | |
| 127 | class N2VCExecutionException(N2VCException): |
| 128 | """ |
| 129 | Error executing primitive |
| 130 | """ |
| 131 | |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 132 | def __init__(self, message: str = "", primitive_name: str = ""): |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 133 | N2VCException.__init__(self, message=message) |
| 134 | self.primitive_name = primitive_name |
| 135 | |
| 136 | def __str__(self): |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 137 | return "<{}> Error executing primitive {} failed: {}".format( |
| 138 | type(self), self.primitive_name, super().__str__() |
| 139 | ) |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 140 | |
| Adam Israel | 9e5eddb | 2019-12-01 12:55:09 -0500 | [diff] [blame] | 141 | |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 142 | class N2VCInvalidCertificate(N2VCException): |
| 143 | """ |
| 144 | Invalid certificate |
| 145 | """ |
| 146 | |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 147 | def __init__(self, message: str = ""): |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 148 | N2VCException.__init__(self, message=message) |
| 149 | |
| 150 | def __str__(self): |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 151 | return "<{}> Invalid certificate: {}".format(type(self), super().__str__()) |
| quilesj | a674841 | 2019-12-04 07:51:26 +0000 | [diff] [blame] | 152 | |
| 153 | |
| David Garcia | c6b1926 | 2020-04-08 09:48:21 +0200 | [diff] [blame] | 154 | class N2VCNotFound(N2VCException): |
| 155 | """ |
| 156 | Not found |
| 157 | """ |
| 158 | |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 159 | def __init__(self, message: str = ""): |
| David Garcia | c6b1926 | 2020-04-08 09:48:21 +0200 | [diff] [blame] | 160 | N2VCException.__init__(self, message=message) |
| 161 | |
| 162 | def __str__(self): |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 163 | return "<{}> Not found: {}".format(type(self), super().__str__()) |
| David Garcia | c6b1926 | 2020-04-08 09:48:21 +0200 | [diff] [blame] | 164 | |
| 165 | |
| quilesj | a674841 | 2019-12-04 07:51:26 +0000 | [diff] [blame] | 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 |
| David Garcia | 4fee80e | 2020-05-13 12:18:38 +0200 | [diff] [blame] | 180 | |
| 181 | |
| 182 | class EntityInvalidException(Exception): |
| 183 | """Entity is not valid, the type does not match any EntityType.""" |