843c7fe01bcf59576c7d69b07894fe47ba9e08ef
[plcapi.git] / PLC / Methods / DeleteKeyType.py
1 # $Id$
2 from PLC.Faults import *
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.KeyTypes import KeyType, KeyTypes
6 from PLC.Auth import Auth
7
8 class DeleteKeyType(Method):
9     """
10     Deletes a key type.
11
12     WARNING: This will cause the deletion of all keys of this type.
13
14     Returns 1 if successful, faults otherwise.
15     """
16
17     roles = ['admin']
18
19     accepts = [
20         Auth(),
21         KeyType.fields['key_type']
22         ]
23
24     returns = Parameter(int, '1 if successful')
25     
26     
27     def call(self, auth, name):
28         key_types = KeyTypes(self.api, [name])
29         if not key_types:
30             raise PLCInvalidArgument, "No such key type"
31         key_type = key_types[0]
32
33         key_type.delete()
34
35         return 1