v42 backwards compatibility to make scripts like gen-sites-xml.py etc. work
authorMarc Fiuczynski <mef@cs.princeton.edu>
Tue, 2 Jun 2009 14:29:46 +0000 (14:29 +0000)
committerMarc Fiuczynski <mef@cs.princeton.edu>
Tue, 2 Jun 2009 14:29:46 +0000 (14:29 +0000)
PLC/Methods/GetNodeGroups.py

index 707a952..0c2c79c 100644 (file)
@@ -6,7 +6,7 @@ from PLC.Filter import Filter
 from PLC.Auth import Auth
 from PLC.NodeGroups import NodeGroup, NodeGroups
 
-class GetNodeGroups(Method):
+class v43GetNodeGroups(Method):
     """
     Returns an array of structs containing details about node groups.
     If nodegroup_filter is specified and is an array of node group
@@ -29,3 +29,54 @@ class GetNodeGroups(Method):
   
     def call(self, auth, nodegroup_filter = None, return_fields = None):
        return NodeGroups(self.api, nodegroup_filter, return_fields)
+
+
+nodegroup_fields = NodeGroup.fields.copy()
+nodegroup_fields['name'] = Parameter(str, "Legacy version of groupname", max = 50),
+
+class v42GetNodeGroups(v43GetNodeGroups):
+    """
+    Legacy wrapper for v42GetNodeGroups.
+    """
+
+    accepts = [
+        Auth(),
+        Mixed([Mixed(NodeGroup.fields['nodegroup_id'],
+                     NodeGroup.fields['groupname'])],
+              Filter(nodegroup_fields)),
+        Parameter([str], "List of fields to return", nullok = True)
+        ]
+
+    returns = [nodegroup_fields]
+  
+    def call(self, auth, nodegroup_filter = None, return_fields = None):
+        # convert name -> groupname in both filters
+        if isinstance(nodegroup_filter, dict):
+            if nodegroup_filter.has_key('name'):
+                groupname = nodegroup_filter.pop('name')
+                if not nodegroup_filter.has_key('groupname'):
+                    nodegroup_filter['groupname']=groupname
+
+        if isinstance(return_fields, list):
+            if 'name' in return_fields:
+                return_fields.remove('name')
+                if 'groupname' not in return_fields:
+                    return_fields.append('groupname')
+
+        nodegroups = NodeGroups(self.api, nodegroup_filter, return_fields)
+        # if groupname is present, then create a name mapping
+        for nodegroup in nodegroups:
+            if nodegroup.has_key('groupname'):
+                nodegroup['name']=nodegroup['groupname']
+        return nodegroups
+
+class GetNodeGroups(v42GetNodeGroups):
+    """
+    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. If return_fields
+    is specified, only the specified details will be returned.
+    """
+
+    pass