# Mark Huang <mlhuang@cs.princeton.edu>
#
# Copyright (C) 2004-2006 The Trustees of Princeton University
-# $Id$
+# $Id: Faults.py,v 1.1 2006/09/06 15:36:06 mlhuang Exp $
#
import xmlrpclib
faultString = "Failed to authenticate call"
PLCFault.__init__(self, 103, faultString, extra)
-class PLCNotImplemented(PLCFault):
- def __init__(self, extra = None):
- faultString = "Not fully implemented"
- PLCFault.__init__(self, 109, faultString, extra)
+class PLCLocalObjectRequired(PLCFault):
+ def __init__(self,method_name="anonymous",obj_name="anonymous",
+ peer_id=None,extra=None):
+ faultString = "Method: <%s> - Object <%s> must be local"%(method_name,obj_name)
+ if peer_id is not None:
+ faultString += " (authoritative plc has peer_id %d)"%peer_id
+ PLCFault.__init__(self, 104, faultString, extra)
class PLCDBError(PLCFault):
def __init__(self, extra = None):
faultString = "Permission denied"
PLCFault.__init__(self, 108, faultString, extra)
+class PLCNotImplemented(PLCFault):
+ def __init__(self, extra = None):
+ faultString = "Not fully implemented"
+ PLCFault.__init__(self, 109, faultString, extra)
+
class PLCAPIError(PLCFault):
def __init__(self, extra = None):
faultString = "Internal API error"
PLCFault.__init__(self, 111, faultString, extra)
+
+####################
+# shorthands to check various types of objects for localness (are we authoritative)
+def PLCCheckLocalNode (node,method_name):
+ if node['peer_id'] is not None:
+ raise PLCLocalObjectRequired(method_name,node['hostname'],node['peer_id'])
+
+def PLCCheckLocalPerson (person,method_name):
+ if person['peer_id'] is not None:
+ raise PLCLocalObjectRequired(method_name,person['email'],person['peer_id'])
+
+def PLCCheckLocalSite (site,method_name):
+ if site['peer_id'] is not None:
+ raise PLCLocalObjectRequired(method_name,site['name'],site['peer_id'])
+
+def PLCCheckLocalSlice (slice,method_name):
+ if slice['peer_id'] is not None:
+ raise PLCLocalObjectRequired(method_name,slice['name'],slice['peer_id'])
+
+def PLCCheckLocalKey (key,method_name):
+ if key['peer_id'] is not None:
+ raise PLCLocalObjectRequired(method_name,key['key_id'],key['peer_id'])
+
+def PLCCheckLocalSliceAttributeType (sliceAttributeType,method_name):
+ if sliceAttributeType['peer_id'] is not None:
+ raise PLCLocalObjectRequired(method_name,sliceAttributeType['name'],sliceAttributeType['peer_id'])
+
+def PLCCheckLocalSliceAttribute (sliceAttribute,method_name):
+ if sliceAttribute['peer_id'] is not None:
+ raise PLCLocalObjectRequired(method_name,sliceAttribute['name'],sliceAttribute['peer_id'])
+
+
if not nodes:
raise PLCInvalidArgument, "No such node"
node = nodes[0]
+ PLCCheckLocalNode (node,"AddConfFileToNode")
# Link configuration file to node
if node['node_id'] not in conf_file['node_ids']:
if not nodes:
raise PLCInvalidArgument, "No such node"
node = nodes[0]
+ PLCCheckLocalNode (node,"AddNodeToNodeGroup")
# Get nodegroup info
nodegroups = NodeGroups(self.api, [nodegroup_id_or_name])
raise PLCInvalidArgument, "No such node"
node = nodes[0]
+ PLCCheckLocalNode(node,"AddNodeToPCU")
# Get PCU
pcus = PCUs(self.api, [pcu_id])
if not persons:
raise PLCInvalidArgument, "No such account"
person = persons[0]
+ PLCCheckLocalPerson (person,"AddPersonKey")
# If we are not admin, make sure caller is adding a key to their account
if 'admin' not in self.caller['roles']:
raise PLCInvalidArgument, "No such account"
person = persons[0]
+ PLCCheckLocalPerson(person,"AddPersonToSite")
# Get site information
sites = Sites(self.api, [site_id_or_login_base])
raise PLCInvalidArgument, "No such site"
site = sites[0]
+ PLCCheckLocalSite(site,"AddPersonToSite")
if site['site_id'] not in person['site_ids']:
site.add_person(person)
raise PLCInvalidArgument, "No such account"
person = persons[0]
+ # Let's be open-minded as a start
+ #PLCCheckLocalPerson(person,"AddPersonToSlice")
# Get slice information
slices = Slices(self.api, [slice_id_or_name])
raise PLCInvalidArgument, "No such slice"
slice = slices[0]
+ PLCCheckLocalSlice(slice,"AddPersonToSlice")
# If we are not admin, make sure the caller is a PI
# of the site associated with the slice
raise PLCInvalidArgument, "No such account"
person = persons[0]
+ PLCCheckLocalPerson(person,"AddRoleToPerson")
# Authenticated function
assert self.caller is not None
raise PLCInvalidArgument, "No such slice"
slice = slices[0]
+ PLCCheckLocalSlice(slice,"AddSliceToNodes")
if 'admin' not in self.caller['roles']:
if self.caller['person_id'] in slice['person_ids']:
raise PLCInvalidArgument, "No such account"
person = persons[0]
+ PLCCheckLocalPerson(person,"AdmDeletePersonKeys")
if 'admin' not in self.caller['roles']:
if self.caller['person_id'] != person['person_id']:
if not nodes:
raise PLCInvalidArgument, "No such node"
node = nodes[0]
+ PLCCheckLocalNode(node,"AdmGenerateNodeConfFile")
# If we are not an admin, make sure that the caller is a
# member of the site at which the node is located.
if not keys:
raise PLCInvalidArgument, "No such key"
key = keys[0]
+ PLCCheckLocalKey(key,"BlackListKey")
key.blacklist()
self.object_ids = [key['key_id']]
if not keys:
raise PLCInvalidArgument, "No such key"
key = keys[0]
+ PLCCheckLocalKey(key,"DeleteKey")
if 'admin' not in self.caller['roles']:
if key['key_id'] not in self.caller['key_ids']:
raise PLCInvalidArgument, "No such node"
node = nodes[0]
+ ### xxx here xxx
+ PLCCheckLocalNode(node,"DeleteNode")
# If we are not an admin, make sure that the caller is a
# member of the site at which the node is located.
raise PLCInvalidArgument, "No such account"
person = persons[0]
+ PLCCheckLocalPerson(person,"DeletePerson")
# Authenticated function
assert self.caller is not None
raise PLCInvalidArgument, "No such site"
site = sites[0]
+ PLCCheckLocalSite(site,"DeletePersonFromSite")
if site['site_id'] in person['site_ids']:
site.remove_person(person)
raise PLCInvalidArgument, "No such slice"
slice = slices[0]
+ PLCCheckLocalSlice(slice,"DeletePersonFromSlice")
# If we are not admin, make sure the caller is a pi
# of the site associated with the slice
raise PLCInvalidArgument, "No such account"
person = persons[0]
+ PLCCheckLocalPerson(person,"DeleteRoleFromPerson")
# Authenticated function
assert self.caller is not None
raise PLCInvalidArgument, "No such site"
site = sites[0]
+ PLCCheckLocalSite(site,"DeleteSite")
+
site.delete()
self.object_ids = [site['site_id']]
if not slices:
raise PLCInvalidArgument, "No such slice"
slice = slices[0]
+ PLCCheckLocalSlice(slice,"DeleteSlice")
if 'admin' not in self.caller['roles']:
if self.caller['person_id'] in slice['person_ids']:
if not slice_attributes:
raise PLCInvalidArgument, "No such slice attribute"
slice_attribute = slice_attributes[0]
+ PLCCheckLocalSliceAttribute(slice_attribute,"DeleteSliceAttribute")
slices = Slices(self.api, [slice_attribute['slice_id']])
if not slices:
raise PLCInvalidArgument, "No such slice"
slice = slices[0]
+ PLCCheckLocalSlice(slice,"DeleteSliceAttribute")
assert slice_attribute['slice_attribute_id'] in slice['slice_attribute_ids']
if not attribute_types:
raise PLCInvalidArgument, "No such slice attribute type"
attribute_type = attribute_types[0]
+ PLCCheckLocalSliceAttributeType(attribute_type,"DeleteSliceAttributeType")
attribute_type.delete()
self.object_ids = [attribute_type['attribute_type_id']]
raise PLCInvalidArgument, "No such slice"
slice = slices[0]
+ PLCCheckLocalSlice(slice,"DeleteSliceFromNodes")
if 'admin' not in self.caller['roles']:
if self.caller['person_id'] in slice['person_ids']:
raise PLCInvalidArgument, "No such account"
person = persons[0]
+ PLCCheckLocalPerson(person,"SetPersonPrimarySite")
# Authenticated function
assert self.caller is not None
raise PLCInvalidArgument, "No such site"
site = sites[0]
+ PLCCheckLocalSite(site,"SetPersonPrimarySite")
if site['site_id'] not in person['site_ids']:
raise PLCInvalidArgument, "Not a member of the specified site"
if not keys:
raise PLCInvalidArgument, "No such key"
key = keys[0]
+ PLCCheckLocalKey(key,"UpdateKey")
if 'admin' not in self.caller['roles']:
if key['key_id'] not in self.caller['key_ids']:
raise PLCInvalidArgument, "No such node"
node = nodes[0]
+ PLCCheckLocalNode(node,"UpdateNode")
# Authenticated function
assert self.caller is not None
raise PLCInvalidArgument, "No such account"
person = persons[0]
+ PLCCheckLocalPerson(person,"UpdatePerson")
# Authenticated function
assert self.caller is not None
raise PLCInvalidArgument, "No such site"
site = sites[0]
+ PLCCheckLocalSite(site,"UpdateSite")
# Authenticated function
assert self.caller is not None
if not slices:
raise PLCInvalidArgument, "No such slice"
slice = slices[0]
+ PLCCheckLocalSlice(slice,"UpdateSlice")
if 'admin' not in self.caller['roles']:
if self.caller['person_id'] in slice['person_ids']:
if not slice_attributes:
raise PLCInvalidArgument, "No such slice attribute"
slice_attribute = slice_attributes[0]
+ PLCCheckLocalSliceAttribute(slice_attribute,"UpdateSliceAttribute")
slices = Slices(self.api, [slice_attribute['slice_id']])
if not slices:
raise PLCInvalidArgument, "No such slice"
slice = slices[0]
+ PLCCheckLocalSlice(slice,"UpdateSliceAttribute")
assert slice_attribute['slice_attribute_id'] in slice['slice_attribute_ids']
if not attribute_types:
raise PLCInvalidArgument, "No such attribute"
attribute_type = attribute_types[0]
+ PLCCheckLocalSliceAttributeType(attribute_type,"UpdateSliceAttributeType")
attribute_type.update(attribute_type_fields)
attribute_type.sync()