get rid of svn keywords once and for good
[plcapi.git] / PLC / Methods / UpdateNodeGroup.py
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
6
7 can_update = lambda (field, value): field in ['groupname','value']
8
9 class UpdateNodeGroup(Method):
10     """
11     Updates a custom node group.
12
13     Returns 1 if successful, faults otherwise.
14     """
15
16     roles = ['admin']
17
18     nodegroup_fields = dict(filter(can_update, NodeGroup.fields.items()))
19
20     accepts = [
21         Auth(),
22         Mixed(NodeGroup.fields['nodegroup_id'],
23               NodeGroup.fields['groupname']),
24         nodegroup_fields
25         ]
26
27     returns = Parameter(int, '1 if successful')
28
29     def call(self, auth, nodegroup_id_or_name, nodegroup_fields):
30         nodegroup_fields = dict(filter(can_update, nodegroup_fields.items()))
31
32         # Get nodegroup information
33         nodegroups = NodeGroups(self.api, [nodegroup_id_or_name])
34         if not nodegroups:
35             raise PLCInvalidArgument, "No such nodegroup %r"%nodegroup_id_or_name
36         nodegroup = nodegroups[0]
37
38         nodegroup.update(nodegroup_fields)
39         nodegroup.sync()
40
41         # Logging variables
42         self.event_objects = {'NodeGroup': [nodegroup['nodegroup_id']]}
43         self.message = 'Node group %d updated: %s' % \
44                 (nodegroup['nodegroup_id'], ", ".join(nodegroup_fields.keys()))
45         return 1