2 from PLC.Faults import *
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.Auth import Auth
7 from PLC.NodeGroups import NodeGroup, NodeGroups
8 from PLC.TagTypes import TagType, TagTypes
9 from PLC.NodeTags import NodeTag, NodeTags
11 can_update = lambda (field, value): field in NodeGroup.fields.keys() and field != NodeGroup.primary_field
13 class AddNodeGroup(Method):
15 Adds a new node group. Any values specified in nodegroup_fields
16 are used, otherwise defaults are used.
18 Returns the new nodegroup_id (> 0) if successful, faults otherwise.
23 nodegroup_fields = dict(filter(can_update, NodeGroup.fields.items()))
27 NodeGroup.fields['groupname'],
28 Mixed(TagType.fields['tag_type_id'],
29 TagType.fields['tagname']),
30 NodeTag.fields['value'],
33 returns = Parameter(int, 'New nodegroup_id (> 0) if successful')
36 def call(self, auth, groupname, tag_type_id_or_tagname, value):
38 tag_types = TagTypes (self.api,[tag_type_id_or_tagname])
40 raise PLCInvalidArgument, "No such tag type %r"%tag_type_id_or_tagname
43 nodegroup_fields = { 'groupname' : groupname,
44 'tag_type_id' : tag_type['tag_type_id'],
46 nodegroup = NodeGroup(self.api, nodegroup_fields)
50 self.event_objects = {'NodeGroup': [nodegroup['nodegroup_id']]}
51 self.message = 'Node group %d created' % nodegroup['nodegroup_id']
53 return nodegroup['nodegroup_id']