From f2559c4c39af60d8704b813ae0e8effa427a73a0 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Sun, 26 May 2013 08:14:30 -0700 Subject: [PATCH] Add MethodNotAllowed and Conflict exception classes It is expected to recieve a 405 or a 409 from Nova, but novaclient presents them as a generic ClientException. This patch adds MethodNotAllowed and Conflict classes to represent these HTTP responses. Change-Id: If89cee04ebd74daaa28ea30b5c57cdc63edc1551 --- novaclient/exceptions.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/novaclient/exceptions.py b/novaclient/exceptions.py index b331c3c01..afea93326 100644 --- a/novaclient/exceptions.py +++ b/novaclient/exceptions.py @@ -116,6 +116,22 @@ class NotFound(ClientException): message = "Not found" +class MethodNotAllowed(ClientException): + """ + HTTP 405 - Method Not Allowed + """ + http_status = 405 + message = "Method Not Allowed" + + +class Conflict(ClientException): + """ + HTTP 409 - Conflict + """ + http_status = 409 + message = "Conflict" + + class OverLimit(ClientException): """ HTTP 413 - Over limit: you're over the API limits for this time period. @@ -147,8 +163,9 @@ class HTTPNotImplemented(ClientException): # for c in ClientException.__subclasses__()) # # Instead, we have to hardcode it: -_code_map = dict((c.http_status, c) for c in [BadRequest, Unauthorized, - Forbidden, NotFound, OverLimit, HTTPNotImplemented]) +_error_classes = [BadRequest, Unauthorized, Forbidden, NotFound, + MethodNotAllowed, Conflict, OverLimit, HTTPNotImplemented] +_code_map = dict((c.http_status, c) for c in _error_classes) def from_response(response, body, url, method=None):