nodegroups work and are getting tested as part of the plcapi test
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 29 May 2008 15:24:14 +0000 (15:24 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 29 May 2008 15:24:14 +0000 (15:24 +0000)
PLC/Methods/AddNodeGroup.py
PLC/Methods/UpdateNodeGroup.py

index 9555f73..6b0c94d 100644 (file)
@@ -1,9 +1,12 @@
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
-from PLC.NodeGroups import NodeGroup, NodeGroups
 from PLC.Auth import Auth
 
+from PLC.NodeGroups import NodeGroup, NodeGroups
+from PLC.NodeTagTypes import NodeTagType, NodeTagTypes
+from PLC.NodeTags import NodeTag, NodeTags
+
 can_update = lambda (field, value): field in NodeGroup.fields.keys() and field != NodeGroup.primary_field
 
 class AddNodeGroup(Method):
@@ -20,14 +23,25 @@ class AddNodeGroup(Method):
 
     accepts = [
         Auth(),
-        nodegroup_fields
+        NodeGroup.fields['groupname'],
+        Mixed(NodeTagType.fields['node_tag_type_id'],
+              NodeTagType.fields['tagname']),
+        NodeTag.fields['tagvalue'],
         ]
 
     returns = Parameter(int, 'New nodegroup_id (> 0) if successful')
 
 
-    def call(self, auth, nodegroup_fields):
-        nodegroup_fields = dict([f for f in nodegroup_fields.items() if can_update(f)])
+    def call(self, auth, groupname, node_tag_type_id_or_tagname, tagvalue):
+        # locate tag type
+        tag_types = NodeTagTypes (self.api,node_tag_type_id_or_tagname)
+        if not(tag_types):
+            raise PLCInvalidArgument, "No such tag type %r"%node_tag_type_id_or_tagname
+        tag_type=tag_types[0]
+
+        nodegroup_fields = { 'groupname' : groupname,
+                             'node_tag_type_id' : tag_type['node_tag_type_id'],
+                             'tagvalue' : tagvalue }
         nodegroup = NodeGroup(self.api, nodegroup_fields)
         nodegroup.sync()
 
index d695012..4271085 100644 (file)
@@ -4,10 +4,7 @@ from PLC.Parameter import Parameter, Mixed
 from PLC.NodeGroups import NodeGroup, NodeGroups
 from PLC.Auth import Auth
 
-related_fields = NodeGroup.related_fields.keys()
-can_update = lambda (field, value): field in \
-             ['groupname', 'tagname','tagvalue'] + \
-            related_fields
+can_update = lambda (field, value): field in ['groupname','tagvalue'] 
 
 class UpdateNodeGroup(Method):
     """
@@ -18,7 +15,7 @@ class UpdateNodeGroup(Method):
 
     roles = ['admin']
 
-    nodegroup_fields = dict(filter(can_update, NodeGroup.fields.items() + NodeGroup.related_fields.items()))
+    nodegroup_fields = dict(filter(can_update, NodeGroup.fields.items())
 
     accepts = [
         Auth(),
@@ -35,15 +32,9 @@ class UpdateNodeGroup(Method):
        # Get nodegroup information
        nodegroups = NodeGroups(self.api, [nodegroup_id_or_name])
        if not nodegroups:
-            raise PLCInvalidArgument, "No such nodegroup"
+            raise PLCInvalidArgument, "No such nodegroup %r"%nodegroup_id_or_name
        nodegroup = nodegroups[0]
 
-       # Make requested associations
-        for field in related_fields:
-            if field in nodegroup_fields:
-                nodegroup.associate(auth, field, nodegroup_fields[field])
-                nodegroup_fields.pop(field)
-       
        nodegroup.update(nodegroup_fields)
         nodegroup.sync()