Initial checkin of new API implementation
authorTony Mack <tmack@cs.princeton.edu>
Mon, 9 Oct 2006 17:51:27 +0000 (17:51 +0000)
committerTony Mack <tmack@cs.princeton.edu>
Mon, 9 Oct 2006 17:51:27 +0000 (17:51 +0000)
PLC/Methods/AddSliceToNodes.py [new file with mode: 0644]
PLC/Methods/DeletePersonFromSlice.py [new file with mode: 0644]
PLC/Methods/DeleteSliceFromNodes.py [new file with mode: 0644]
PLC/Methods/__init__.py

diff --git a/PLC/Methods/AddSliceToNodes.py b/PLC/Methods/AddSliceToNodes.py
new file mode 100644 (file)
index 0000000..249a1d8
--- /dev/null
@@ -0,0 +1,51 @@
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.Nodes import Node, Nodes
+from PLC.Slices import Slice, Slices
+from PLC.Auth import PasswordAuth
+
+class AddSliceToNodes(Method):
+    """
+    Adds the specified slice to the specified nodes. If the slice is
+    already associated with a node, no errors are returned. 
+
+    Returns 1 if successful, faults otherwise.
+    """
+
+    roles = ['admin', 'pi']
+
+    accepts = [
+        PasswordAuth(),
+        Mixed(Slice.fields['slice_id'],
+              Slice.fields['name']),
+       [Mixed(Node.fields['node_id'],
+               Node.fields['hostname'])]
+        ]
+
+    returns = Parameter(int, '1 if successful')
+
+    def call(self, auth, slice_id_or_name, node_id_or_hostname_list):
+
+        # Get slice information
+        slices = Slices(self.api, [slice_id_or_name])
+        if not slices:
+            raise PLCInvalidArgument, "No such slice"
+
+        slice = slices.values()[0]
+
+        # Get specified nodes
+        nodes = Nodes(self.api, node_id_or_hostname_list).values()
+
+        # If we are not admin, make sure the caller is a pi
+        # of the site associated with the slice
+       if 'admin' not in self.caller['roles']:
+               if slice['site_id'] not in self.caller['site_ids']:
+                       raise PLCPermissionDenied, "Not allowed to add nodes to this slice"
+       
+       # add slice to all nodes found
+       for node in nodes:
+               if slice['slice_id'] not in node['slice_ids']:
+                       slice.add_node(node)
+
+        return 1
diff --git a/PLC/Methods/DeletePersonFromSlice.py b/PLC/Methods/DeletePersonFromSlice.py
new file mode 100644 (file)
index 0000000..b9a5977
--- /dev/null
@@ -0,0 +1,52 @@
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.Persons import Person, Persons
+from PLC.Slices import Slice, Slices
+from PLC.Auth import PasswordAuth
+
+class DeletePersonFromSlice(Method):
+    """
+    Deletes the specified person from the specified slice. If the person is
+    not a member of the slice, no errors are returned. 
+
+    Returns 1 if successful, faults otherwise.
+    """
+
+    roles = ['admin', 'pi']
+
+    accepts = [
+        PasswordAuth(),
+        Mixed(Person.fields['person_id'],
+              Person.fields['email']),
+        Mixed(Slice.fields['slice_id'],
+              Slice.fields['name'])
+        ]
+
+    returns = Parameter(int, '1 if successful')
+
+    def call(self, auth, person_id_or_email, slice_id_or_name):
+        # Get account information
+        persons = Persons(self.api, [person_id_or_email])
+        if not persons:
+            raise PLCInvalidArgument, "No such account"
+
+        person = persons.values()[0]
+
+        # Get slice information
+        slices = Slices(self.api, [slice_id_or_name])
+        if not slices:
+            raise PLCInvalidArgument, "No such slice"
+
+        slice = slices.values()[0]
+
+        # If we are not admin, make sure the caller is a pi
+        # of the site associated with the slice
+       if 'admin' not in self.caller['roles']:
+               if slice['site_id'] not in self.caller['site_ids']:
+                       raise PLCPermissionDenied, "Not allowed to delete users from this slice"
+
+       if slice['slice_id'] in person['slice_ids']:
+            slice.remove_person(person)
+
+        return 1
diff --git a/PLC/Methods/DeleteSliceFromNodes.py b/PLC/Methods/DeleteSliceFromNodes.py
new file mode 100644 (file)
index 0000000..c61c5eb
--- /dev/null
@@ -0,0 +1,51 @@
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.Nodes import Node, Nodes
+from PLC.Slices import Slice, Slices
+from PLC.Auth import PasswordAuth
+
+class DeleteSliceFromNodes(Method):
+    """
+    Deletes the specified slice from the specified nodes. If the slice is
+    not associated with a node, no errors are returned. 
+
+    Returns 1 if successful, faults otherwise.
+    """
+
+    roles = ['admin', 'pi']
+
+    accepts = [
+        PasswordAuth(),
+        Mixed(Slice.fields['slice_id'],
+              Slice.fields['name']),
+       [Mixed(Node.fields['node_id'],
+               Node.fields['hostname'])]
+        ]
+
+    returns = Parameter(int, '1 if successful')
+
+    def call(self, auth, slice_id_or_name, node_id_or_hostname_list):
+
+        # Get slice information
+        slices = Slices(self.api, [slice_id_or_name])
+        if not slices:
+            raise PLCInvalidArgument, "No such slice"
+
+        slice = slices.values()[0]
+
+       # Get specified nodes
+        nodes = Nodes(self.api, node_id_or_hostname_list).values()
+
+        # If we are not admin, make sure the caller is a pi
+        # of the site associated with the slice
+       if 'admin' not in self.caller['roles']:
+               if slice['site_id'] not in self.caller['site_ids']:
+                       raise PLCPermissionDenied, "Not allowed to delete nodes from this slice"
+       
+       # add slice to all nodes found
+       for node in nodes:
+               if slice['slice_id'] in node['slice_ids']:
+                       slice.remove_node(node)
+
+        return 1
index 9063405..5950b46 100644 (file)
@@ -1 +1 @@
-methods = 'AddAddress AddAddressType AddAddressTypeToAddress AddAttribute AddNodeGroup AddNodeNetwork AddNode AddNodeToNodeGroup AddPerson AddPersonToSite AddRoleToPerson AddSite AddSliceAttribute AddSlice AdmAddNodeGroup AdmAddNodeNetwork AdmAddNode AdmAddNodeToNodeGroup AdmAddPerson AdmAddPersonToSite AdmAddSite AdmAuthCheck AdmDeleteNodeGroup AdmDeleteNodeNetwork AdmDeleteNode AdmDeletePerson AdmDeleteSite AdmGetAllNodeNetworkBandwidthLimits AdmGetAllNodeNetworks AdmGetAllRoles AdmGetNodeGroupNodes AdmGetNodeGroups AdmGetNodes AdmGetPersonRoles AdmGetPersonSites AdmGetPersons AdmGetSiteNodes AdmGetSitePersons AdmGetSites AdmGrantRoleToPerson AdmIsPersonInRole AdmRemoveNodeFromNodeGroup AdmRemovePersonFromSite AdmRevokeRoleFromPerson AdmSetPersonEnabled AdmSetPersonPrimarySite AdmUpdateNodeGroup AdmUpdateNodeNetwork AdmUpdateNode AdmUpdatePerson AdmUpdateSite Authenticate DeleteAddress DeleteAddressTypeFromAddress DeleteAddressType DeleteAttribute DeleteNodeGroup DeleteNodeNetwork DeleteNode DeletePerson DeleteSite DeleteSliceAttribute DeleteSlice GetAddresses GetAddressTypes GetAttributes GetNodeGroups GetNodeNetworkBandwidthLimits GetNodeNetworks GetNodes GetPersons GetSites GetSliceAttributes GetSlices RemoveNodeFromNodeGroup RemovePersonFromSite RemoveRoleFromPerson SetPersonPrimarySite UpdateAddress UpdateAddressType UpdateAttribute UpdateNodeGroup UpdateNodeNetwork UpdateNode UpdatePerson UpdateSite UpdateSliceAttribute UpdateSlice  system.listMethods  system.methodHelp  system.methodSignature  system.multicall'.split()
+methods = 'AddAddress AddAddressType AddAddressTypeToAddress AddAttribute AddNodeGroup AddNodeNetwork AddNode AddNodeToNodeGroup AddPerson AddPersonToSite AddPersonToSlice AddRoleToPerson AddSite AddSliceAttribute AddSlice AddSliceToNodes AdmAddNodeGroup AdmAddNodeNetwork AdmAddNode AdmAddNodeToNodeGroup AdmAddPerson AdmAddPersonToSite AdmAddSite AdmAuthCheck AdmDeleteNodeGroup AdmDeleteNodeNetwork AdmDeleteNode AdmDeletePerson AdmDeleteSite AdmGetAllNodeNetworkBandwidthLimits AdmGetAllNodeNetworks AdmGetAllRoles AdmGetNodeGroupNodes AdmGetNodeGroups AdmGetNodes AdmGetPersonRoles AdmGetPersonSites AdmGetPersons AdmGetSiteNodes AdmGetSitePersons AdmGetSites AdmGrantRoleToPerson AdmIsPersonInRole AdmRemoveNodeFromNodeGroup AdmRemovePersonFromSite AdmRevokeRoleFromPerson AdmSetPersonEnabled AdmSetPersonPrimarySite AdmUpdateNodeGroup AdmUpdateNodeNetwork AdmUpdateNode AdmUpdatePerson AdmUpdateSite DeleteAddress DeleteAddressTypeFromAddress DeleteAddressType DeleteAttribute DeleteNodeFromNodeGroup DeleteNodeGroup DeleteNodeNetwork DeleteNode DeletePersonFromSite DeletePersonFromSlice DeletePerson DeleteRoleFromPerson DeleteSite DeleteSliceAttribute DeleteSliceFromNodes DeleteSlice GetAddresses GetAddressTypes GetAttributes GetNodeGroups GetNodeNetworks GetNodes GetPersons GetSites GetSliceAttributes GetSlices SetPersonPrimarySite UpdateAddress UpdateAddressType UpdateAttribute UpdateNodeGroup UpdateNodeNetwork UpdateNode UpdatePerson UpdateSite UpdateSliceAttribute UpdateSlice  system.listMethods  system.methodHelp  system.methodSignature  system.multicall'.split()