From a0e7ad122df9ea4d667ef903b45382a65d750a13 Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Fri, 10 Apr 2009 02:33:24 +0000 Subject: [PATCH] merging GeniFaults from util.faults here --- geni/util/excep.py | 188 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 146 insertions(+), 42 deletions(-) diff --git a/geni/util/excep.py b/geni/util/excep.py index 5a6c99fd..5436178c 100644 --- a/geni/util/excep.py +++ b/geni/util/excep.py @@ -1,129 +1,233 @@ +# +# GeniAPI XML-RPC faults +# +# -class MalformedHrnException(Exception): - def __init__(self, value): +import xmlrpclib + +class GeniFault(xmlrpclib.Fault): + def __init__(self, faultCode, faultString, extra = None): + if extra: + faultString += ": " + extra + xmlrpclib.Fault.__init__(self, faultCode, faultString) + +class GeniInvalidAPIMethod(GeniFault): + def __init__(self, method, role = None, extra = None): + faultString = "Invalid method " + method + if role: + faultString += " for role " + role + GeniFault.__init__(self, 100, faultString, extra) + +class GeniInvalidArgumentCount(GeniFault): + 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) + +class GeniInvalidArgument(GeniFault): + 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) + +class GeniAuthenticationFailure(GeniFault): + def __init__(self, extra = None): + faultString = "Failed to authenticate call" + GeniFault.__init__(self, 103, faultString, extra) + +class GeniDBError(GeniFault): + def __init__(self, extra = None): + faultString = "Database error" + GeniFault.__init__(self, 106, faultString, extra) + +class GeniPermissionDenied(GeniFault): + def __init__(self, extra = None): + faultString = "Permission denied" + GeniFault.__init__(self, 108, faultString, extra) + +class GeniNotImplemented(GeniFault): + def __init__(self, extra = None): + faultString = "Not fully implemented" + GeniFault.__init__(self, 109, faultString, extra) + +class GeniAPIError(GeniFault): + def __init__(self, extra = None): + faultString = "Internal API error" + GeniFault.__init__(self, 111, faultString, extra) + +class MalformedHrnException(GeniFault): + def __init__(self, value, extra = None): self.value = value + faultString = "Malformed HRN: %(value)s" % locals() + GeniFault.__init__(self, 102, faultString, extra) def __str__(self): return repr(self.value) -class TreeException(Exception): - def __init__(self, value): +class TreeException(GeniFault): + 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) -class NonexistingRecord(Exception): - def __init__(self, value): +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(Exception): - def __init__(self, value): +class ExistingRecord(GeniFault): + def __init__(self, value, extra = None): self.value = value + faultString = "Existing record: %(value)s, " % locals() + GeniFault.__init__(self, 111, faultString, extra) def __str__(self): return repr(self.value) -class NonexistingCredType(Exception): - def __init__(self, value): +class NonexistingCredType(GeniFault): + def __init__(self, value, extra = None): self.value = value + faultString = "Non existing record: %(value)s, " % locals() + GeniFault.__init__(self, 111, faultString, extra) def __str__(self): return repr(self.value) -class NonexistingFile(Exception): +class NonexistingFile(GeniFault): def __init__(self, value): self.value = value + faultString = "Non existing file: %(value)s, " % locals() + GeniFault.__init__(self, 111, faultString, extra) def __str__(self): return repr(self.value) -class InvalidRPCParams(Exception): +class InvalidRPCParams(GeniFault): def __init__(self, value): self.value = value + faultString = "Invalid RPC Params: %(value)s, " % locals() + GeniFault.__init__(self, 102, faultString, extra) def __str__(self): return repr(self.value) # SMBAKER exceptions follow -class ConnectionKeyGIDMismatch(Exception): - def __init__(self, value): +class ConnectionKeyGIDMismatch(GeniFault): + def __init__(self, value, extra = None): self.value = value + faultString = "Connection Key GID mismatch: %(value)s" % locals() + GeniFault.__init__(self, 102, faultstring, extra) def __str__(self): return repr(self.value) -class MissingCallerGID(Exception): - def __init__(self, value): +class MissingCallerGID(GeniFault): + def __init__(self, value, extra = None): self.value = value + faultString = "Missing Caller GID: %(value)s" % locals() + GeniFault.__init__(self, 102, faultstring, extra) def __str__(self): return repr(self.value) -class RecordNotFound(Exception): - def __init__(self, value): +class RecordNotFound(GeniFault): + def __init__(self, value, extra = None): self.value = value - def __str__(self): - return repr(self.value) + faultString = "Record not found: %(value)s" % locals() + GeniFault.__init__(self, 102, faultString, extra) + #def __str__(self): + # return repr(self.value) -class UnknownGeniType(Exception): - def __init__(self, value): +class UnknownGeniType(GeniFault): + def __init__(self, value, extra = None): self.value = value + faultString = "Unknown Geni Type: %(value)s" % locals() + GeniFault.__init__(self, 102, faultString, extra) def __str__(self): return repr(self.value) -class MissingAuthority(Exception): - def __init__(self, value): +class MissingAuthority(GeniFault): + def __init__(self, value, extra = None): self.value = value + faultString = "Missing authority: %(value)s" % locals() + GeniFault.__init__(self, 102, faultString, extra) def __str__(self): return repr(self.value) -class PlanetLabRecordDoesNotExist(Exception): - def __init__(self, value): +class PlanetLabRecordDoesNotExist(GeniFault): + def __init__(self, value, extra = None): self.value = value + faultString = "PlanetLab record does not exist : %(value)s" % locals() + GeniFault.__init__(self, 102, faultString, extra) def __str__(self): return repr(self.value) -class PermissionError(Exception): - def __init__(self, value): +class PermissionError(GeniFault): + def __init__(self, value, extra = None): self.value = value + faultString = "Permission error: %(value)s" % locals() + GeniFault.__init__(self, 108, faultString, extra) def __str__(self): return repr(self.value) -class InsufficientRights(Exception): - def __init__(self, value): +class InsufficientRights(GeniFault): + def __init__(self, value, extra = None): self.value = value + faultString = "Insufficient rights: %(value)s" % locals() + GeniFault.__init__(self, 108, faultString, extra) def __str__(self): return repr(self.value) -class MissingDelegateBit(Exception): - def __init__(self, value): +class MissingDelegateBit(GeniFault): + def __init__(self, value, extra = None): self.value = value + faultString = "Missing delegate bit: %(value)s" % locals() + GeniFault.__init__(self, 108, faultString, extra) def __str__(self): return repr(self.value) -class ChildRightsNotSubsetOfParent(Exception): - def __init__(self, value): +class ChildRightsNotSubsetOfParent(GeniFault): + 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) def __str__(self): return repr(self.value) -class CertMissingParent(Exception): - def __init__(self, value): +class CertMissingParent(GeniFault): + def __init__(self, value, extra = None): self.value = value + faultString = "Cert missing parent: %(value)s" % locals() + GeniFault.__init__(self, 103, faultString, extra) def __str__(self): return repr(self.value) -class CertNotSignedByParent(Exception): - def __init__(self, value): +class CertNotSignedByParent(GeniFault): + def __init__(self, value, extra = None): self.value = value + faultString = "Cert not signed by parent: %(value)s" % locals() + GeniFault.__init__(self, 103, faultString, extra) def __str__(self): return repr(self.value) -class GidInvalidParentHrn(Exception): - def __init__(self, value): +class GidInvalidParentHrn(GeniFault): + def __init__(self, value, extra = None): self.value = value + faultString = "GID invalid parent hrn: %(value)s" % locals() + GeniFault.__init__(self, 102, faultString, extra) def __str__(self): return repr(self.value) -class SliverDoesNotExist(Exception): - def __init__(self, value): +class SliverDoesNotExist(GeniFault): + def __init__(self, value, extra = None): self.value = value + faultString = "Sliver does not exist : %(value)s" % locals() + GeniFault.__init__(self, 102, faultString, extra) def __str__(self): return repr(self.value) -- 2.43.0