allow filters to be specified in most Get() calls
authorMark Huang <mlhuang@cs.princeton.edu>
Wed, 8 Nov 2006 23:11:49 +0000 (23:11 +0000)
committerMark Huang <mlhuang@cs.princeton.edu>
Wed, 8 Nov 2006 23:11:49 +0000 (23:11 +0000)
17 files changed:
PLC/Methods/GetAddressTypes.py
PLC/Methods/GetAddresses.py
PLC/Methods/GetBootStates.py
PLC/Methods/GetConfFiles.py
PLC/Methods/GetForeignNodes.py
PLC/Methods/GetKeyTypes.py
PLC/Methods/GetKeys.py
PLC/Methods/GetNodeGroups.py
PLC/Methods/GetNodeNetworks.py
PLC/Methods/GetNodes.py
PLC/Methods/GetPCUs.py
PLC/Methods/GetPeers.py
PLC/Methods/GetPersons.py
PLC/Methods/GetSites.py
PLC/Methods/GetSliceAttributeTypes.py
PLC/Methods/GetSliceAttributes.py
PLC/Methods/GetSlices.py

index df3a1b6..419027e 100644 (file)
@@ -1,27 +1,28 @@
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
+from PLC.Filter import Filter
 from PLC.AddressTypes import AddressType, AddressTypes
 from PLC.Auth import Auth
 
 class GetAddressTypes(Method):
     """
-    Get an array of structs containing details about valid address
-    types. If address_type_id_or_name_list is specified, only the
-    specified address types will be queried.
+    Returns an array of structs containing details about address
+    types.  If address_type_filter is specified and is an array of
+    address type identifiers, or a struct of address type attributes,
+    only address types matching the filter will be returned.
     """
 
     roles = ['admin', 'pi', 'user', 'tech']
 
     accepts = [
         Auth(),
-        [Mixed(AddressType.fields['address_type_id'],
-               AddressType.fields['name'])]
+        Mixed([Mixed(AddressType.fields['address_type_id'],
+                     AddressType.fields['name'])],
+              Filter(AddressType.fields))
         ]
 
     returns = [AddressType.fields]
 
-    def call(self, auth, address_type_id_or_name_list = None):
-        address_types = AddressTypes(self.api, address_type_id_or_name_list).values()
-
-        return address_types
+    def call(self, auth, address_type_filter = None):
+        return AddressTypes(self.api, address_type_filter).values()
index 75b8ad6..567cd98 100644 (file)
@@ -1,24 +1,27 @@
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
+from PLC.Filter import Filter
 from PLC.Addresses import Address, Addresses
 from PLC.Auth import Auth
 
 class GetAddresses(Method):
     """
-    Get an array of structs containing details about addresses. If
-    address_id_list is specified, only the specified addresses will be
-    queried.
+    Returns an array of structs containing details about addresses. If
+    address_filter is specified and is an array of address
+    identifiers, or a struct of address attributes, only addresses
+    matching the filter will be returned.
     """
 
     roles = ['admin', 'pi', 'user', 'tech']
 
     accepts = [
         Auth(),
-        [Address.fields['address_id']],
+        Mixed([Address.fields['address_id']],
+              Filter(Address.fields))
         ]
 
     returns = [Address.fields]
 
-    def call(self, auth, address_id_list = None):
-        return Addresses(self.api, address_id_list).values()
+    def call(self, auth, address_filter = None):
+        return Addresses(self.api, address_filter).values()
index 71e2cd4..25c6c7d 100644 (file)
@@ -6,7 +6,7 @@ from PLC.Auth import Auth
 
 class GetBootStates(Method):
     """
-    Returns a list of all valid node boot states.
+    Returns an array of all valid node boot states.
     """
 
     roles = ['admin', 'pi', 'user', 'tech']
index fe3cb79..d12365e 100644 (file)
@@ -1,24 +1,28 @@
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
+from PLC.Filter import Filter
 from PLC.ConfFiles import ConfFile, ConfFiles
 from PLC.Auth import Auth
 
 class GetConfFiles(Method):
     """
-    Returns an array of structs containing details about node
-    configuration files. If conf_file_ids is specified, only the
-    specified configuration files will be queried.
+    Returns an array of structs containing details about configuration
+    files. If conf_file_filter is specified and is an array of
+    configuration file identifiers, or a struct of configuration file
+    attributes, only configuration files matching the filter will be
+    returned.
     """
 
     roles = ['admin']
 
     accepts = [
         Auth(),
-        [ConfFile.fields['conf_file_id']]
+        Mixed([ConfFile.fields['conf_file_id']],
+              Filter(ConfFile.fields))
         ]
 
     returns = [ConfFile.fields]
 
