Skip to content

Commit 6c269ef

Browse files
author
Dean Troyer
committed
Use osc-lib and set up deprecation warnings
The initial use of osc-lib is behind the compatibility/deprecation modules that we will leave in place for a time for plugins to catch up. * openstackclient.common.exceptions * openstackclient.common.utils Module-level warnings are emitted directly on stderr since logging has not been configured yet. Change-Id: I79e57ce9523a20366bccaf9b949ab5906792ea0d
1 parent df71ae8 commit 6c269ef

3 files changed

Lines changed: 17 additions & 520 deletions

File tree

Lines changed: 8 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Copyright 2012-2013 OpenStack, LLC.
2-
#
31
# Licensed under the Apache License, Version 2.0 (the "License"); you may
42
# not use this file except in compliance with the License. You may obtain
53
# a copy of the License at
@@ -13,105 +11,15 @@
1311
# under the License.
1412
#
1513

16-
"""Exception definitions."""
17-
18-
19-
class CommandError(Exception):
20-
pass
21-
22-
23-
class AuthorizationFailure(Exception):
24-
pass
25-
26-
27-
class PluginAttributeError(Exception):
28-
"""A plugin threw an AttributeError while being lazily loaded."""
29-
# This *must not* inherit from AttributeError;
30-
# that would defeat the whole purpose.
31-
pass
32-
33-
34-
class NoTokenLookupException(Exception):
35-
"""This does not support looking up endpoints from an existing token."""
36-
pass
37-
38-
39-
class EndpointNotFound(Exception):
40-
"""Could not find Service or Region in Service Catalog."""
41-
pass
42-
43-
44-
class UnsupportedVersion(Exception):
45-
"""The user is trying to use an unsupported version of the API"""
46-
pass
47-
48-
49-
class ClientException(Exception):
50-
"""The base exception class for all exceptions this library raises."""
14+
# NOTE(dtroyer): This file is deprecated in Jun 2016, remove after 4.x release
15+
# or Jun 2017.
5116

52-
def __init__(self, code, message=None, details=None):
53-
self.code = code
54-
self.message = message or self.__class__.message
55-
self.details = details
17+
import sys
5618

57-
def __str__(self):
58-
return "%s (HTTP %s)" % (self.message, self.code)
19+
from osc_lib.exceptions import * # noqa
5920

6021

61-
class BadRequest(ClientException):
62-
"""HTTP 400 - Bad request: you sent some malformed data."""
63-
http_status = 400
64-
message = "Bad request"
65-
66-
67-
class Unauthorized(ClientException):
68-
"""HTTP 401 - Unauthorized: bad credentials."""
69-
http_status = 401
70-
message = "Unauthorized"
71-
72-
73-
class Forbidden(ClientException):
74-
"""HTTP 403 - Forbidden: not authorized to access to this resource."""
75-
http_status = 403
76-
message = "Forbidden"
77-
78-
79-
class NotFound(ClientException):
80-
"""HTTP 404 - Not found"""
81-
http_status = 404
82-
message = "Not found"
83-
84-
85-
class Conflict(ClientException):
86-
"""HTTP 409 - Conflict"""
87-
http_status = 409
88-
message = "Conflict"
89-
90-
91-
class OverLimit(ClientException):
92-
"""HTTP 413 - Over limit: reached the API limits for this time period."""
93-
http_status = 413
94-
message = "Over limit"
95-
96-
97-
# NotImplemented is a python keyword.
98-
class HTTPNotImplemented(ClientException):
99-
"""HTTP 501 - Not Implemented: server does not support this operation."""
100-
http_status = 501
101-
message = "Not Implemented"
102-
103-
104-
# In Python 2.4 Exception is old-style and thus doesn't have a __subclasses__()
105-
# so we can do this:
106-
# _code_map = dict((c.http_status, c)
107-
# for c in ClientException.__subclasses__())
108-
#
109-
# Instead, we have to hardcode it:
110-
_code_map = dict((c.http_status, c) for c in [
111-
BadRequest,
112-
Unauthorized,
113-
Forbidden,
114-
NotFound,
115-
OverLimit,
116-
HTTPNotImplemented
117-
])
22+
sys.stderr.write(
23+
"WARNING: %s is deprecated and will be removed after Jun 2017. "
24+
"Please use osc_lib.exceptions\n" % __name__
25+
)

0 commit comments

Comments
 (0)