move sfa package import inside of __init__()
[plcapi.git] / PLC / Methods / DeleteInitScript.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.InitScripts import InitScript, InitScripts
7 from PLC.Auth import Auth
8
9 class DeleteInitScript(Method):
10     """
11     Deletes an existing initscript.  
12     
13     Returns 1 if successful, faults otherwise. 
14     """
15
16     roles = ['admin']
17
18     accepts = [
19         Auth(),
20         Mixed(InitScript.fields['initscript_id'],
21               InitScript.fields['name']),
22         ]
23
24     returns = Parameter(int, '1 if successful')
25     
26
27     def call(self, auth, initscript_id_or_name):
28         initscripts = InitScripts(self.api, [initscript_id_or_name])
29         if not initscripts:
30             raise PLCInvalidArgument, "No such initscript"
31
32         initscript = initscripts[0]
33         initscript.delete()
34         self.event_objects = {'InitScript':  [initscript['initscript_id']]}
35
36         return 1