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