680e718608f9547ebcf75cd743faf313971f9c41
[plcapi.git] / PLC / Methods / DeleteNodeGroup.py
1 # $Id$
2 # $URL$
3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.Auth import Auth
7 from PLC.NodeGroups import NodeGroup, NodeGroups
8
9 class DeleteNodeGroup(Method):
10     """
11     Delete an existing Node Group.
12
13     ins may delete any node group
14
15     Returns 1 if successful, faults otherwise.
16     """
17
18     roles = ['admin']
19
20     accepts = [
21         Auth(),
22         Mixed(NodeGroup.fields['nodegroup_id'],
23               NodeGroup.fields['groupname'])
24         ]
25
26     returns = Parameter(int, '1 if successful')
27
28
29     def call(self, auth, node_group_id_or_name):
30         # Get account information
31         nodegroups = NodeGroups(self.api, [node_group_id_or_name])
32         if not nodegroups:
33             raise PLCInvalidArgument, "No such node group"
34
35         nodegroup = nodegroups[0]
36
37         nodegroup.delete()
38
39         # Logging variables
40         self.event_objects = {'NodeGroup': [nodegroup['nodegroup_id']]}
41         self.message  = 'Node group %d deleted' % nodegroup['nodegroup_id']
42
43         return 1