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