-    def call(self, auth, conf_file_ids = None):
-        return ConfFiles(self.api, conf_file_ids).values()
+    def call(self, auth, conf_file_filter = None):
+        return ConfFiles(self.api, conf_file_filter).values()
index e9c2321..9676da4 100644 (file)
@@ -5,25 +5,30 @@
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
+from PLC.Filter import Filter
 from PLC.Auth import Auth
 
 from PLC.ForeignNodes import ForeignNode, ForeignNodes
 
-class GetForeignNodes (Method):
+class GetForeignNodes(Method):
     """
-    returns information on foreign nodes
+    Returns an array of structs containing details about foreign
+    nodes. If foreign_node_filter is specified and is an array of
+    foreign node identifiers or hostnames, or a struct of foreign node
+    attributes, only foreign nodes matching the filter will be
+    returned.
     """
 
     roles = ['admin']
 
-    accepts = [ Auth(),
-               [ Mixed(ForeignNode.fields['node_id'],
-                       ForeignNode.fields['hostname'])]
-               ]
+    accepts = [
+        Auth(),
+        Mixed([Mixed(ForeignNode.fields['node_id'],
+                     ForeignNode.fields['hostname'])],
+              Filter(ForeignNode.fields))
+        ]
     
-    returns = [ ForeignNode.fields]
+    returns = [ForeignNode.fields]
 
-    def call (self, auth, foreign_id_or_hostname_list = None):
-
-       return ForeignNodes (self.api, foreign_id_or_hostname_list).values()
-       
+    def call(self, auth, foreign_node_filter = None):
+       return ForeignNodes(self.api, foreign_node_filter).values()
index 50828a0..f005b99 100644 (file)
@@ -6,7 +6,7 @@ from PLC.Auth import Auth
 
 class GetKeyTypes(Method):
     """
-    Returns a list of all valid key types.
+    Returns an array of all valid key types.
     """
 
     roles = ['admin', 'pi', 'user', 'tech']
index 910707b..9f8f7f4 100644 (file)
@@ -6,8 +6,8 @@ from PLC.Auth import Auth
 
 class GetKeys(Method):
     """
-    Return an array of structs containing details about keys. If
-    key_id_list is specified, only the specified keys will be queried.
+    Returns an array of structs containing details about keys. If
+    key_ids is specified, only the specified keys will be queried.
 
     Admin may query all keys. Non-admins may only query their own
     keys.
index 8601a05..c41b8b9 100644 (file)
@@ -1,25 +1,28 @@
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
+from PLC.Filter import Filter
 from PLC.Auth import Auth
 from PLC.NodeGroups import NodeGroup, NodeGroups
 
 class GetNodeGroups(Method):
     """
-    Returns an array of structs containing details about all node
-    groups. If nodegroup_id_or_name_list is specified, only the
-    specified node groups will be queried.
+    Returns an array of structs containing details about node groups.
+    If nodegroup_filter is specified and is an array of node group
+    identifiers or names, or a struct of node group attributes, only
+    node groups matching the filter will be returned.
     """
 
     roles = ['admin', 'pi', 'user', 'tech']
 
     accepts = [
         Auth(),
-        [Mixed(NodeGroup.fields['nodegroup_id'],
-              NodeGroup.fields['name'])]
+        Mixed([Mixed(NodeGroup.fields['nodegroup_id'],
+                     NodeGroup.fields['name'])],
+              Filter(NodeGroup.fields))
         ]
 
     returns = [NodeGroup.fields]
   
-    def call(self, auth, nodegroup_id_or_name_list = None):
-       return NodeGroups(self.api, nodegroup_id_or_name_list).values()
+    def call(self, auth, nodegroup_filter = None):
+       return NodeGroups(self.api, nodegroup_filter).values()
index e20487f..e2a8c85 100644 (file)
@@ -1,25 +1,28 @@
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
+from PLC.Filter import Filter
 from PLC.NodeNetworks import NodeNetwork, NodeNetworks
 from PLC.Auth import Auth
 
 class GetNodeNetworks(Method):
     """
