From a5d87c50303cb3b022eb7da1813cee5f2a02d2f0 Mon Sep 17 00:00:00 2001 From: Marc Fiuczynski Date: Fri, 22 May 2009 03:27:01 +0000 Subject: [PATCH] Implemented legacy support for GetNodes using proper inheritance rather than behind the scenes python trickery. --- PLC/Methods/GetNodes.py | 33 ++++++++++++++++++++++++- PLC/__init__.py | 1 - PLC/v42LegacyNodes.py | 54 ----------------------------------------- 3 files changed, 32 insertions(+), 56 deletions(-) delete mode 100644 PLC/v42LegacyNodes.py diff --git a/PLC/Methods/GetNodes.py b/PLC/Methods/GetNodes.py index 878f327..d36b3ca 100644 --- a/PLC/Methods/GetNodes.py +++ b/PLC/Methods/GetNodes.py @@ -7,7 +7,7 @@ from PLC.Nodes import Node, Nodes from PLC.Persons import Person, Persons from PLC.Auth import Auth -class GetNodes(Method): +class v43GetNodes(Method): """ Returns an array of structs containing details about nodes. If node_filter is specified and is an array of node identifiers or @@ -82,3 +82,34 @@ class GetNodes(Method): del node[field] return nodes + +node_fields = Node.fields.copy() +node_fields['nodenetwork_ids']=Parameter([int], "Legacy version of interface_ids") + +class v42GetNodes(v43GetNodes): + accepts = [ + Auth(), + Mixed([Mixed(Node.fields['node_id'], + Node.fields['hostname'])], + Parameter(str,"hostname"), + Parameter(int,"node_id"), + Filter(node_fields)), + Parameter([str], "List of fields to return", nullok = True), + ] + returns = [node_fields] + + def call(self, auth, node_filter = None, return_fields = None): + # 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 = v43GetNodes.call(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 + +GetNodes = v42GetNodes + diff --git a/PLC/__init__.py b/PLC/__init__.py index 3e35b76..7102749 100644 --- a/PLC/__init__.py +++ b/PLC/__init__.py @@ -49,7 +49,6 @@ Table TagTypes v42LegacyNodeNetworkSettings v42LegacyNodeNetworks -v42LegacyNodes v42Legacy v42LegacyTypes """.split() diff --git a/PLC/v42LegacyNodes.py b/PLC/v42LegacyNodes.py deleted file mode 100644 index a36d750..0000000 --- a/PLC/v42LegacyNodes.py +++ /dev/null @@ -1,54 +0,0 @@ -# $Id: $ - -from PLC.Parameter import Parameter, Mixed, python_type -from PLC.Filter import Filter -from PLC.Nodes import Node, Nodes - -def import_deep(name): - mod = __import__(name) - components = name.split('.') - for comp in components[1:]: - mod = getattr(mod, comp) - return mod - -# GetNodes update -c = getattr(import_deep("PLC.Methods.GetNodes"),"GetNodes") -# rename call to __origcall so we can still invoke -original = getattr(c,"call") -setattr(c,"__origcall",original) - -node_fields = {} -node_fields['nodenetwork_ids']=Parameter([int], "Legacy version of interface_ids") -for k,v in Node.fields.iteritems(): - node_fields[k]=v - -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): - # 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 = self.__origcall(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) -- 2.43.0