1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.NodeGroups import NodeGroup, NodeGroups
5 from PLC.Auth import Auth
7 can_update = lambda field_value: field_value[0] in ['groupname','value']
9 class UpdateNodeGroup(Method):
11 Updates a custom node group.
13 Returns 1 if successful, faults otherwise.
18 nodegroup_fields = dict(list(filter(can_update, list(NodeGroup.fields.items()))))
22 Mixed(NodeGroup.fields['nodegroup_id'],
23 NodeGroup.fields['groupname']),
27 returns = Parameter(int, '1 if successful')
29 def call(self, auth, nodegroup_id_or_name, nodegroup_fields):
30 nodegroup_fields = dict(list(filter(can_update, list(nodegroup_fields.items()))))
32 # Get nodegroup information
33 nodegroups = NodeGroups(self.api, [nodegroup_id_or_name])
35 raise PLCInvalidArgument("No such nodegroup %r"%nodegroup_id_or_name)
36 nodegroup = nodegroups[0]
38 nodegroup.update(nodegroup_fields)
42 self.event_objects = {'NodeGroup': [nodegroup['nodegroup_id']]}
43 self.message = 'Node group %d updated: %s' % \
44 (nodegroup['nodegroup_id'], ", ".join(list(nodegroup_fields.keys())))