-    Return an array of structs contain details about node network
-    interfaces. If nodenetwork_id_or_ip_list is specified, only
-    the specified node network interfaces will be queried.
+    Returns an array of structs containing details about node network
+    interfacess. If nodenetworks_filter is specified and is an array
+    of node network identifiers, or a struct of node network
+    attributes, only node network interfaces matching the filter will
+    be returned.
     """
 
     roles = ['admin', 'pi', 'user', 'tech']
 
     accepts = [
         Auth(),
-        [Mixed(NodeNetwork.fields['nodenetwork_id'],
-               NodeNetwork.fields['ip'])]
+        Mixed([NodeNetwork.fields['nodenetwork_id']],
+              Filter(NodeNetwork.fields))
         ]
 
     returns = [NodeNetwork.fields]
 
-    def call(self, auth, nodenetwork_id_or_ip_list = None):
-        return NodeNetworks(self.api, nodenetwork_id_or_ip_list).values()
+    def call(self, auth, nodenetwork_filter = None):
+        return NodeNetworks(self.api, nodenetwork_filter).values()
index d552bcd..a2c2566 100644 (file)
@@ -1,14 +1,16 @@
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
+from PLC.Filter import Filter
 from PLC.Nodes import Node, Nodes
 from PLC.Auth import Auth
 
 class GetNodes(Method):
     """
-    Return an array of structs containing details about nodes. If
-    node_id_or_hostname_list is specified, only the specified nodes
-    will be queried.
+    Returns an array of structs containing details about nodes. If
+    node_filter is specified and is an array of node identifiers or
+    hostnames, or a struct of node attributes, only nodes matching the
+    filter will be returned.
 
     Some fields may only be viewed by admins.
     """
@@ -17,15 +19,16 @@ class GetNodes(Method):
 
     accepts = [
         Auth(),
-        [Mixed(Node.fields['node_id'],
-               Node.fields['hostname'])],
+        Mixed([Mixed(Node.fields['node_id'],
+                     Node.fields['hostname'])],
+              Filter(Node.fields))
         ]
 
     returns = [Node.fields]
 
-    def call(self, auth, node_id_or_hostname_list = None):
+    def call(self, auth, node_filter = None):
         # Get node information
-        nodes = Nodes(self.api, node_id_or_hostname_list).values()
+        nodes = Nodes(self.api, node_filter).values()
 
         # Remove admin only fields
         if 'admin' not in self.caller['roles']:
index 881a85f..dbf371e 100644 (file)
@@ -1,13 +1,16 @@
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
+from PLC.Filter import Filter
 from PLC.PCUs import PCU, PCUs
 from PLC.Auth import Auth
 
 class GetPCUs(Method):
     """
-    Return an array of structs containing details about PCUs. If
-    pcu_id_list is specified, only the specified PCUs will be queried.
+    Returns an array of structs containing details about power control
+    units (PCUs). If pcu_filter is specified and is an array of PCU
+    identifiers, or a struct of PCU attributes, only PCUs matching the
+    filter will be returned.
 
     Admin may query all PCUs. Non-admins may only query the PCUs at
     their sites.
@@ -17,12 +20,13 @@ class GetPCUs(Method):
 
     accepts = [
         Auth(),
-        [PCU.fields['pcu_id']]
+        Mixed([PCU.fields['pcu_id']],
+              Filter(PCU.fields))
         ]
 
     returns = [PCU.fields]
 
-    def call(self, auth, pcu_ids = None):
+    def call(self, auth, pcu_filter = None):
        # If we are not admin, make sure to only return our own PCUs
         if 'admin' not in self.caller['roles']:
             # Get list of PCUs that we are able to view
@@ -32,8 +36,16 @@ class GetPCUs(Method):
                 for site in sites:
                     valid_pcu_ids += site['pcu_ids']
 
-            pcu_ids = set(pcu_ids).intersection(valid_pcu_ids)
-            if not pcu_ids:
+            if not valid_pcu_ids:
                 return []
 
