2 from PLC.Faults import *
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.NodeGroups import NodeGroup, NodeGroups
6 from PLC.Auth import Auth
8 can_update = lambda (field, value): field in ['groupname','tagvalue']
10 class UpdateNodeGroup(Method):
12 Updates a custom node group.
14 Returns 1 if successful, faults otherwise.
19 nodegroup_fields = dict(filter(can_update, NodeGroup.fields.items()))
23 Mixed(NodeGroup.fields['nodegroup_id'],
24 NodeGroup.fields['groupname']),
28 returns = Parameter(int, '1 if successful')
30 def call(self, auth, nodegroup_id_or_name, nodegroup_fields):
31 nodegroup_fields = dict(filter(can_update, nodegroup_fields.items()))
33 # Get nodegroup information
34 nodegroups = NodeGroups(self.api, [nodegroup_id_or_name])
36 raise PLCInvalidArgument, "No such nodegroup %r"%nodegroup_id_or_name
37 nodegroup = nodegroups[0]
39 nodegroup.update(nodegroup_fields)
43 self.event_objects = {'NodeGroup': [nodegroup['nodegroup_id']]}
44 self.message = 'Node group %d updated: %s' % \
45 (nodegroup['nodegroup_id'], ", ".join(nodegroup_fields.keys()))