- removed 'Adm' prefix
[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 PasswordAuth
6
7 class UpdateNodeGroup(Method):
8     """
9     Updates a custom node group.
10      
11     Returns 1 if successful, faults otherwise.
12     """
13
14     roles = ['admin']
15
16     accepts = [
17         PasswordAuth(),
18         Mixed(NodeGroup.fields['nodegroup_id'],
19               NodeGroup.fields['name']),
20         NodeGroup.fields['name'],
21         NodeGroup.fields['description']
22         ]
23
24     returns = Parameter(int, '1 if successful')
25
26     def call(self, auth, nodegroup_id_or_name, name, description):
27         # Get nodegroup information
28         nodegroups = NodeGroups(self.api, [nodegroup_id_or_name])
29         if not nodegroups:
30             raise PLCInvalidArgument, "No such nodegroup"
31
32         nodegroup = nodegroups.values()[0]
33         
34         # Modify node group
35         update_fields = {
36             'name': name,
37             'description': description
38             }
39
40         nodegroup.update(update_fields)
41         nodegroup.sync()
42
43         return 1