-        return PCUs(self.api, pcu_ids).values()
+            if pcu_filter is None:
+                pcu_filter = valid_pcu_ids
+
+        pcus = PCUs(self.api, pcu_filter).values()
+
+        # Filter out PCUs that are not viewable
+        if 'admin' not in self.caller['roles']:
+            pcus = filter(lambda pcu: pcu['pcu_id'] in valid_pcu_ids, pcus)
+
+        return pcus
index cc85ef1..e4fd459 100644 (file)
@@ -5,24 +5,29 @@
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
+from PLC.Filter import Filter
 from PLC.Auth import Auth
 
 from PLC.Peers import Peer, Peers
 
 class GetPeers (Method):
     """
-    returns information on known peers
+    Returns an array of structs containing details about peers. If
+    person_filter is specified and is an array of peer identifiers or
+    peer names, or a struct of peer attributes, only peers matching
+    the filter will be returned.
     """
 
     roles = ['admin']
 
-    accepts = [Auth(),
-              [Mixed(Peer.fields['peer_id'],
-                     Peer.fields['peername'])],
-              ]
+    accepts = [
+        Auth(),
+        Mixed([Mixed(Peer.fields['peer_id'],
+                     Peer.fields['peername'])],
+              Filter(Peer.fields))
+        ]
 
     returns = [Peer.fields]
 
-    def call (self, auth, peer_id_or_peername_list = None):
-
-       return Peers (self.api, peer_id_or_peername_list).values()
+    def call (self, auth, peer_filter = None):
+       return Peers(self.api, peer_filter).values()
index ecac429..d0f4b2d 100644 (file)
@@ -1,14 +1,16 @@
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
+from PLC.Filter import Filter
 from PLC.Persons import Person, Persons
 from PLC.Auth import Auth
 
 class GetPersons(Method):
     """
-    Return an array of structs containing details about accounts. If
-    person_id_or_email_list is specified, only the specified accounts
-    will be queried.
+    Returns an array of structs containing details about users. If
+    person_filter is specified and is an array of user identifiers or
+    usernames, or a struct of user attributes, only users matching the
+    filter will be returned.
 
     Users and techs may only retrieve details about themselves. PIs
     may retrieve details about themselves and others at their
@@ -19,9 +21,9 @@ class GetPersons(Method):
 
     accepts = [
         Auth(),
-        [Mixed(Person.fields['person_id'],
-               Person.fields['email'])],
-        Parameter([str], 'List of fields to return')
+        Mixed([Mixed(Person.fields['person_id'],
+                     Person.fields['email'])],
+              Filter(Person.fields))
         ]
 
     # Filter out password field
@@ -29,7 +31,7 @@ class GetPersons(Method):
     return_fields = dict(filter(can_return, Person.fields.items()))
     returns = [return_fields]
 
-    def call(self, auth, person_id_or_email_list = None):
+    def call(self, auth, person_filter = None):
        # If we are not admin, make sure to only return viewable accounts
         if 'admin' not in self.caller['roles']:
             # Get accounts that we are able to view
@@ -42,10 +44,10 @@ class GetPersons(Method):
             if not valid_person_ids:
                 return []
 
-            if not person_id_or_email_list:
-                person_id_or_email_list = valid_person_ids
+            if person_filter is None:
+                person_filter = valid_person_ids
 
-        persons = Persons(self.api, person_id_or_email_list).values()
+        persons = Persons(self.api, person_filter).values()
 
         # Filter out accounts that are not viewable
         if 'admin' not in self.caller['roles']:
index 0f0257a..885e280 100644 (file)
@@ -1,5 +1,6 @@
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
+from PLC.Filter import Filter
 from PLC.Auth import Auth
 from PLC.Sites import Site, Sites
 
@@ -14,8 +15,9 @@ class GetSites(Method):
 
     accepts = [
         Auth(),
-        [Mixed(Site.fields['site_id'],
-               Site.fields['login_base'])]
+        Mixed([Mixed(Site.fields['site_id'],
+                     Site.fields['login_base'])],
+              Filter(Site.fields))
         ]
 
     returns = [Site.fields]
@@ -24,5 +26,5 @@ class GetSites(Method):
     object_type = 'Site'
     object_ids = []
        
-    def call(self, auth, site_id_or_login_base_list = None):
-        return Sites(self.api, site_id_or_login_base_list).values()
+    def call(self, auth, site_filter = None):
+        return Sites(self.api, site_filter).values()
index a0db661..0495523 100644 (file)
@@ -1,5 +1,6 @@
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
+from PLC.Filter import Filter
 from PLC.Auth import Auth
 from PLC.SliceAttributeTypes import SliceAttributeType, SliceAttributeTypes
 
@@ -14,11 +15,12 @@ class GetSliceAttributeTypes(Method):
 
     accepts = [
         Auth(),
-        [Mixed(SliceAttributeType.fields['attribute_type_id'],
-               SliceAttributeType.fields['name'])],
+        Mixed([Mixed(SliceAttributeType.fields['attribute_type_id'],
+                     SliceAttributeType.fields['name'])],
+              Filter(SliceAttributeType.fields))
         ]
 
     returns = [SliceAttributeType.fields]
 
-    def call(self, auth, attribute_type_id_or_name_list = None):
-        return SliceAttributeTypes(self.api, attribute_type_id_or_name_list).values()
+    def call(self, auth, attribute_type_filter = None):
+        return SliceAttributeTypes(self.api, attribute_type_filter).values()
index 9a37c93..af5deec 100644 (file)
@@ -1,10 +1,10 @@
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
+from PLC.Filter import Filter
 from PLC.SliceAttributes import SliceAttribute, SliceAttributes
 from PLC.Sites import Site, Sites
 from PLC.Slices import Slice, Slices
-from PLC.Nodes import Node, Nodes
 from PLC.Auth import Auth
 
 class GetSliceAttributes(Method):
@@ -24,12 +24,13 @@ class GetSliceAttributes(Method):
 
     accepts = [
         Auth(),
-        [SliceAttribute.fields['slice_attribute_id']],
+        Mixed([SliceAttribute.fields['slice_attribute_id']],
+              Filter(SliceAttribute.fields))
         ]
 
     returns = [SliceAttribute.fields]
 
-    def call(self, auth, slice_attribute_ids = None):
+    def call(self, auth, slice_attribute_filter = None):
        # If we are not admin, make sure to only return our own slice
        # and sliver attributes.
         if 'admin' not in self.caller['roles']:
@@ -49,8 +50,18 @@ class GetSliceAttributes(Method):
             for slice in slices:
                 valid_slice_attribute_ids += slice['slice_attribute_ids']
 
-            slice_attribute_ids = set(slice_attribute_ids).intersection(valid_slice_attribute_ids)
-            if not slice_attribute_ids:
+            if not valid_slice_attribute_ids:
                 return []
 
-        return SliceAttributes(self.api, slice_attribute_ids).values()
+            if slice_attribute_filter is None:
+                slice_attribute_filter = valid_slice_attribute_ids
+
+        slice_attributes = SliceAttributes(self.api, slice_attribute_filter).values()
+
+        # Filter out slice attributes that are not viewable
+        if 'admin' not in self.caller['roles']:
+            slice_attributes = filter(lambda slice_attribute: \
+                                      slice_attribute['slice_attribute_id'] in valid_slice_attribute_ids,
+                                      slice_attributes)
+
+        return slice_attributes
index 6c870f2..478ff95 100644 (file)
@@ -1,13 +1,15 @@
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
+from PLC.Filter import Filter
 from PLC.Auth import Auth
 from PLC.Slices import Slice, Slices
 
 class GetSlices(Method):
     """
