svn keywords
[plcapi.git] / PLC / Methods / AddNodeGroup.py
index bdde7fe..88210c1 100644 (file)
@@ -1,11 +1,15 @@
+# $Id$
+# $URL$
 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
 
-can_update = lambda (field, value): field in \
-             ['name', 'description']
+from PLC.NodeGroups import NodeGroup, NodeGroups
+from PLC.TagTypes import TagType, TagTypes
+from PLC.NodeTags import NodeTag, NodeTags
+
+can_update = lambda (field, value): field in NodeGroup.fields.keys() and field != NodeGroup.primary_field
 
 class AddNodeGroup(Method):
     """
@@ -21,19 +25,30 @@ class AddNodeGroup(Method):
 
     accepts = [
         Auth(),
-        nodegroup_fields
+        NodeGroup.fields['groupname'],
+        Mixed(TagType.fields['tag_type_id'],
+              TagType.fields['tagname']),
+        NodeTag.fields['value'],
         ]
 
     returns = Parameter(int, 'New nodegroup_id (> 0) if successful')
 
 
-    def call(self, auth, nodegroup_fields):
-        nodegroup_fields = dict(filter(can_update, nodegroup_fields.items()))
+    def call(self, auth, groupname, tag_type_id_or_tagname, value):
+        # locate tag type
+        tag_types = TagTypes (self.api,[tag_type_id_or_tagname])
+        if not(tag_types):
+            raise PLCInvalidArgument, "No such tag type %r"%tag_type_id_or_tagname
+        tag_type=tag_types[0]
+
+        nodegroup_fields = { 'groupname' : groupname,
+                             'tag_type_id' : tag_type['tag_type_id'],
+                             'value' : value }
         nodegroup = NodeGroup(self.api, nodegroup_fields)
         nodegroup.sync()
 
        # Logging variables
-       self.object_ids = [nodegroup['nodegroup_id']]
+       self.event_objects = {'NodeGroup': [nodegroup['nodegroup_id']]}
        self.message = 'Node group %d created' % nodegroup['nodegroup_id']
  
         return nodegroup['nodegroup_id']