Statistics
| Branch: | Tag: | Revision:

root / astakosclient / astakosclient / errors.py @ d2104099

History | View | Annotate | Download (3.9 kB)

1 f93cc364 Ilias Tsitsimpis
# Copyright (C) 2012, 2013 GRNET S.A. All rights reserved.
2 f93cc364 Ilias Tsitsimpis
#
3 f93cc364 Ilias Tsitsimpis
# Redistribution and use in source and binary forms, with or
4 f93cc364 Ilias Tsitsimpis
# without modification, are permitted provided that the following
5 f93cc364 Ilias Tsitsimpis
# conditions are met:
6 f93cc364 Ilias Tsitsimpis
#
7 f93cc364 Ilias Tsitsimpis
#   1. Redistributions of source code must retain the above
8 f93cc364 Ilias Tsitsimpis
#      copyright notice, this list of conditions and the following
9 f93cc364 Ilias Tsitsimpis
#      disclaimer.
10 f93cc364 Ilias Tsitsimpis
#
11 f93cc364 Ilias Tsitsimpis
#   2. Redistributions in binary form must reproduce the above
12 f93cc364 Ilias Tsitsimpis
#      copyright notice, this list of conditions and the following
13 f93cc364 Ilias Tsitsimpis
#      disclaimer in the documentation and/or other materials
14 f93cc364 Ilias Tsitsimpis
#      provided with the distribution.
15 f93cc364 Ilias Tsitsimpis
#
16 f93cc364 Ilias Tsitsimpis
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 f93cc364 Ilias Tsitsimpis
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 f93cc364 Ilias Tsitsimpis
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 f93cc364 Ilias Tsitsimpis
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 f93cc364 Ilias Tsitsimpis
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 f93cc364 Ilias Tsitsimpis
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 f93cc364 Ilias Tsitsimpis
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 f93cc364 Ilias Tsitsimpis
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 f93cc364 Ilias Tsitsimpis
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 f93cc364 Ilias Tsitsimpis
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 f93cc364 Ilias Tsitsimpis
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 f93cc364 Ilias Tsitsimpis
# POSSIBILITY OF SUCH DAMAGE.
28 f93cc364 Ilias Tsitsimpis
#
29 f93cc364 Ilias Tsitsimpis
# The views and conclusions contained in the software and
30 f93cc364 Ilias Tsitsimpis
# documentation are those of the authors and should not be
31 f93cc364 Ilias Tsitsimpis
# interpreted as representing official policies, either expressed
32 f93cc364 Ilias Tsitsimpis
# or implied, of GRNET S.A.
33 f93cc364 Ilias Tsitsimpis
34 2c9c147e Ilias Tsitsimpis
"""
35 2c9c147e Ilias Tsitsimpis
Astakos Client Exceptions
36 2c9c147e Ilias Tsitsimpis
"""
37 2c9c147e Ilias Tsitsimpis
38 f93cc364 Ilias Tsitsimpis
39 f93cc364 Ilias Tsitsimpis
class AstakosClientException(Exception):
40 2c9c147e Ilias Tsitsimpis
    """Base AstakosClientException Class"""
41 2b40f200 Christos Stavrakakis
    def __init__(self, message='', details='', status=500):
42 f93cc364 Ilias Tsitsimpis
        self.message = message
43 21190887 Ilias Tsitsimpis
        self.details = details
44 21190887 Ilias Tsitsimpis
        if not hasattr(self, 'status'):
45 21190887 Ilias Tsitsimpis
            self.status = status
46 21190887 Ilias Tsitsimpis
        super(AstakosClientException,
47 21190887 Ilias Tsitsimpis
              self).__init__(self.message, self.details, self.status)
48 f93cc364 Ilias Tsitsimpis
49 f93cc364 Ilias Tsitsimpis
50 83f9157b Ilias Tsitsimpis
class BadValue(AstakosClientException):
51 2c9c147e Ilias Tsitsimpis
    """Re-define ValueError Exception under AstakosClientException"""
52 83f9157b Ilias Tsitsimpis
    def __init__(self, details):
53 83f9157b Ilias Tsitsimpis
        message = "ValueError"
54 83f9157b Ilias Tsitsimpis
        super(BadValue, self).__init__(message, details)
55 83f9157b Ilias Tsitsimpis
56 83f9157b Ilias Tsitsimpis
57 0a2a342c Ilias Tsitsimpis
class InvalidResponse(AstakosClientException):
58 2c9c147e Ilias Tsitsimpis
    """Return simplejson parse Exception as AstakosClient one"""
