- change calling convention for Add slightly; if the Add function for
authorMark Huang <mlhuang@cs.princeton.edu>
Wed, 25 Oct 2006 14:31:13 +0000 (14:31 +0000)
committerMark Huang <mlhuang@cs.princeton.edu>
Wed, 25 Oct 2006 14:31:13 +0000 (14:31 +0000)
  an entity implicitly implies a join with another entity, require a
  reference to that entity in the function arguments itself,
  e.g. AddNode(auth, site, node)

25 files changed:
PLC/Methods/AddAddressType.py
PLC/Methods/AddConfFile.py
PLC/Methods/AddNode.py
PLC/Methods/AddNodeGroup.py
PLC/Methods/AddNodeNetwork.py
PLC/Methods/AddPCU.py
PLC/Methods/AddPerson.py
PLC/Methods/AddSiteAddress.py
PLC/Methods/AddSlice.py
PLC/Methods/AddSliceAttributeType.py
PLC/Methods/AuthCheck.py
PLC/Methods/BootCheckAuthentication.py [new file with mode: 0644]
PLC/Methods/BootUpdateNode.py [new file with mode: 0644]
PLC/Methods/UpdateAddress.py
PLC/Methods/UpdateAddressType.py
PLC/Methods/UpdateConfFile.py
PLC/Methods/UpdateKey.py
PLC/Methods/UpdateNode.py
PLC/Methods/UpdateNodeGroup.py
PLC/Methods/UpdateNodeNetwork.py
PLC/Methods/UpdatePerson.py
PLC/Methods/UpdateSite.py
PLC/Methods/UpdateSlice.py
PLC/Methods/UpdateSliceAttributeType.py
PLC/Methods/__init__.py

index 373f804..904a432 100644 (file)
@@ -29,7 +29,7 @@ class AddAddressType(Method):
     object_type = 'AddressType'
     object_ids = []
 
-    def call(self, auth, address_type_fields = {}):
+    def call(self, auth, address_type_fields):
         address_type_fields = dict(filter(can_update, address_type_fields.items()))
         address_type = AddressType(self.api, address_type_fields)
         address_type.sync()
index d258ab7..5b53561 100644 (file)
@@ -30,7 +30,7 @@ class AddConfFile(Method):
     object_type = 'ConfFile'
     object_ids = []
 
-    def call(self, auth, conf_file_fields = {}):
+    def call(self, auth, conf_file_fields):
         conf_file_fields = dict(filter(can_update, conf_file_fields.items()))
         conf_file = ConfFile(self.api, conf_file_fields)
         conf_file.sync()
index a931c02..1b243d0 100644 (file)
@@ -7,7 +7,7 @@ from PLC.Sites import Site, Sites
 from PLC.Auth import PasswordAuth
 
 can_update = lambda (field, value): field in \
-             ['hostname', 'site_id', 'boot_state', 'model', 'version']
+             ['hostname', 'boot_state', 'model', 'version']
 
 class AddNode(Method):
     """
@@ -26,6 +26,8 @@ class AddNode(Method):
 
     accepts = [
         PasswordAuth(),
+        Mixed(Site.fields['site_id'],
+              Site.fields['login_base']),
         node_fields
         ]
 
@@ -35,11 +37,11 @@ class AddNode(Method):
     object_type = 'Node'
     object_ids = []
 
-    def call(self, auth, node_fields = {}):
+    def call(self, auth, site_id_or_login_base, node_fields):
         node_fields = dict(filter(can_update, node_fields.items()))
-        
+
         # Get site information
-        sites = Sites(self.api, [node_fields['site_id']])
+        sites = Sites(self.api, [site_id_or_login_base])
         if not sites:
             raise PLCInvalidArgument, "No such site"
 
@@ -58,6 +60,7 @@ class AddNode(Method):
                 assert self.caller['person_id'] in site['person_ids']
 
         node = Node(self.api, node_fields)
+        node['site_id'] = site['site_id']
         node.sync()
 
        self.object_ids = [site['site_id'], node['node_id']]    
index 34a73d2..f0dd56d 100644 (file)
@@ -30,7 +30,7 @@ class AddNodeGroup(Method):
     object_type = 'NodeGroup'
     object_ids = []
 
-    def call(self, auth, nodegroup_fields = {}):
+    def call(self, auth, nodegroup_fields):
         nodegroup_fields = dict(filter(can_update, nodegroup_fields.items()))
         nodegroup = NodeGroup(self.api, nodegroup_fields)
         nodegroup.sync()
index da08581..1ffebfc 100644 (file)
@@ -5,19 +5,22 @@ from PLC.Nodes import Node, Nodes
 from PLC.NodeNetworks import NodeNetwork, NodeNetworks
 from PLC.Auth import PasswordAuth
 
-can_update = lambda (field, value): field not in ['nodenetwork_id']
+can_update = lambda (field, value): field not in ['nodenetwork_id', 'node_id']
 
 class AddNodeNetwork(Method):
     """
