/usr/lib/python3/dist-packages/maasserver/exceptions.py is in python3-django-maas 2.4.0~beta2-6865-gec43e47e6-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | # Copyright 2012-2017 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Exceptions."""
__all__ = [
"ClusterUnavailable",
"MAASException",
"MAASAPIBadRequest",
"MAASAPIException",
"MAASAPINotFound",
"NodeStateViolation",
"NodeGroupMisconfiguration",
"NoScriptsFound",
"IteratorReusedError",
"PowerProblem",
"StaticIPAddressExhaustion",
"StaticIPAddressTypeClash",
"UnresolvableHost",
]
import http.client
import json
from django.core.exceptions import ValidationError
from django.http import (
HttpResponse,
HttpResponseRedirect,
)
class MAASException(Exception):
"""Base class for MAAS' exceptions."""
class CannotDeleteUserException(Exception):
"""User can't be deleted."""
class MAASAPIException(Exception):
"""Base class for MAAS' API exceptions.
:ivar api_error: The HTTP code that should be returned when this error
is raised in the API (defaults to 500: "Internal Server Error").
"""
api_error = int(http.client.INTERNAL_SERVER_ERROR)
def make_http_response(self):
"""Create an :class:`HttpResponse` representing this exception."""
encoding = 'utf-8'
return HttpResponse(
status=self.api_error, content=str(self).encode(encoding),
content_type="text/plain; charset=%s" % encoding)
class MAASAPIBadRequest(MAASAPIException):
api_error = int(http.client.BAD_REQUEST)
class MAASAPINotFound(MAASAPIException):
api_error = int(http.client.NOT_FOUND)
class MAASAPIForbidden(MAASAPIException):
api_error = int(http.client.FORBIDDEN)
class MAASAPIValidationError(MAASAPIBadRequest, ValidationError):
"""A validation error raised during a MAAS API request."""
def make_http_response(self):
"""Create an :class:`HttpResponse` representing this exception."""
content_type = b"application/json"
if hasattr(self, 'error_dict'):
messages = json.dumps(self.message_dict)
elif len(self.messages) == 1:
messages = self.messages[0]
content_type = b"text/plain"
else:
messages = json.dumps(self.messages)
encoding = b'utf-8'
return HttpResponse(
status=self.api_error, content=messages,
content_type=b"%s; charset=%s" % (content_type, encoding))
class Unauthorized(MAASAPIException):
"""HTTP error 401: Unauthorized. Login required."""
api_error = int(http.client.UNAUTHORIZED)
class NodeStateViolation(MAASAPIException):
"""Operation on node not possible given node's current state."""
api_error = int(http.client.CONFLICT)
class NodesNotAvailable(NodeStateViolation):
"""Requested node(s) are not available to be acquired."""
api_error = int(http.client.CONFLICT)
class Redirect(MAASAPIException):
"""Redirect. The exception message is the target URL."""
api_error = int(http.client.FOUND)
def make_http_response(self):
return HttpResponseRedirect(str(self))
class NodeGroupMisconfiguration(MAASAPIException):
"""Node Groups (aka Cluster Controllers) are misconfigured.
This might mean that more than one controller is marked as managing the
same network
"""
api_error = int(http.client.CONFLICT)
class ClusterUnavailable(MAASAPIException):
"""A Cluster Controller is not available for RPC queries."""
api_error = int(http.client.SERVICE_UNAVAILABLE)
class IteratorReusedError(Exception):
"""Raise when a :class:`UseOnceIterator` gets reused."""
class StaticIPAddressExhaustion(MAASAPIException):
"""Raised when no more static IPs are available during allocation."""
api_error = int(http.client.SERVICE_UNAVAILABLE)
class StaticIPAddressUnavailable(MAASAPIException):
"""Raised when a requested IP is not available."""
api_error = int(http.client.NOT_FOUND)
class StaticIPAddressOutOfRange(MAASAPIException):
"""Raised when a requested IP is not in an acceptable range."""
api_error = int(http.client.FORBIDDEN)
class StaticIPAddressTypeClash(MAASAPIException):
"""Raised when trying to allocate an IP for a MAC where one of another
type already exists."""
api_error = int(http.client.CONFLICT)
class StaticIPAlreadyExistsForMACAddress(MAASAPIException):
"""Raised when trying to allocate a static IP for a non-node MAC
where a node with that MAC already exists."""
api_error = int(http.client.CONFLICT)
class StaticIPAddressConflict(MAASAPIException):
"""Raised when trying to allocate a static IP that doesn't belong to
the network the MAC address is connected to."""
api_error = int(http.client.CONFLICT)
class StaticIPAddressForbidden(MAASAPIException):
"""Raised when trying to allocate a static IP that belongs to a
dynamic range."""
api_error = int(http.client.CONFLICT)
class NodeActionError(MAASException):
"""Raised when there is an error performing a NodeAction."""
def __init__(self, error):
# Avoid circular imports.
from maasserver.clusterrpc.utils import (
get_error_message_for_exception)
if isinstance(error, Exception):
super(NodeActionError, self).__init__(
get_error_message_for_exception(error))
else:
super(NodeActionError, self).__init__(error)
class UnresolvableHost(MAASException):
"""Raised when a hostname can't be resolved to an IP address."""
class MissingBootImage(MAASException):
"""Raised when a boot image is expected to exists."""
class PreseedError(MAASException):
"""Raised when issue generating the preseed."""
class PowerProblem(MAASAPIException):
"""Raised when there's a problem with a power operation.
This could be a problem with parameters, a problem with the power
controller, or something else. The exception text will contain more
information.
"""
api_error = int(http.client.SERVICE_UNAVAILABLE)
class PodProblem(MAASAPIException):
"""Raised when there's a problem with a pod operation.
This could be a problem with parameters, a problem with the pod's
controller, or something else. The exception text will contain more
information.
"""
api_error = int(http.client.SERVICE_UNAVAILABLE)
class NoScriptsFound(MAASException):
"""Raised when no Scripts are found based on user input."""
|