| 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 | |
| 20 | class JujuApplicationExists(Exception): |
| 21 | """The Application already exists.""" |
| 22 | |
| 23 | |
| 24 | class N2VCPrimitiveExecutionFailed(Exception): |
| 25 | """Something failed while attempting to execute a primitive.""" |
| 26 | |
| 27 | |
| 28 | class NetworkServiceDoesNotExist(Exception): |
| 29 | """The Network Service being acted against does not exist.""" |
| 30 | |
| 31 | |
| 32 | class PrimitiveDoesNotExist(Exception): |
| 33 | """The Primitive being executed does not exist.""" |
| 34 | |
| 35 | |
| 36 | class NoRouteToHost(Exception): |
| 37 | """There was no route to the specified host.""" |
| 38 | |
| 39 | |
| 40 | class AuthenticationFailed(Exception): |
| 41 | """The authentication for the specified user failed.""" |
| Adam Israel | 19c5cfc | 2019-10-03 12:35:38 -0400 | [diff] [blame] | 42 | |
| Adam Israel | d238b03 | 2019-11-11 16:42:02 -0800 | [diff] [blame] | 43 | |
| beierlm | 32862bb | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 44 | class MethodNotImplemented(Exception): |
| Adam Israel | 9e5eddb | 2019-12-01 12:55:09 -0500 | [diff] [blame] | 45 | """The method is not implemented.""" |
| 46 | |
| 47 | |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 48 | class N2VCException(Exception): |
| 49 | """ |
| 50 | N2VC exception base class |
| 51 | """ |
| 52 | |
| beierlm | 32862bb | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 53 | def __init__(self, message: str = ""): |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 54 | Exception.__init__(self, message) |
| 55 | self.message = message |
| 56 | |
| 57 | def __str__(self): |
| 58 | return self.message |
| 59 | |
| 60 | def __repr__(self): |
| beierlm | 32862bb | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 61 | return "{}({})".format(type(self), self.message) |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 62 | |
| 63 | |
| 64 | class N2VCBadArgumentsException(N2VCException): |
| 65 | """ |
| 66 | Bad argument values exception |
| 67 | """ |
| 68 | |
| beierlm | 32862bb | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 69 | def __init__(self, message: str = "", bad_args: list = None): |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 70 | N2VCException.__init__(self, message=message) |
| 71 | self.bad_args = bad_args |
| 72 | |
| 73 | def __str__(self): |
| beierlm | 32862bb | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 74 | return "<{}> Bad arguments: {} -> {}".format( |
| 75 | type(self), super().__str__(), self.bad_args |
| 76 | ) |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 77 | |
| 78 | |
| 79 | class N2VCConnectionException(N2VCException): |
| 80 | """ |
| 81 | Error connecting to VCA |
| 82 | """ |
| 83 | |
| beierlm | 32862bb | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 84 | def __init__(self, message: str = "", url: str = None): |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 85 | N2VCException.__init__(self, message=message) |
| 86 | self.url = url |
| 87 | |
| 88 | def __str__(self): |
| beierlm | 32862bb | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 89 | return "<{}> Connection to {} failed: {}".format( |
| 90 | type(self), self.url, super().__str__() |
| 91 | ) |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 92 | |
| 93 | |
| 94 | class N2VCTimeoutException(N2VCException): |
| 95 | """ |
| 96 | Timeout |
| 97 | """ |
| 98 | |
| beierlm | 32862bb | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 99 | def __init__(self, message: str = "", timeout: str = ""): |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 100 | N2VCException.__init__(self, message=message) |
| 101 | self.timeout = timeout |
| 102 | |
| 103 | def __str__(self): |
| beierlm | 32862bb | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 104 | return "<{}> {} timeout: {}".format(type(self), self.timeout, super().__str__()) |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 105 | |
| 106 | |
| 107 | class N2VCExecutionException(N2VCException): |
| 108 | """ |
| 109 | Error executing primitive |
| 110 | """ |
| 111 | |
| beierlm | 32862bb | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 112 | def __init__(self, message: str = "", primitive_name: str = ""): |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 113 | N2VCException.__init__(self, message=message) |
| 114 | self.primitive_name = primitive_name |
| 115 | |
| 116 | def __str__(self): |
| beierlm | 32862bb | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 117 | return "<{}> Error executing primitive {} failed: {}".format( |
| 118 | type(self), self.primitive_name, super().__str__() |
| 119 | ) |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 120 | |
| Adam Israel | 9e5eddb | 2019-12-01 12:55:09 -0500 | [diff] [blame] | 121 | |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 122 | class N2VCInvalidCertificate(N2VCException): |
| 123 | """ |
| 124 | Invalid certificate |
| 125 | """ |
| 126 | |
| beierlm | 32862bb | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 127 | def __init__(self, message: str = ""): |
| quilesj | 2911434 | 2019-10-29 09:30:44 +0100 | [diff] [blame] | 128 | N2VCException.__init__(self, message=message) |
| 129 | |
| 130 | def __str__(self): |
| beierlm | 32862bb | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 131 | return "<{}> Invalid certificate: {}".format(type(self), super().__str__()) |
| quilesj | a674841 | 2019-12-04 07:51:26 +0000 | [diff] [blame] | 132 | |
| 133 | |
| David Garcia | 84861ad | 2020-04-08 09:48:21 +0200 | [diff] [blame] | 134 | class N2VCNotFound(N2VCException): |
| 135 | """ |
| 136 | Not found |
| 137 | """ |
| 138 | |
| beierlm | 32862bb | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 139 | def __init__(self, message: str = ""): |
| David Garcia | 84861ad | 2020-04-08 09:48:21 +0200 | [diff] [blame] | 140 | N2VCException.__init__(self, message=message) |
| 141 | |
| 142 | def __str__(self): |
| beierlm | 32862bb | 2020-04-21 16:36:35 -0400 | [diff] [blame] | 143 | return "<{}> Not found: {}".format(type(self), super().__str__()) |
| David Garcia | 84861ad | 2020-04-08 09:48:21 +0200 | [diff] [blame] | 144 | |
| 145 | |
| quilesj | a674841 | 2019-12-04 07:51:26 +0000 | [diff] [blame] | 146 | class K8sException(Exception): |
| 147 | """ |
| 148 | K8s exception |
| 149 | """ |
| 150 | |
| 151 | def __init__(self, message: str): |
| 152 | Exception.__init__(self, message) |
| 153 | self._message = message |
| 154 | |
| 155 | def __str__(self): |
| 156 | return self._message |
| 157 | |
| 158 | def __repr__(self): |
| 159 | return self._message |