1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Auth import Auth
6 from PLC.NodeGroups import NodeGroup, NodeGroups
7 from PLC.NodeTagTypes import NodeTagType, NodeTagTypes
8 from PLC.NodeTags import NodeTag, NodeTags
10 can_update = lambda (field, value): field in NodeGroup.fields.keys() and field != NodeGroup.primary_field
12 class AddNodeGroup(Method):
14 Adds a new node group. Any values specified in nodegroup_fields
15 are used, otherwise defaults are used.
17 Returns the new nodegroup_id (> 0) if successful, faults otherwise.
22 nodegroup_fields = dict(filter(can_update, NodeGroup.fields.items()))
26 NodeGroup.fields['groupname'],
27 Mixed(NodeTagType.fields['node_tag_type_id'],
28 NodeTagType.fields['tagname']),
29 NodeTag.fields['tagvalue'],
32 returns = Parameter(int, 'New nodegroup_id (> 0) if successful')
35 def call(self, auth, groupname, node_tag_type_id_or_tagname, tagvalue):
37 tag_types = NodeTagTypes (self.api,node_tag_type_id_or_tagname)
39 raise PLCInvalidArgument, "No such tag type %r"%node_tag_type_id_or_tagname
42 nodegroup_fields = { 'groupname' : groupname,
43 'node_tag_type_id' : tag_type['node_tag_type_id'],
44 'tagvalue' : tagvalue }
45 nodegroup = NodeGroup(self.api, nodegroup_fields)
49 self.event_objects = {'NodeGroup': [nodegroup['nodegroup_id']]}
50 self.message = 'Node group %d created' % nodegroup['nodegroup_id']
52 return nodegroup['nodegroup_id']