patch our local xmlrpc lib (for supporting allow_none=True) with php5.4
[plcapi.git] / PLC / Methods / DeleteInitScript.py
1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.InitScripts import InitScript, InitScripts
5 from PLC.Auth import Auth
6
7 class DeleteInitScript(Method):
8     """
9     Deletes an existing initscript.
10
11     Returns 1 if successful, faults otherwise.
12     """
13
14     roles = ['admin']
15
16     accepts = [
17         Auth(),
18         Mixed(InitScript.fields['initscript_id'],
19               InitScript.fields['name']),
20         ]
21
22     returns = Parameter(int, '1 if successful')
23
24
25     def call(self, auth, initscript_id_or_name):
26         initscripts = InitScripts(self.api, [initscript_id_or_name])
27         if not initscripts:
28             raise PLCInvalidArgument, "No such initscript"
29
30         initscript = initscripts[0]
31         initscript.delete()
32         self.event_objects = {'InitScript':  [initscript['initscript_id']]}
33
34         return 1