diff --git a/magnum/api/controllers/v1/bay.py b/magnum/api/controllers/v1/bay.py index 00b72187b0..9d9d4ac5d3 100644 --- a/magnum/api/controllers/v1/bay.py +++ b/magnum/api/controllers/v1/bay.py @@ -55,13 +55,13 @@ class Bay(base.APIBase): # FIXME(comstud): One should only allow UUID here, but # there seems to be a bug in that tests are passing an # ID. See bug #1301046 for more details. - bay = objects.Node.get(pecan.request.context, value) + bay = objects.Bay.get(pecan.request.context, value) self._bay_uuid = bay.uuid # NOTE(lucasagomes): Create the bay_id attribute on-the-fly # to satisfy the api -> rpc object # conversion. self.bay_id = bay.id - except exception.NodeNotFound as e: + except exception.BayNotFound as e: # Change error code because 404 (NotFound) is inappropriate # response for a POST request to create a Bay e.code = 400 # BadRequest @@ -164,7 +164,7 @@ class BaysController(rest.RestController): from_bays = False """A flag to indicate if the requests to this controller are coming - from the top-level resource Nodes.""" + from the top-level resource Bays.""" _custom_actions = { 'detail': ['GET'], diff --git a/magnum/api/controllers/v1/container.py b/magnum/api/controllers/v1/container.py index 2a0fb2e916..ce6c976cbd 100644 --- a/magnum/api/controllers/v1/container.py +++ b/magnum/api/controllers/v1/container.py @@ -56,12 +56,12 @@ class Container(base.APIBase): # FIXME(comstud): One should only allow UUID here, but # there seems to be a bug in that tests are passing an # ID. See bug #1301046 for more details. - container = objects.Node.get(pecan.request.context, value) + container = objects.Container.get(pecan.request.context, value) self._container_uuid = container.uuid # NOTE(lucasagomes): Create the container_id attribute # on-the-fly to satisfy the api -> rpc object conversion. self.container_id = container.id - except exception.NodeNotFound as e: + except exception.BayNotFound as e: # Change error code because 404 (NotFound) is inappropriate # response for a POST request to create a Container e.code = 400 # BadRequest @@ -301,7 +301,7 @@ class ContainersController(rest.RestController): if rpc_container[field] != patch_val: rpc_container[field] = patch_val - rpc_container = objects.Node.get_by_id(pecan.request.context, + rpc_container = objects.Container.get_by_id(pecan.request.context, rpc_container.container_id) topic = pecan.request.rpcapi.get_topic_for(rpc_container) diff --git a/magnum/common/exception.py b/magnum/common/exception.py index c8ec3a21f5..d43ac5141e 100644 --- a/magnum/common/exception.py +++ b/magnum/common/exception.py @@ -237,4 +237,174 @@ class ResourceExists(ObjectNotUnique): class AuthorizationFailure(MagnumException): - msg_fmt = _("%(client)s connection failed. %(message)s") \ No newline at end of file + msg_fmt = _("%(client)s connection failed. %(message)s") + + +class UnsupportedObjectError(MagnumException): + message = _('Unsupported object type %(objtype)s') + + +class IncompatibleObjectVersion(MagnumException): + message = _('Version %(objver)s of %(objname)s is not supported') + + +class OrphanedObjectError(MagnumException): + message = _('Cannot call %(method)s on orphaned %(objtype)s object') + + +class Invalid(MagnumException): + message = _("Unacceptable parameters.") + code = 400 + + +class InvalidUUID(Invalid): + message = _("Expected a uuid but received %(uuid)s.") + + +class InvalidIdentity(Invalid): + message = _("Expected an uuid or int but received %(identity)s.") + + +class HTTPNotFound(ResourceNotFound): + pass + + +class Conflict(MagnumException): + message = _('Conflict.') + code = 409 + + +class Invalid(MagnumException): + message = _("Unacceptable parameters.") + code = 400 + + +class InvalidState(Conflict): + message = _("Invalid resource state.") + + +# Cannot be templated as the error syntax varies. +# msg needs to be constructed when raised. +class InvalidParameterValue(Invalid): + message = _("%(err)s") + + +class InstanceAssociated(Conflict): + message = _("Instance %(instance_uuid)s is already associated with a node," + " it cannot be associated with this other node %(node)s") + + +class InstanceNotFound(ResourceNotFound): + message = _("Instance %(instance)s could not be found.") + + +class PatchError(Invalid): + message = _("Couldn't apply patch '%(patch)s'. Reason: %(reason)s") + + +class NotAuthorized(MagnumException): + message = _("Not authorized.") + code = 403 + + +class OperationNotPermitted(NotAuthorized): + message = _("Operation not permitted.") + + +class InvalidMAC(Invalid): + message = _("Expected a MAC address but received %(mac)s.") + + +class SSHConnectFailed(MagnumException): + message = _("Failed to establish SSH connection to host %(host)s.") + + +class FileSystemNotSupported(MagnumException): + message = _("Failed to create a file system. " + "File system %(fs)s is not supported.") + + +class BayNotFound(ResourceNotFound): + message = _("Bay %(bay)s could not be found.") + + +class BayAssociated(InvalidState): + message = _("Bay %(bay)s is associated with instance %(instance)s.") + + +class BayAlreadyExists(Conflict): + message = _("A node with UUID %(uuid)s already exists.") + + +class BayLocked(Conflict): + message = _("Bay %(bay)s is locked by host %(host)s, please retry " + "after the current operation is completed.") + + +class BayNotLocked(Invalid): + message = _("Bay %(bay)s found not to be locked on release") + + +class ContainerNotFound(ResourceNotFound): + message = _("Container %(container)s could not be found.") + + +class ContainerAssociated(InvalidState): + message = _("Container %(container)s is associated with " + "instance %(instance)s.") + + +class ContainerAlreadyExists(Conflict): + message = _("A node with UUID %(uuid)s already exists.") + + +class ContainerLocked(Conflict): + message = _("Container %(container)s is locked by host %(host)s, " + "please retry after the current operation is completed.") + + +class ContainerNotLocked(Invalid): + message = _("Container %(container)s found not to be locked on release") + + +class PodNotFound(ResourceNotFound): + message = _("Pod %(pod)s could not be found.") + + +class PodAssociated(InvalidState): + message = _("Pod %(pod)s is associated with instance %(instance)s.") + + +class PodAlreadyExists(Conflict): + message = _("A node with UUID %(uuid)s already exists.") + + +class PodLocked(Conflict): + message = _("Pod %(pod)s is locked by host %(host)s, please retry " + "after the current operation is completed.") + + +class PodNotLocked(Invalid): + message = _("Pod %(pod)s found not to be locked on release") + + +class ServiceNotFound(ResourceNotFound): + message = _("Service %(service)s could not be found.") + + +class ServiceAssociated(InvalidState): + message = _("Service %(service)s is associated with " + "instance %(instance)s.") + + +class ServiceAlreadyExists(Conflict): + message = _("A node with UUID %(uuid)s already exists.") + + +class ServiceLocked(Conflict): + message = _("Service %(service)s is locked by host %(host)s, please retry " + "after the current operation is completed.") + + +class ServiceNotLocked(Invalid): + message = _("Service %(service)s found not to be locked on release")