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