-    Return an array of structs containing details about slices. If
-    slice_id_or_name_list is specified, only the specified slices will
-    be queried.
+    Returns an array of structs containing details about slices. If
+    slice_filter is specified and is an array of slice identifiers or
+    slice names, or a struct of slice attributes, only slices matching
+    the filter will be returned.
 
     Users may only query slices of which they are members. PIs may
     query any of the slices at their sites. Admins may query any
@@ -20,13 +22,14 @@ class GetSlices(Method):
 
     accepts = [
         Auth(),
-        [Mixed(Slice.fields['slice_id'],
-               Slice.fields['name'])]
+        Mixed([Mixed(Slice.fields['slice_id'],
+                     Slice.fields['name'])],
+              Filter(Slice.fields))
         ]
 
     returns = [Slice.fields]
 
-    def call(self, auth, slice_id_or_name_list = None):
+    def call(self, auth, slice_filter = None):
        # If we are not admin, make sure to return only viewable
        # slices.
         if 'admin' not in self.caller['roles']:
@@ -40,10 +43,10 @@ class GetSlices(Method):
             if not valid_slice_ids:
                 return []
 
-            if not slice_id_or_name_list:
-                slice_id_or_name_list = valid_slice_ids
+            if slice_filter is None:
+                slice_filter = valid_slice_ids
 
-        slices = Slices(self.api, slice_id_or_name_list).values()
+        slices = Slices(self.api, slice_filter).values()
 
         # Filter out slices that are not viewable
         if 'admin' not in self.caller['roles']: