X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Futil%2Ffaults.py;h=ea62bad2f0abd25f9c798fae63407cb8a46f6a93;hb=04a3f20dc71bf8b3f96b1e3172623aa346a638a7;hp=b8dee9e3aef55a0807d6f2849ca3669153dbc7db;hpb=151ecb656399f0b67e10ced88e2c3867e764857a;p=sfa.git diff --git a/sfa/util/faults.py b/sfa/util/faults.py index b8dee9e3..ea62bad2 100644 --- a/sfa/util/faults.py +++ b/sfa/util/faults.py @@ -1,248 +1,493 @@ +#---------------------------------------------------------------------- +# Copyright (c) 2008 Board of Trustees, Princeton University # -# GeniAPI XML-RPC faults +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and/or hardware specification (the "Work") to +# deal in the Work without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Work, and to permit persons to whom the Work +# is furnished to do so, subject to the following conditions: # +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Work. # +# THE WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS +# IN THE WORK. +#---------------------------------------------------------------------- +# +# SFA API faults +# + +from sfa.util.genicode import GENICODE +from sfa.util.py23 import xmlrpc_client -### $Id$ -### $URL$ -import xmlrpclib +class SfaFault(xmlrpc_client.Fault): -class GeniFault(xmlrpclib.Fault): - def __init__(self, faultCode, faultString, extra = None): + def __init__(self, faultCode, faultString, extra=None): if extra: - faultString += ": " + extra - xmlrpclib.Fault.__init__(self, faultCode, faultString) + faultString += ": " + str(extra) + xmlrpc_client.Fault.__init__(self, faultCode, faultString) + + +class Forbidden(SfaFault): + + def __init__(self, extra=None): + faultString = "FORBIDDEN" + SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra) + + +class BadArgs(SfaFault): + + def __init__(self, extra=None): + faultString = "BADARGS" + SfaFault.__init__(self, GENICODE.BADARGS, faultString, extra) + + +class CredentialMismatch(SfaFault): + + def __init__(self, extra=None): + faultString = "Credential mismatch" + SfaFault.__init__(self, GENICODE.CREDENTIAL_MISMATCH, + faultString, extra) -class GeniInvalidAPIMethod(GeniFault): - def __init__(self, method, interface = None, extra = None): + +class SfaInvalidAPIMethod(SfaFault): + + def __init__(self, method, interface=None, extra=None): faultString = "Invalid method " + method if interface: faultString += " for interface " + interface - GeniFault.__init__(self, 100, faultString, extra) + SfaFault.__init__(self, GENICODE.UNSUPPORTED, faultString, extra) + -class GeniInvalidArgumentCount(GeniFault): - def __init__(self, got, min, max = min, extra = None): +class SfaInvalidArgumentCount(SfaFault): + + def __init__(self, got, min, max=min, extra=None): if min != max: expected = "%d-%d" % (min, max) else: expected = "%d" % min faultString = "Expected %s arguments, got %d" % \ (expected, got) - GeniFault.__init__(self, 101, faultString, extra) + SfaFault.__init__(self, GENICODE.BADARGS, faultString, extra) + + +class SfaInvalidArgument(SfaFault): -class GeniInvalidArgument(GeniFault): - def __init__(self, extra = None, name = None): + def __init__(self, extra=None, name=None): if name is not None: faultString = "Invalid %s value" % name else: faultString = "Invalid argument" - GeniFault.__init__(self, 102, faultString, extra) + SfaFault.__init__(self, GENICODE.BADARGS, faultString, extra) -class GeniAuthenticationFailure(GeniFault): - def __init__(self, extra = None): + +class SfaAuthenticationFailure(SfaFault): + + def __init__(self, extra=None): faultString = "Failed to authenticate call" - GeniFault.__init__(self, 103, faultString, extra) + SfaFault.__init__(self, GENICODE.ERROR, faultString, extra) + -class GeniDBError(GeniFault): - def __init__(self, extra = None): +class SfaDBError(SfaFault): + + def __init__(self, extra=None): faultString = "Database error" - GeniFault.__init__(self, 106, faultString, extra) + SfaFault.__init__(self, GENICODE.DBERROR, faultString, extra) + -class GeniPermissionDenied(GeniFault): - def __init__(self, extra = None): +class SfaPermissionDenied(SfaFault): + + def __init__(self, extra=None): faultString = "Permission denied" - GeniFault.__init__(self, 108, faultString, extra) + SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra) + + +class SfaNotImplemented(SfaFault): + + def __init__(self, interface=None, extra=None): + faultString = "Not implemented" + if interface: + faultString += " at interface " + interface + SfaFault.__init__(self, GENICODE.UNSUPPORTED, faultString, extra) + -class GeniNotImplemented(GeniFault): - def __init__(self, extra = None): - faultString = "Not fully implemented" - GeniFault.__init__(self, 109, faultString, extra) +class SfaAPIError(SfaFault): -class GeniAPIError(GeniFault): - def __init__(self, extra = None): - faultString = "Internal API error" - GeniFault.__init__(self, 111, faultString, extra) + def __init__(self, extra=None): + faultString = "Internal SFA API error" + SfaFault.__init__(self, GENICODE.SERVERERROR, faultString, extra) -class MalformedHrnException(GeniFault): - def __init__(self, value, extra = None): + +class MalformedHrnException(SfaFault): + + def __init__(self, value, extra=None): self.value = value faultString = "Malformed HRN: %(value)s" % locals() - GeniFault.__init__(self, 102, faultString, extra) + SfaFault.__init__(self, GENICODE.ERROR, extra) + def __str__(self): return repr(self.value) -class TreeException(GeniFault): - def __init__(self, value, extra = None): + +class TreeException(SfaFault): + + def __init__(self, value, extra=None): self.value = value faultString = "Tree Exception: %(value)s, " % locals() - GeniFault.__init__(self, 111, faultString, extra) - def __str__(self): - return repr(self.value) + SfaFault.__init__(self, GENICODE.ERROR, faultString, extra) -class NonexistingRecord(GeniFault): - def __init__(self, value, extra = None): - self.value = value - faultString = "Non exsiting record %(value)s, " % locals() - GeniFault.__init__(self, 111, faultString, extra) def __str__(self): return repr(self.value) -class ExistingRecord(GeniFault): - def __init__(self, value, extra = None): + +class SearchFailed(SfaFault): + + def __init__(self, value, extra=None): self.value = value - faultString = "Existing record: %(value)s, " % locals() - GeniFault.__init__(self, 111, faultString, extra) + faultString = "%s does not exist here " % self.value + SfaFault.__init__(self, GENICODE.SEARCHFAILED, faultString, extra) + def __str__(self): return repr(self.value) - -class NonexistingCredType(GeniFault): - def __init__(self, value, extra = None): + + +class NonExistingRecord(SfaFault): + + def __init__(self, value, extra=None): self.value = value - faultString = "Non existing record: %(value)s, " % locals() - GeniFault.__init__(self, 111, faultString, extra) + faultString = "Non exsiting record %(value)s, " % locals() + SfaFault.__init__(self, GENICODE.SEARCHFAILED, faultString, extra) + def __str__(self): return repr(self.value) -class NonexistingFile(GeniFault): - def __init__(self, value): + +class ExistingRecord(SfaFault): + + def __init__(self, value, extra=None): self.value = value - faultString = "Non existing file: %(value)s, " % locals() - GeniFault.__init__(self, 111, faultString, extra) + faultString = "Existing record: %(value)s, " % locals() + SfaFault.__init__(self, GENICODE.REFUSED, faultString, extra) + def __str__(self): return repr(self.value) -class InvalidRPCParams(GeniFault): - def __init__(self, value): + +class InvalidRPCParams(SfaFault): + + def __init__(self, value, extra=None): self.value = value faultString = "Invalid RPC Params: %(value)s, " % locals() - GeniFault.__init__(self, 102, faultString, extra) + SfaFault.__init__(self, GENICODE.RPCERROR, faultString, extra) + def __str__(self): return repr(self.value) # SMBAKER exceptions follow -class ConnectionKeyGIDMismatch(GeniFault): - def __init__(self, value, extra = None): + +class ConnectionKeyGIDMismatch(SfaFault): + + def __init__(self, value, extra=None): self.value = value faultString = "Connection Key GID mismatch: %(value)s" % locals() - GeniFault.__init__(self, 102, faultString, extra) + SfaFault.__init__(self, GENICODE.ERROR, faultString, extra) + def __str__(self): return repr(self.value) -class MissingCallerGID(GeniFault): - def __init__(self, value, extra = None): + +class MissingCallerGID(SfaFault): + + def __init__(self, value, extra=None): self.value = value faultString = "Missing Caller GID: %(value)s" % locals() - GeniFault.__init__(self, 102, faultString, extra) + SfaFault.__init__(self, GENICODE.ERROR, faultString, extra) + def __str__(self): return repr(self.value) -class RecordNotFound(GeniFault): - def __init__(self, value, extra = None): + +class RecordNotFound(SfaFault): + + def __init__(self, value, extra=None): self.value = value faultString = "Record not found: %(value)s" % locals() - GeniFault.__init__(self, 102, faultString, extra) - #def __str__(self): - # return repr(self.value) + SfaFault.__init__(self, GENICODE.ERROR, faultString, extra) + + def __str__(self): + return repr(self.value) + + +class UnknownSfaType(SfaFault): -class UnknownGeniType(GeniFault): - def __init__(self, value, extra = None): + def __init__(self, value, extra=None): self.value = value - faultString = "Unknown Geni Type: %(value)s" % locals() - GeniFault.__init__(self, 102, faultString, extra) + faultString = "Unknown SFA Type: %(value)s" % locals() + SfaFault.__init__(self, GENICODE.ERROR, faultString, extra) + def __str__(self): return repr(self.value) -class MissingAuthority(GeniFault): - def __init__(self, value, extra = None): + +class MissingAuthority(SfaFault): + + def __init__(self, value, extra=None): self.value = value faultString = "Missing authority: %(value)s" % locals() - GeniFault.__init__(self, 102, faultString, extra) + SfaFault.__init__(self, GENICODE.ERROR, faultString, extra) + def __str__(self): return repr(self.value) -class PlanetLabRecordDoesNotExist(GeniFault): - def __init__(self, value, extra = None): + +class PlanetLabRecordDoesNotExist(SfaFault): + + def __init__(self, value, extra=None): self.value = value faultString = "PlanetLab record does not exist : %(value)s" % locals() - GeniFault.__init__(self, 102, faultString, extra) + SfaFault.__init__(self, GENICODE.ERROR, faultString, extra) + def __str__(self): return repr(self.value) -class PermissionError(GeniFault): - def __init__(self, value, extra = None): + +class PermissionError(SfaFault): + + def __init__(self, value, extra=None): self.value = value faultString = "Permission error: %(value)s" % locals() - GeniFault.__init__(self, 108, faultString, extra) + SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra) + def __str__(self): return repr(self.value) -class InsufficientRights(GeniFault): - def __init__(self, value, extra = None): + +class InsufficientRights(SfaFault): + + def __init__(self, value, extra=None): self.value = value faultString = "Insufficient rights: %(value)s" % locals() - GeniFault.__init__(self, 108, faultString, extra) + SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra) + def __str__(self): return repr(self.value) -class MissingDelegateBit(GeniFault): - def __init__(self, value, extra = None): + +class MissingDelegateBit(SfaFault): + + def __init__(self, value, extra=None): self.value = value faultString = "Missing delegate bit: %(value)s" % locals() - GeniFault.__init__(self, 108, faultString, extra) + SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra) + def __str__(self): return repr(self.value) -class ChildRightsNotSubsetOfParent(GeniFault): - def __init__(self, value, extra = None): + +class ChildRightsNotSubsetOfParent(SfaFault): + + def __init__(self, value, extra=None): self.value = value faultString = "Child rights not subset of parent: %(value)s" % locals() - GeniFault.__init__(self, 103, faultString, extra) + SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra) + def __str__(self): return repr(self.value) -class CertMissingParent(GeniFault): - def __init__(self, value, extra = None): + +class CertMissingParent(SfaFault): + + def __init__(self, value, extra=None): self.value = value faultString = "Cert missing parent: %(value)s" % locals() - GeniFault.__init__(self, 103, faultString, extra) + SfaFault.__init__(self, GENICODE.ERROR, faultString, extra) + def __str__(self): return repr(self.value) -class CertNotSignedByParent(GeniFault): - def __init__(self, value, extra = None): + +class CertNotSignedByParent(SfaFault): + + def __init__(self, value, extra=None): self.value = value faultString = "Cert not signed by parent: %(value)s" % locals() - GeniFault.__init__(self, 103, faultString, extra) + SfaFault.__init__(self, GENICODE.ERROR, faultString, extra) + def __str__(self): return repr(self.value) -class GidInvalidParentHrn(GeniFault): - def __init__(self, value, extra = None): + +class GidParentHrn(SfaFault): + + def __init__(self, value, extra=None): + self.value = value + faultString = "Cert URN is not an extension of its parent: %(value)s" % locals( + ) + SfaFault.__init__(self, GENICODE.ERROR, faultString, extra) + + def __str__(self): + return repr(self.value) + + +class GidInvalidParentHrn(SfaFault): + + def __init__(self, value, extra=None): self.value = value faultString = "GID invalid parent hrn: %(value)s" % locals() - GeniFault.__init__(self, 102, faultString, extra) + SfaFault.__init__(self, GENICODE.ERROR, faultString, extra) + def __str__(self): return repr(self.value) -class SliverDoesNotExist(GeniFault): - def __init__(self, value, extra = None): + +class SliverDoesNotExist(SfaFault): + + def __init__(self, value, extra=None): self.value = value faultString = "Sliver does not exist : %(value)s" % locals() - GeniFault.__init__(self, 102, faultString, extra) + SfaFault.__init__(self, GENICODE.ERROR, faultString, extra) + def __str__(self): return repr(self.value) -class BadRequestHash(xmlrpclib.Fault): - def __init__(self, hash = None): + +class BadRequestHash(xmlrpc_client.Fault): + + def __init__(self, hash=None, extra=None): faultString = "bad request hash: " + str(hash) - xmlrpclib.Fault.__init__(self, 902, faultString) + xmlrpc_client.Fault.__init__(self, GENICODE.ERROR, faultString) + + +class MissingTrustedRoots(SfaFault): + + def __init__(self, value, extra=None): + self.value = value + faultString = "Trusted root directory does not exist: %(value)s" % locals( + ) + SfaFault.__init__(self, GENICODE.SERVERERROR, faultString, extra) + + def __str__(self): + return repr(self.value) + + +class MissingSfaInfo(SfaFault): + + def __init__(self, value, extra=None): + self.value = value + faultString = "Missing information: %(value)s" % locals() + SfaFault.__init__(self, GENICODE.ERROR, faultString, extra) + + def __str__(self): + return repr(self.value) + + +class InvalidRSpec(SfaFault): + + def __init__(self, value, extra=None): + self.value = value + faultString = "Invalid RSpec: %(value)s" % locals() + SfaFault.__init__(self, GENICODE.ERROR, faultString, extra) + + def __str__(self): + return repr(self.value) + + +class InvalidRSpecVersion(SfaFault): + + def __init__(self, value, extra=None): + self.value = value + faultString = "Invalid RSpec version: %(value)s" % locals() + SfaFault.__init__(self, GENICODE.BADVERSION, faultString, extra) + + def __str__(self): + return repr(self.value) + + +class UnsupportedRSpecVersion(SfaFault): + + def __init__(self, value, extra=None): + self.value = value + faultString = "Unsupported RSpec version: %(value)s" % locals() + SfaFault.__init__(self, GENICODE.UNSUPPORTED, faultString, extra) + + def __str__(self): + return repr(self.value) + + +class InvalidRSpecElement(SfaFault): + + def __init__(self, value, extra=None): + self.value = value + faultString = "Invalid RSpec Element: %(value)s" % locals() + SfaFault.__init__(self, GENICODE.ERROR, faultString, extra) + + def __str__(self): + return repr(self.value) + + +class InvalidXML(SfaFault): + + def __init__(self, value, extra=None): + self.value = value + faultString = "Invalid XML Document: %(value)s" % locals() + SfaFault.__init__(self, GENICODE.BADARGS, faultString, extra) + + def __str__(self): + return repr(self.value) + + +class AccountNotEnabled(SfaFault): -class MissingTrustedRoots(GeniFault): - def __init__(self, value, extra = None): + def __init__(self, extra=None): + faultString = "Account Disabled" + SfaFault.__init__(self, GENICODE.ERROR, faultString, extra) + + def __str__(self): + return repr(self.value) + + +class CredentialNotVerifiable(SfaFault): + + def __init__(self, value=None, extra=None): self.value = value - faultString = "Trusted root directory does not exist: %(value)s" % locals() - GeniFault.__init__(self, 102, faultString, extra) + faultString = "Unable to verify credential" % locals() + if value: + faultString += ": %s" % value + faultString += ", " + SfaFault.__init__(self, GENICODE.BADARGS, faultString, extra) + def __str__(self): return repr(self.value) + + +class CertExpired(SfaFault): + + def __init__(self, value, extra=None): + self.value = value + faultString = "%s cert is expired" % value + SfaFault.__init__(self, GENICODE.ERROR, faultString, extra) + + +class SfatablesRejected(SfaFault): + + def __init__(self, value, extra=None): + self.value = value + faultString = "%s rejected by sfatables" + SfaFault.__init__(self, GENICODE.FORBIDDEN, faultString, extra) + + +class UnsupportedOperation(SfaFault): + + def __init__(self, value, extra=None): + self.value = value + faultString = "Unsupported operation: %s" % value + SfaFault.__init__(self, GENICODE.UNSUPPORTED, faultString, extra)