2 # PLCAPI XML-RPC faults
4 # Aaron Klingaman <alk@absarokasoft.com>
5 # Mark Huang <mlhuang@cs.princeton.edu>
7 # Copyright (C) 2004-2006 The Trustees of Princeton University
8 # $Id: Faults.py,v 1.1 2006/09/06 15:36:06 mlhuang Exp $
13 class PLCFault(xmlrpclib.Fault):
14 def __init__(self, faultCode, faultString, extra = None):
16 faultString += ": " + extra
17 xmlrpclib.Fault.__init__(self, faultCode, faultString)
19 class PLCInvalidAPIMethod(PLCFault):
20 def __init__(self, method, role = None, extra = None):
21 faultString = "Invalid method " + method
23 faultString += " for role " + role
24 PLCFault.__init__(self, 100, faultString, extra)
26 class PLCInvalidArgumentCount(PLCFault):
27 def __init__(self, got, min, max = min, extra = None):
29 expected = "%d-%d" % (min, max)
32 faultString = "Expected %s arguments, got %d" % \
34 PLCFault.__init__(self, 101, faultString, extra)
36 class PLCInvalidArgument(PLCFault):
37 def __init__(self, extra = None, name = None):
39 faultString = "Invalid %s value" % name
41 faultString = "Invalid argument"
42 PLCFault.__init__(self, 102, faultString, extra)
44 class PLCAuthenticationFailure(PLCFault):
45 def __init__(self, extra = None):
46 faultString = "Failed to authenticate call"
47 PLCFault.__init__(self, 103, faultString, extra)
49 class PLCLocalObjectRequired(PLCFault):
50 def __init__(self,method_name="anonymous",obj_name="anonymous",
51 peer_id=None,extra=None):
52 faultString = "Method: <%s> - Object <%s> must be local"%(method_name,obj_name)
53 if peer_id is not None:
54 faultString += " (authoritative plc has peer_id %d)"%peer_id
55 PLCFault.__init__(self, 104, faultString, extra)
57 class PLCDBError(PLCFault):
58 def __init__(self, extra = None):
59 faultString = "Database error"
60 PLCFault.__init__(self, 106, faultString, extra)
62 class PLCPermissionDenied(PLCFault):
63 def __init__(self, extra = None):
64 faultString = "Permission denied"
65 PLCFault.__init__(self, 108, faultString, extra)
67 class PLCNotImplemented(PLCFault):
68 def __init__(self, extra = None):
69 faultString = "Not fully implemented"
70 PLCFault.__init__(self, 109, faultString, extra)
72 class PLCAPIError(PLCFault):
73 def __init__(self, extra = None):
74 faultString = "Internal API error"
75 PLCFault.__init__(self, 111, faultString, extra)
78 # shorthands to check various types of objects for localness (are we authoritative)
79 def PLCCheckLocalNode (node,method_name):
80 if node['peer_id'] is not None:
81 raise PLCLocalObjectRequired(method_name,node['hostname'],node['peer_id'])
83 def PLCCheckLocalPerson (person,method_name):
84 if person['peer_id'] is not None:
85 raise PLCLocalObjectRequired(method_name,person['email'],person['peer_id'])
87 def PLCCheckLocalSite (site,method_name):
88 if site['peer_id'] is not None:
89 raise PLCLocalObjectRequired(method_name,site['name'],site['peer_id'])
91 def PLCCheckLocalSlice (slice,method_name):
92 if slice['peer_id'] is not None:
93 raise PLCLocalObjectRequired(method_name,slice['name'],slice['peer_id'])
95 def PLCCheckLocalKey (key,method_name):
96 if key['peer_id'] is not None:
97 raise PLCLocalObjectRequired(method_name,key['key_id'],key['peer_id'])
99 def PLCCheckLocalSliceAttributeType (sliceAttributeType,method_name):
100 if sliceAttributeType['peer_id'] is not None:
101 raise PLCLocalObjectRequired(method_name,sliceAttributeType['name'],sliceAttributeType['peer_id'])
103 def PLCCheckLocalSliceAttribute (sliceAttribute,method_name):
104 if sliceAttribute['peer_id'] is not None:
105 raise PLCLocalObjectRequired(method_name,sliceAttribute['name'],sliceAttribute['peer_id'])