+
     Adds a new network for a node. Any values specified in
-    nodenetwork_fields are used, otherwise defaults are used. Acceptable
-    values for method are dhcp, static, proxy, tap, and
-    ipmi. Acceptable value for type is ipv4. If type is static, ip,
-    gateway, network, broadcast, netmask, and dns1 must all be
-    specified in nodenetwork_fields. If type is dhcp, these parameters,
-    even if specified, are ignored.
-
-    PIs and techs may only add networks to their own nodes. ins may
+    nodenetwork_fields are used, otherwise defaults are
+    used. Acceptable values for method may be retrieved via
+    GetNetworkMethods. Acceptable values for type may be retrieved via
+    GetNetworkTypes.
+
+    If type is static, ip, gateway, network, broadcast, netmask, and
+    dns1 must all be specified in nodenetwork_fields. If type is dhcp,
+    these parameters, even if specified, are ignored.
+
+    PIs and techs may only add networks to their own nodes. Admins may
     add networks to any node.
 
     Returns the new nodenetwork_id (> 0) if successful, faults otherwise.
@@ -29,6 +32,8 @@ class AddNodeNetwork(Method):
 
     accepts = [
         PasswordAuth(),
+        Mixed(Node.fields['node_id'],
+              Node.fields['hostname']),
         nodenetwork_fields
         ]
 
@@ -38,11 +43,11 @@ class AddNodeNetwork(Method):
     object_type = 'NodeNetwork'
     object_ids = []
 
-    def call(self, auth, nodenetwork_fields = {}):
+    def call(self, auth, node_id_or_hostname, nodenetwork_fields):
         nodenetwork_fields = dict(filter(can_update, nodenetwork_fields.items()))
 
         # Check if node exists
-        nodes = Nodes(self.api, [nodenetwork_fields['node_id']]).values()
+        nodes = Nodes(self.api, [node_id_or_hostname]).values()
         if not nodes:
             raise PLCInvalidArgument, "No such node"
        node = nodes[0]
@@ -58,6 +63,7 @@ class AddNodeNetwork(Method):
 
         # Add node network
        nodenetwork = NodeNetwork(self.api, nodenetwork_fields)
+        nodenetwork['node_id'] = node['node_id']
         nodenetwork.sync()
 
        self.object_ids = [node['node_id'], nodenetwork['nodenetwork_id']]      
index 2534079..95ecb63 100644 (file)
@@ -6,8 +6,7 @@ from PLC.Auth import PasswordAuth
 from PLC.Sites import Site, Sites
 
 can_update = lambda (field, value): field in \