59 0a2a342c Ilias Tsitsimpis
    def __init__(self, message, details):
60 0a2a342c Ilias Tsitsimpis
        super(InvalidResponse, self).__init__(message, details)
61 0a2a342c Ilias Tsitsimpis
62 0a2a342c Ilias Tsitsimpis
63 f93cc364 Ilias Tsitsimpis
class BadRequest(AstakosClientException):
64 2c9c147e Ilias Tsitsimpis
    """BadRequest Exception"""
65 21190887 Ilias Tsitsimpis
    status = 400
66 f93cc364 Ilias Tsitsimpis
67 f93cc364 Ilias Tsitsimpis
68 f93cc364 Ilias Tsitsimpis
class Unauthorized(AstakosClientException):
69 2c9c147e Ilias Tsitsimpis
    """Unauthorized Exception"""
70 21190887 Ilias Tsitsimpis
    status = 401
71 f93cc364 Ilias Tsitsimpis
72 f93cc364 Ilias Tsitsimpis
73 f93cc364 Ilias Tsitsimpis
class Forbidden(AstakosClientException):
74 2c9c147e Ilias Tsitsimpis
    """Forbidden Exception"""
75 21190887 Ilias Tsitsimpis
    status = 403
76 f93cc364 Ilias Tsitsimpis
77 f93cc364 Ilias Tsitsimpis
78 f93cc364 Ilias Tsitsimpis
class NotFound(AstakosClientException):
79 2c9c147e Ilias Tsitsimpis
    """NotFound Exception"""
80 21190887 Ilias Tsitsimpis
    status = 404
81 2377e7c2 Ilias Tsitsimpis
82 2377e7c2 Ilias Tsitsimpis
83 fd420756 Ilias Tsitsimpis
class QuotaLimit(AstakosClientException):
84 2c9c147e Ilias Tsitsimpis
    """QuotaLimit Exception"""
85 fd420756 Ilias Tsitsimpis
    status = 413
86 fd420756 Ilias Tsitsimpis
87 fd420756 Ilias Tsitsimpis
88 794c94e6 Ilias Tsitsimpis
class NoUserName(AstakosClientException):
89 2c9c147e Ilias Tsitsimpis
    """No display name for the given uuid"""
90 2377e7c2 Ilias Tsitsimpis
    def __init__(self, uuid):
91 2377e7c2 Ilias Tsitsimpis
        message = "No display name for the given uuid: %s" % uuid
92 794c94e6 Ilias Tsitsimpis
        super(NoUserName, self).__init__(message)
93 2377e7c2 Ilias Tsitsimpis
94 2377e7c2 Ilias Tsitsimpis
95 2377e7c2 Ilias Tsitsimpis
class NoUUID(AstakosClientException):
96 2c9c147e Ilias Tsitsimpis
    """No uuid for the given display name"""
97 2377e7c2 Ilias Tsitsimpis
    def __init__(self, display_name):
98 2377e7c2 Ilias Tsitsimpis
        message = "No uuid for the given display name: %s" % display_name
99 2377e7c2 Ilias Tsitsimpis
        super(NoUUID, self).__init__(message)
100 2c9c147e Ilias Tsitsimpis
101 2c9c147e Ilias Tsitsimpis
102 2c9c147e Ilias Tsitsimpis
class NoEndpoints(AstakosClientException):
103 2c9c147e Ilias Tsitsimpis
    """No endpoints found matching the criteria given"""
104 2c9c147e Ilias Tsitsimpis
    def __init__(self, ep_name, ep_type, ep_region, ep_version_id):
105 2c9c147e Ilias Tsitsimpis
        message = "No endpoints found matching" + \
106 2c9c147e Ilias Tsitsimpis
                  (", name = %s" % ep_name) if ep_name is not None else "" + \
107 2c9c147e Ilias Tsitsimpis
                  (", type = %s" % ep_type) if ep_type is not None else "" + \
108 2c9c147e Ilias Tsitsimpis
                  (", region = %s" % ep_region) \
109 2c9c147e Ilias Tsitsimpis
                  if ep_region is not None else "" + \
110 2c9c147e Ilias Tsitsimpis
                  (", version_id = %s" % ep_version_id) \
111 2c9c147e Ilias Tsitsimpis
                  if ep_version_id is not None else "."
112 2c9c147e Ilias Tsitsimpis
        super(NoEndpoints, self).__init__(message)