Files
python-blazarclient/blazarclient/exception.py
Hiroki Ito 2afa290302 Restore backward compatibility for init client
After merged the patch I08c8b753972c27b4e6bbe07a8aa51e0e72fbc56d,
blazarclient can't be used with blazar_url and auth_token since this
patch only allows sessions for the initiation of client.
For backward compatibility, blazarclient should be initiated with
blazar_url and auth_token as before.

This patch enables using blazarclient with a set of blazar_url and
auth_token or session by reviving BaseClientManager class with adding
a logic to chose an auth method based on given params.

Change-Id: I25a665145b0503cc04e49bc85c39e2f6dca36925
Closes-Bug: #1724757
2017-11-17 07:48:38 +00:00

93 lines
2.8 KiB
Python

# Copyright (c) 2013 Mirantis Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from blazarclient.i18n import _
class BlazarClientException(Exception):
"""Base exception class."""
message = _("An unknown exception occurred %s.")
code = 500
def __init__(self, message=None, **kwargs):
self.kwargs = kwargs
if 'code' not in self.kwargs:
try:
self.kwargs['code'] = self.code
except AttributeError:
pass
if not message:
message = self.message % kwargs
super(BlazarClientException, self).__init__(message)
class CommandError(BlazarClientException):
"""Occurs if not all authentication vital options are set."""
message = _("You have to provide all options like user name or tenant "
"id to make authentication possible.")
code = 401
class NotAuthorized(BlazarClientException):
"""HTTP 401 - Not authorized.
User have no enough rights to perform action.
"""
code = 401
message = _("Not authorized request.")
class NoBlazarEndpoint(BlazarClientException):
"""Occurs if no endpoint for Blazar set in the Keystone."""
message = _("No publicURL endpoint for Blazar found. Set endpoint "
"for Blazar in the Keystone.")
code = 404
class NoUniqueMatch(BlazarClientException):
"""Occurs if there are more than one appropriate resources."""
message = _("There is no unique requested resource.")
code = 409
class UnsupportedVersion(BlazarClientException):
"""Occurs if unsupported client version was requested."""
message = _("Unsupported client version requested.")
code = 406
class IncorrectLease(BlazarClientException):
"""Occurs if lease parameters are incorrect."""
message = _("The lease parameters are incorrect.")
code = 409
class DuplicatedLeaseParameters(BlazarClientException):
"""Occurs if lease parameters are duplicated."""
message = _("The lease parameters are duplicated.")
code = 400
class InsufficientAuthInfomation(BlazarClientException):
"""Occurs if the auth info passed to blazar client is insufficient."""
message = _("The passed arguments are insufficient "
"for the authentication. The instance of "
"keystoneauth1.session.Session class is required.")
code = 400