3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.Auth import Auth
8 from PLC.NodeGroups import NodeGroup, NodeGroups
9 from PLC.TagTypes import TagType, TagTypes
10 from PLC.NodeTags import NodeTag, NodeTags
12 can_update = lambda (field, value): field in NodeGroup.fields.keys() and field != NodeGroup.primary_field
14 class AddNodeGroup(Method):
16 Adds a new node group. Any values specified in nodegroup_fields
17 are used, otherwise defaults are used.
19 Returns the new nodegroup_id (> 0) if successful, faults otherwise.
24 nodegroup_fields = dict(filter(can_update, NodeGroup.fields.items()))
28 NodeGroup.fields['groupname'],
29 Mixed(TagType.fields['tag_type_id'],
30 TagType.fields['tagname']),
31 NodeTag.fields['value'],
34 returns = Parameter(int, 'New nodegroup_id (> 0) if successful')
37 def call(self, auth, groupname, tag_type_id_or_tagname, value):
39 tag_types = TagTypes (self.api,[tag_type_id_or_tagname])
41 raise PLCInvalidArgument, "No such tag type %r"%tag_type_id_or_tagname
44 nodegroup_fields = { 'groupname' : groupname,
45 'tag_type_id' : tag_type['tag_type_id'],
47 nodegroup = NodeGroup(self.api, nodegroup_fields)
51 self.event_objects = {'NodeGroup': [nodegroup['nodegroup_id']]}
52 self.message = 'Node group %d created' % nodegroup['nodegroup_id']
54 return nodegroup['nodegroup_id']