-             ['site_id',
-              'ip', 'hostname', 'protocol',
+             ['ip', 'hostname', 'protocol',
               'username', 'password',
               'model', 'notes']
 
@@ -28,6 +27,8 @@ class AddPCU(Method):
 
     accepts = [
         PasswordAuth(),
+        Mixed(Site.fields['site_id'],
+              Site.fields['login_base']),
         pcu_fields
         ]
 
@@ -37,11 +38,11 @@ class AddPCU(Method):
     object_type = 'PCU'
     object_ids = []
 
-    def call(self, auth, pcu_fields = {}):
+    def call(self, auth, site_id_or_login_base, pcu_fields = {}):
         pcu_fields = dict(filter(can_update, pcu_fields.items()))
 
         # Get associated site details
-        sites = Sites(self.api, [pcu_fields['site_id']]).values()
+        sites = Sites(self.api, [site_id_or_login_base]).values()
         if not sites:
             raise PLCInvalidArgument, "No such site"
         site = sites[0]
@@ -51,6 +52,7 @@ class AddPCU(Method):
                 raise PLCPermissionDenied, "Not allowed to add a PCU to that site"
 
         pcu = PCU(self.api, pcu_fields)
+        pcu['site_id'] = site['site_id']
         pcu.sync()
 
        self.object_ids = [site['site_id'], pcu['pcu_id']]
index 6af541b..63b3cf3 100644 (file)
@@ -34,7 +34,7 @@ class AddPerson(Method):
     object_type = 'Person'
     object_ids = []
 
-    def call(self, auth, person_fields = {}):
+    def call(self, auth, person_fields):
         person_fields = dict(filter(can_update, person_fields.items()))
         person = Person(self.api, person_fields)
         person.sync()
index 4524996..7baf771 100644 (file)
@@ -36,7 +36,7 @@ class AddSiteAddress(Method):
     object_type = 'Address'
     object_ids = []
 
-    def call(self, auth, site_id_or_login_base, address_fields = {}):
+    def call(self, auth, site_id_or_login_base, address_fields):
         address_fields = dict(filter(can_update, address_fields.items()))
 
         # Get associated site details
index 0116803..f0adebe 100644 (file)
@@ -42,7 +42,7 @@ class AddSlice(Method):
     object_type = 'Slice'
     object_ids = []
 
-    def call(self, auth, slice_fields = {}):
+    def call(self, auth, slice_fields):
         slice_fields = dict(filter(can_update, slice_fields.items()))
 
         # 1. Lowercase.
index 8ed1d58..ddb3bf5 100644 (file)
@@ -31,7 +31,7 @@ class AddSliceAttributeType(Method):
     object_type = 'SliceAttributeType'
     object_ids = []
 
-    def call(self, auth, attribute_type_fields = {}):
+    def call(self, auth, attribute_type_fields):
         attribute_type_fields = dict(filter(can_update, attribute_type_fields.items()))
         attribute_type = SliceAttributeType(self.api, attribute_type_fields)
         attribute_type.sync()
index 3a697ee..09b2f9b 100644 (file)
@@ -1,15 +1,15 @@
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
-from PLC.Auth import PasswordAuth
+from PLC.Auth import PasswordAuth, BootAuth
 
 class AuthCheck(Method):
     """
-    Returns 1 if the user authenticated successfully, faults
+    Returns 1 if the user or node authenticated successfully, faults
     otherwise.
     """
 
     roles = ['admin', 'pi', 'user', 'tech']
-    accepts = [PasswordAuth()]
+    accepts = [Mixed(PasswordAuth(), BootAuth())]
     returns = Parameter(int, '1 if successful')
 
     def call(self, auth):
diff --git a/PLC/Methods/BootCheckAuthentication.py b/PLC/Methods/BootCheckAuthentication.py
new file mode 100644 (file)
index 0000000..ea9b098
--- /dev/null
@@ -0,0 +1,8 @@
+from PLC.Methods.AuthCheck import AuthCheck
+
+class BootCheckAuthentication(AuthCheck):
+    """
+    Deprecated. See AuthCheck.
+    """
+
+    status = "deprecated"
diff --git a/PLC/Methods/BootUpdateNode.py b/PLC/Methods/BootUpdateNode.py
new file mode 100644 (file)
index 0000000..032328c
--- /dev/null
@@ -0,0 +1,18 @@
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.Auth import PasswordAuth, BootAuth
+
+class BootUpdateNode(Method):
+    """
+    Allows the calling node to update its own record. Only the primary
+    network can be updated, and the node IP cannot be changed.
+
+    Returns 1 if updated successfully.
+    """
+
+    accepts = [BootAuth(), dict]
+    returns = Parameter(int, '1 if successful')
+
+    def call(self, auth, update_fields):
+        # XXX
+        return 1
index e6885d9..c0687b6 100644 (file)
@@ -21,8 +21,6 @@ class UpdateAddress(Method):
     roles = ['admin', 'pi']
 
     address_fields = dict(filter(can_update, Address.fields.items()))
-    for field in address_fields.values():
-        field.optional = True
 
     accepts = [
         PasswordAuth(),
index 7e71431..2956680 100644 (file)
@@ -17,8 +17,6 @@ class UpdateAddressType(Method):
     roles = ['admin']
 
     address_type_fields = dict(filter(can_update, AddressType.fields.items()))
-    for field in address_type_fields.values():
-        field.optional = True
 
     accepts = [
         PasswordAuth(),
index f68e0fe..e236ce9 100644 (file)
@@ -18,8 +18,6 @@ class UpdateConfFile(Method):
     roles = ['admin']
 
     conf_file_fields = dict(filter(can_update, ConfFile.fields.items()))
-    for field in conf_file_fields.values():
-        field.optional = True
 
     accepts = [
         PasswordAuth(),
index 58dfccb..db32663 100644 (file)
@@ -20,8 +20,6 @@ class UpdateKey(Method):
     roles = ['admin', 'pi', 'tech', 'user']
 
     key_fields = dict(filter(can_update, Key.fields.items()))
-    for field in key_fields.values():
-        field.optional = True
 
     accepts = [
         PasswordAuth(),
index 3566a42..4c2f284 100644 (file)
@@ -22,8 +22,6 @@ class UpdateNode(Method):
     roles = ['admin', 'pi', 'tech']
 
     node_fields = dict(filter(can_update, Node.fields.items()))
-    for field in node_fields.values():
-        field.optional = True
 
     accepts = [
         PasswordAuth(),
index e84d98e..6088230 100644 (file)
@@ -17,8 +17,6 @@ class UpdateNodeGroup(Method):
     roles = ['admin']
 
     nodegroup_fields = dict(filter(can_update, NodeGroup.fields.items()))
-    for field in nodegroup_fields.values():
-        field.optional = True
 
     accepts = [
         PasswordAuth(),
@@ -29,7 +27,7 @@ class UpdateNodeGroup(Method):
 
     returns = Parameter(int, '1 if successful')
 
-    def call(self, auth, nodegroup_id_or_name, nodegroup_fields = {}):
+    def call(self, auth, nodegroup_id_or_name, nodegroup_fields):
         nodegroup_fields = dict(filter(can_update, nodegroup_fields.items()))
 
        # Get nodegroup information
index 8b4ba85..dc52700 100644 (file)
@@ -26,8 +26,6 @@ class UpdateNodeNetwork(Method):
     roles = ['admin', 'pi', 'tech']
 
     nodenetwork_fields = dict(filter(can_update, NodeNetwork.fields.items()))
-    for field in nodenetwork_fields.values():
-        field.optional = True
 
     accepts = [
         PasswordAuth(),
index 66392fe..4e91a8f 100644 (file)
@@ -13,11 +13,6 @@ class UpdatePerson(Method):
     """
     Updates a person. Only the fields specified in person_fields are
     updated, all other fields are left untouched.
-
-    To remove a value without setting a new one in its place (for
-    example, to remove an address from the person), specify -1 for int
-    and double fields and 'null' for string fields. first_name and
-    last_name cannot be unset.
     
     Users and techs can only update themselves. PIs can only update
     themselves and other non-PIs at their sites.
@@ -28,8 +23,6 @@ class UpdatePerson(Method):
     roles = ['admin', 'pi', 'user', 'tech']
 
     person_fields = dict(filter(can_update, Person.fields.items()))
-    for field in person_fields.values():
-        field.optional = True
 
     accepts = [
         PasswordAuth(),
index e734f60..09d7b13 100644 (file)
@@ -14,11 +14,6 @@ class UpdateSite(Method):
     Updates a site. Only the fields specified in update_fields are
     updated, all other fields are left untouched.
 
-    To remove a value without setting a new one in its place (for
-    example, to remove an address from the node), specify -1 for int
-    and double fields and 'null' for string fields. hostname and
-    boot_state cannot be unset.
-    
     PIs can only update sites they are a member of. Only admins can 
     update max_slices.
 
@@ -28,8 +23,6 @@ class UpdateSite(Method):
     roles = ['admin', 'pi']
 
     site_fields = dict(filter(can_update, Site.fields.items()))
-    for field in site_fields.values():
-        field.optional = True
 
     accepts = [
         PasswordAuth(),
index 058ad5b..6d046de 100644 (file)
@@ -29,8 +29,6 @@ class UpdateSlice(Method):
     roles = ['admin', 'pi', 'user']
 
     slice_fields = dict(filter(can_update, Slice.fields.items()))
-    for field in slice_fields.values():
-        field.optional = True
 
     accepts = [
         PasswordAuth(),
index 7bfe800..f169864 100644 (file)
@@ -18,8 +18,6 @@ class UpdateSliceAttributeType(Method):
     roles = ['admin']
 
     attribute_type_fields = dict(filter(can_update, SliceAttributeType.fields.items()))
-    for field in attribute_type_fields.values():
-        field.optional = True
 
     accepts = [
         PasswordAuth(),
@@ -39,7 +37,6 @@ class UpdateSliceAttributeType(Method):
         attribute_type = attribute_types[0]
 
         attribute_type.update(attribute_type_fields)
-
         attribute_type.sync()
 
         return 1
index 1ebb7bc..0f9e3b5 100644 (file)
@@ -1 +1 @@
-methods = 'AddAddressType AddAddressTypeToAddress AddBootState AddConfFile AddConfFileToNodeGroup AddConfFileToNode AddKeyType AddNetworkMethod AddNetworkType AddNodeGroup AddNodeNetwork AddNode AddNodeToNodeGroup AddNodeToPCU AddPCU AddPersonKey AddPerson AddPersonToSite AddPersonToSlice AddRole AddRoleToPerson AddSiteAddress AddSite AddSliceAttribute AddSliceAttributeType AddSlice AddSliceToNodes AdmAddAddressType AdmAddNodeGroup AdmAddNodeNetwork AdmAddNode AdmAddNodeToNodeGroup AdmAddPersonKey AdmAddPerson AdmAddPersonToSite AdmAddSitePowerControlUnit AdmAddSite AdmAssociateNodeToPowerControlUnitPort AdmAuthCheck AdmDeleteAddressType AdmDeleteAllPersonKeys AdmDeleteNodeGroup AdmDeleteNodeNetwork AdmDeleteNode AdmDeletePersonKeys AdmDeletePerson AdmDeleteSitePowerControlUnit AdmDeleteSite AdmDisassociatePowerControlUnitPort AdmGenerateNodeConfFile AdmGetAllAddressTypes AdmGetAllKeyTypes AdmGetAllNodeNetworks AdmGetAllRoles AdmGetNodeGroupNodes AdmGetNodeGroups AdmGetNodes AdmGetPersonKeys AdmGetPersonRoles AdmGetPersonSites AdmGetPersons AdmGetPowerControlUnitNodes AdmGetPowerControlUnits AdmGetSiteNodes AdmGetSitePersons AdmGetSitePIs AdmGetSitePowerControlUnits AdmGetSites AdmGetSiteTechContacts AdmGrantRoleToPerson AdmIsPersonInRole AdmQueryConfFile AdmQueryNode AdmQueryPerson AdmQueryPowerControlUnit AdmQuerySite AdmRebootNode AdmRemoveNodeFromNodeGroup AdmRemovePersonFromSite AdmRevokeRoleFromPerson AdmSetPersonEnabled AdmSetPersonPrimarySite AdmUpdateNodeGroup AdmUpdateNodeNetwork AdmUpdateNode AdmUpdatePerson AdmUpdateSitePowerControlUnit AdmUpdateSite AuthCheck BlacklistKey DeleteAddress DeleteAddressTypeFromAddress DeleteAddressType DeleteBootState DeleteConfFileFromNodeGroup DeleteConfFileFromNode DeleteConfFile DeleteKey DeleteKeyType DeleteNetworkMethod DeleteNetworkType DeleteNodeFromNodeGroup DeleteNodeFromPCU DeleteNodeGroup DeleteNodeNetwork DeleteNode DeletePCU DeletePersonFromSite DeletePersonFromSlice DeletePerson DeleteRoleFromPerson DeleteRole DeleteSite DeleteSliceAttribute DeleteSliceAttributeType DeleteSliceFromNodes DeleteSlice GetAddresses GetAddressTypes GetBootStates GetConfFiles GetEvents GetKeys GetKeyTypes GetNetworkMethods GetNetworkTypes GetNodeGroups GetNodeNetworks GetNodes GetPCUs GetPersons GetRoles GetSites GetSliceAttributes GetSliceAttributeTypes GetSlices GetSlivers RebootNode SetPersonPrimarySite SliceCreate SliceDelete UpdateAddress UpdateAddressType UpdateConfFile UpdateKey UpdateNodeGroup UpdateNodeNetwork UpdateNode UpdatePCU UpdatePerson UpdateSite UpdateSliceAttribute UpdateSliceAttributeType UpdateSlice  system.listMethods  system.methodHelp  system.methodSignature  system.multicall'.split()
+methods = 'AddAddressType AddAddressTypeToAddress AddBootState AddConfFile AddConfFileToNodeGroup AddConfFileToNode AddKeyType AddNetworkMethod AddNetworkType AddNodeGroup AddNodeNetwork AddNode AddNodeToNodeGroup AddNodeToPCU AddPCU AddPersonKey AddPerson AddPersonToSite AddPersonToSlice AddRole AddRoleToPerson AddSiteAddress AddSite AddSliceAttribute AddSliceAttributeType AddSlice AddSliceToNodes AdmAddAddressType AdmAddNodeGroup AdmAddNodeNetwork AdmAddNode AdmAddNodeToNodeGroup AdmAddPersonKey AdmAddPerson AdmAddPersonToSite AdmAddSitePowerControlUnit AdmAddSite AdmAssociateNodeToPowerControlUnitPort AdmAuthCheck AdmDeleteAddressType AdmDeleteAllPersonKeys AdmDeleteNodeGroup AdmDeleteNodeNetwork AdmDeleteNode AdmDeletePersonKeys AdmDeletePerson AdmDeleteSitePowerControlUnit AdmDeleteSite AdmDisassociatePowerControlUnitPort AdmGenerateNodeConfFile AdmGetAllAddressTypes AdmGetAllKeyTypes AdmGetAllNodeNetworks AdmGetAllRoles AdmGetNodeGroupNodes AdmGetNodeGroups AdmGetNodes AdmGetPersonKeys AdmGetPersonRoles AdmGetPersonSites AdmGetPersons AdmGetPowerControlUnitNodes AdmGetPowerControlUnits AdmGetSiteNodes AdmGetSitePersons AdmGetSitePIs AdmGetSitePowerControlUnits AdmGetSites AdmGetSiteTechContacts AdmGrantRoleToPerson AdmIsPersonInRole AdmQueryConfFile AdmQueryNode AdmQueryPerson AdmQueryPowerControlUnit AdmQuerySite AdmRebootNode AdmRemoveNodeFromNodeGroup AdmRemovePersonFromSite AdmRevokeRoleFromPerson AdmSetPersonEnabled AdmSetPersonPrimarySite AdmUpdateNodeGroup AdmUpdateNodeNetwork AdmUpdateNode AdmUpdatePerson AdmUpdateSitePowerControlUnit AdmUpdateSite AuthCheck BlacklistKey BootCheckAuthentication BootUpdateNode DeleteAddress DeleteAddressTypeFromAddress DeleteAddressType DeleteBootState DeleteConfFileFromNodeGroup DeleteConfFileFromNode DeleteConfFile DeleteKey DeleteKeyType DeleteNetworkMethod DeleteNetworkType DeleteNodeFromNodeGroup DeleteNodeFromPCU DeleteNodeGroup DeleteNodeNetwork DeleteNode DeletePCU DeletePersonFromSite DeletePersonFromSlice DeletePerson DeleteRoleFromPerson DeleteRole DeleteSite DeleteSliceAttribute DeleteSliceAttributeType DeleteSliceFromNodes DeleteSlice GetAddresses GetAddressTypes GetBootStates GetConfFiles GetEvents GetKeys GetKeyTypes GetNetworkMethods GetNetworkTypes GetNodeGroups GetNodeNetworks GetNodes GetPCUs GetPersons GetRoles GetSites GetSliceAttributes GetSliceAttributeTypes GetSlices GetSlivers RebootNode SetPersonPrimarySite SliceCreate SliceDelete UpdateAddress UpdateAddressType UpdateConfFile UpdateKey UpdateNodeGroup UpdateNodeNetwork UpdateNode UpdatePCU UpdatePerson UpdateSite UpdateSliceAttribute UpdateSliceAttributeType UpdateSlice  system.listMethods  system.methodHelp  system.methodSignature  system.multicall'.split()