support returning nodenetwork_ids, which are identical to interface_ids
authorMarc Fiuczynski <mef@cs.princeton.edu>
Wed, 20 May 2009 21:43:38 +0000 (21:43 +0000)
committerMarc Fiuczynski <mef@cs.princeton.edu>
Wed, 20 May 2009 21:43:38 +0000 (21:43 +0000)
PLC/Legacy/NodeNetworks.py

index 8febd01..7fec8d3 100644 (file)
@@ -34,3 +34,57 @@ for legacyname in methods:
     path = "PLC.Methods."
     setattr(current_module,legacyname,v42legacy.make_class(legacyname,newname,path,v42rename,v43rename))
 
+# GetNodes update
+# first replace the call method so we can translate fields
+c = getattr(v42legacy.import_deep("PLC.Methods.GetNodes"),"GetNodes")
+# rename call to newcall so we can still invoke
+original = getattr(c,"call")
+setattr(c,"newcall",original)
+
+# 4.2 legacy support; update node_fields to include nodenetwork_ids
+from PLC.Parameter import Parameter, Mixed, python_type
+from PLC.Filter import Filter
+from PLC.Nodes import Node, Nodes
+
+node_fields = {}
+node_fields['nodenetwork_ids']=Parameter([int], "Legacy version of interface_ids")
+for k,v in Node.fields.iteritems():
+    node_fields[k]=v
+
+if False:
+    expected = node_fields['nodenetwork_ids']
+    print "type of nodenetwork_ids = %s" % python_type(node_fields['nodenetwork_ids'])
+    print Filter(node_fields).fields.keys()
+    print Filter(Node.fields).fields.keys()
+
+accepts = getattr(c,"accepts")
+arg0=accepts[0]
+arg1=Mixed([Mixed(Node.fields['node_id'],
+                  Node.fields['hostname'])],
+           Parameter(str,"hostname"),
+           Parameter(int,"node_id"),
+           Filter(node_fields))
+arg2=accepts[2]
+newaccepts = [arg0,arg1,arg2]
+setattr(c,"accepts",newaccepts)
+newreturns = [node_fields]
+setattr(c,"returns",newreturns)
+
+def GetNodesCall(self, auth, node_filter = None, return_fields = None):
+    global original
+    # convert nodenetwork_ids -> interface_ids
+    if node_filter <> None and \
+           node_filter.has_key('nodenetwork_ids') and \
+           not node_filter.has_key('interface_ids'):
+        node_filter['interface_ids']=node_filter['nodenetwork_ids']
+        
+    nodes = original(self,auth,node_filter,return_fields)
+
+    # add in a interface_ids -> nodenetwork_ids
+    for node in nodes:
+        if node.has_key('interface_ids'):
+            node['nodenetwork_ids']=node['interface_ids']
+
+    return nodes
+
+setattr(c,"call",GetNodesCall)