| 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 | |
| Adam Israel | 0cd1c02 | 2019-09-03 18:26:08 -0400 | [diff] [blame] | 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.""" |
| Adam Israel | 19c5cfc | 2019-10-03 12:35:38 -0400 | [diff] [blame] | 58 | |
| Adam Israel | d238b03 | 2019-11-11 16:42:02 -0800 | [diff] [blame] | 59 | |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 60 | class MethodNotImplemented(Exception): |
| Adam Israel | 9e5eddb | 2019-12-01 12:55:09 -0500 | [diff] [blame] | 61 | """The method is not implemented.""" |
| 62 | |
| 63 | |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 64 | class N2VCException(Exception): |
| 65 | """ |
| 66 | N2VC exception base class |
| 67 | """ |
| 68 | |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 69 | def __init__(self, message: str = ""): |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 70 | Exception.__init__(self, message) |
| 71 | self.message = message |
| 72 | |
| 73 | def __str__(self): |
| 74 | return self.message |
| 75 | |
| 76 | def __repr__(self): |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 77 | return "{}({})".format(type(self), self.message) |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 78 | |
| 79 | |
| 80 | class N2VCBadArgumentsException(N2VCException): |
| 81 | """ |
| 82 | Bad argument values exception |
| 83 | """ |
| 84 | |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 85 | def __init__(self, message: str = "", bad_args: list = None): |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 86 | N2VCException.__init__(self, message=message) |
| 87 | self.bad_args = bad_args |
| 88 | |
| 89 | def __str__(self): |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 90 | return "<{}> Bad arguments: {} -> {}".format( |
| 91 | type(self), super().__str__(), self.bad_args |
| 92 | ) |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 93 | |
| 94 | |
| 95 | class N2VCConnectionException(N2VCException): |
| 96 | """ |
| 97 | Error connecting to VCA |
| 98 | """ |
| 99 | |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 100 | def __init__(self, message: str = "", url: str = None): |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 101 | N2VCException.__init__(self, message=message) |
| 102 | self.url = url |
| 103 | |
| 104 | def __str__(self): |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 105 | return "<{}> Connection to {} failed: {}".format( |
| 106 | type(self), self.url, super().__str__() |
| 107 | ) |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 108 | |
| 109 | |
| 110 | class N2VCTimeoutException(N2VCException): |
| 111 | """ |
| 112 | Timeout |
| 113 | """ |
| 114 | |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 115 | def __init__(self, message: str = "", timeout: str = ""): |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 116 | N2VCException.__init__(self, message=message) |
| 117 | self.timeout = timeout |
| 118 | |
| 119 | def __str__(self): |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 120 | return "<{}> {} timeout: {}".format(type(self), self.timeout, super().__str__()) |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 121 | |
| 122 | |
| 123 | class N2VCExecutionException(N2VCException): |
| 124 | """ |
| 125 | Error executing primitive |
| 126 | """ |
| 127 | |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 128 | def __init__(self, message: str = "", primitive_name: str = ""): |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 129 | N2VCException.__init__(self, message=message) |
| 130 | self.primitive_name = primitive_name |
| 131 | |
| 132 | def __str__(self): |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 133 | return "<{}> Error executing primitive {} failed: {}".format( |
| 134 | type(self), self.primitive_name, super().__str__() |
| 135 | ) |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 136 | |
| Adam Israel | 9e5eddb | 2019-12-01 12:55:09 -0500 | [diff] [blame] | 137 | |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 138 | class N2VCInvalidCertificate(N2VCException): |
| 139 | """ |
| 140 | Invalid certificate |
| 141 | """ |
| 142 | |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 143 | def __init__(self, message: str = ""): |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 144 | N2VCException.__init__(self, message=message) |
| 145 | |
| 146 | def __str__(self): |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 147 | return "<{}> Invalid certificate: {}".format(type(self), super().__str__()) |
| quilesj | a674841 | 2019-12-04 07:51:26 +0000 | [diff] [blame] | 148 | |
| 149 | |
| David Garcia | c6b1926 | 2020-04-08 09:48:21 +0200 | [diff] [blame] | 150 | class N2VCNotFound(N2VCException): |
| 151 | """ |
| 152 | Not found |
| 153 | """ |
| 154 | |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 155 | def __init__(self, message: str = ""): |
| David Garcia | c6b1926 | 2020-04-08 09:48:21 +0200 | [diff] [blame] | 156 | N2VCException.__init__(self, message=message) |
| 157 | |
| 158 | def __str__(self): |
| beierlm | f52cb7c | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 159 | return "<{}> Not found: {}".format(type(self), super().__str__()) |
| David Garcia | c6b1926 | 2020-04-08 09:48:21 +0200 | [diff] [blame] | 160 | |
| 161 | |
| quilesj | a674841 | 2019-12-04 07:51:26 +0000 | [diff] [blame] | 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 |
| David Garcia | 4fee80e | 2020-05-13 12:18:38 +0200 | [diff] [blame^] | 176 | |
| 177 | |
| 178 | class EntityInvalidException(Exception): |
| 179 | """Entity is not valid, the type does not match any EntityType.""" |