3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.NodeGroups import NodeGroup, NodeGroups
7 from PLC.Auth import Auth
9 can_update = lambda (field, value): field in ['groupname','value']
11 class UpdateNodeGroup(Method):
13 Updates a custom node group.
15 Returns 1 if successful, faults otherwise.
20 nodegroup_fields = dict(filter(can_update, NodeGroup.fields.items()))
24 Mixed(NodeGroup.fields['nodegroup_id'],
25 NodeGroup.fields['groupname']),
29 returns = Parameter(int, '1 if successful')
31 def call(self, auth, nodegroup_id_or_name, nodegroup_fields):
32 nodegroup_fields = dict(filter(can_update, nodegroup_fields.items()))
34 # Get nodegroup information
35 nodegroups = NodeGroups(self.api, [nodegroup_id_or_name])
37 raise PLCInvalidArgument, "No such nodegroup %r"%nodegroup_id_or_name
38 nodegroup = nodegroups[0]
40 nodegroup.update(nodegroup_fields)
44 self.event_objects = {'NodeGroup': [nodegroup['nodegroup_id']]}
45 self.message = 'Node group %d updated: %s' % \
46 (nodegroup['nodegroup_id'], ", ".join(nodegroup_fields.keys()))