**** CubicPower OpenStack Study ****
# Copyright 2014 VMware, Inc.
#
# All Rights Reserved
#
# 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.
#
**** CubicPower OpenStack Study ****
class NsxApiException(Exception):
"""Base NSX API Client Exception.
To correctly use this class, inherit from it and
**** CubicPower OpenStack Study ****
def __init__(self, **kwargs):
try:
self._error_string = self.message % kwargs
except Exception:
# at least get the core message out if something happened
self._error_string = self.message
**** CubicPower OpenStack Study ****
def __str__(self):
return self._error_string
**** CubicPower OpenStack Study ****
class UnAuthorizedRequest(NsxApiException):
message = _("Server denied session's authentication credentials.")
**** CubicPower OpenStack Study ****
class ResourceNotFound(NsxApiException):
message = _("An entity referenced in the request was not found.")
**** CubicPower OpenStack Study ****
class Conflict(NsxApiException):
message = _("Request conflicts with configuration on a different "
"entity.")
**** CubicPower OpenStack Study ****
class ServiceUnavailable(NsxApiException):
message = _("Request could not completed because the associated "
"resource could not be reached.")
**** CubicPower OpenStack Study ****
class Forbidden(NsxApiException):
message = _("The request is forbidden from accessing the "
"referenced resource.")
**** CubicPower OpenStack Study ****
class ReadOnlyMode(Forbidden):
message = _("Create/Update actions are forbidden when in read-only mode.")
**** CubicPower OpenStack Study ****
class RequestTimeout(NsxApiException):
message = _("The request has timed out.")
**** CubicPower OpenStack Study ****
class BadRequest(NsxApiException):
message = _("The server is unable to fulfill the request due "
"to a bad syntax")
**** CubicPower OpenStack Study ****
class InvalidSecurityCertificate(BadRequest):
message = _("The backend received an invalid security certificate.")
**** CubicPower OpenStack Study ****
def fourZeroZero(response=None):
if response and "Invalid SecurityCertificate" in response.body:
raise InvalidSecurityCertificate()
raise BadRequest()
**** CubicPower OpenStack Study ****
def fourZeroFour(response=None):
raise ResourceNotFound()
**** CubicPower OpenStack Study ****
def fourZeroNine(response=None):
raise Conflict()
**** CubicPower OpenStack Study ****
def fiveZeroThree(response=None):
raise ServiceUnavailable()
**** CubicPower OpenStack Study ****
def fourZeroThree(response=None):
if 'read-only' in response.body:
raise ReadOnlyMode()
else:
raise Forbidden()
**** CubicPower OpenStack Study ****
def zero(self, response=None):
raise NsxApiException()
ERROR_MAPPINGS = {
400: fourZeroZero,
404: fourZeroFour,
405: zero,
409: fourZeroNine,
503: fiveZeroThree,
403: fourZeroThree,
301: zero,
307: zero,
500: zero,
501: zero,
503: zero
}