make GetNodeNetworks consistent with all other Get functions
authorMark Huang <mlhuang@cs.princeton.edu>
Mon, 16 Oct 2006 19:13:13 +0000 (19:13 +0000)
committerMark Huang <mlhuang@cs.princeton.edu>
Mon, 16 Oct 2006 19:13:13 +0000 (19:13 +0000)
PLC/Methods/AdmGetAllNodeNetworks.py
PLC/Methods/GetNodeNetworks.py

index 291e19a..fc40ad6 100644 (file)
@@ -1,8 +1,46 @@
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.Nodes import Node, Nodes
+from PLC.NodeNetworks import NodeNetwork, NodeNetworks
+from PLC.Auth import PasswordAuth
 from PLC.Methods.GetNodeNetworks import GetNodeNetworks
 
 class AdmGetAllNodeNetworks(GetNodeNetworks):
     """
-    Deprecated. See GetNodeNetworks.
+    Deprecated. Functionality can be implemented with GetNodes and
+    GetNodeNetworks.
     """
 
     status = "deprecated"
+
+    roles = ['admin', 'pi', 'user', 'tech']
+
+    accepts = [
+        PasswordAuth(),
+        Mixed(Node.fields['node_id'],
+              Node.fields['hostname'])
+        ]
+
+    returns = [NodeNetwork.fields]
+
+    def call(self, auth, node_id_or_hostname):
+        # Authenticated function
+        assert self.caller is not None
+
+        # Get node information
+        nodes = Nodes(self.api, [node_id_or_hostname]).values()
+       if not nodes:
+            raise PLCInvalidArgument, "No such node"
+       node = nodes[0]
+
+       # Get node networks for this node
+        if node['nodenetwork_ids']:
+            nodenetworks = NodeNetworks(self.api, node['nodenetwork_ids']).values()
+        else:
+            nodenetworks = []
+
+        # Cast from NodeNetwork to real dict
+        nodenetworks = [dict(nodenetwork) for nodenetwork in nodenetworks]
+               
+       return nodenetworks
index 199f9bd..1bc6ef2 100644 (file)
@@ -2,42 +2,29 @@ from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
 from PLC.NodeNetworks import NodeNetwork, NodeNetworks
-from PLC.Nodes import Node, Nodes
 from PLC.Auth import PasswordAuth
 
 class GetNodeNetworks(Method):
     """
-    Returns all the networks this node is connected to, as an array of
-    structs.
+    Return an array of structs contain details about node network
+    interfaces. If nodenetwork_id_or_hostname_list is specified, only
+    the specified node network interfaces will be queried.
     """
 
     roles = ['admin', 'pi', 'user', 'tech']
 
     accepts = [
         PasswordAuth(),
-        Mixed(Node.fields['node_id'],
-              Node.fields['hostname'])
+        [Mixed(NodeNetwork.fields['nodenetwork_id'],
+               NodeNetwork.fields['hostname'])]
         ]
 
     returns = [NodeNetwork.fields]
 
-    def call(self, auth, node_id_or_hostname):
-        # Authenticated function
-        assert self.caller is not None
+    def call(self, auth, nodenetwork_id_or_hostname_list = None):
+        nodenetworks = NodeNetworks(self.api, nodenetwork_id_or_hostname_list).values()
 
-        # Get node information
-        nodes = Nodes(self.api, [node_id_or_hostname]).values()
-       if not nodes:
-            raise PLCInvalidArgument, "No such node"
-       node = nodes[0]
-
-       # Get node networks for this node
-        if node['nodenetwork_ids']:
-               nodenetworks = NodeNetworks(self.api, node['nodenetwork_ids']).values()
-        else:
-               nodenetworks = []
-
-       # Turn each node into a real dict.
-        nodenetworks = [dict(nodenetwork.items()) for nodenetwork in nodenetworks]
+        # Cast from NodeNetwork to real dict
+        nodenetworks = [dict(nodenetwork) for nodenetwork in nodenetworks]
                
        return nodenetworks