blind 2to3
[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 Auth
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         Auth(),
20         KeyType.fields['key_type']
21         ]
22
23     returns = Parameter(int, '1 if successful')
24
25
26     def call(self, auth, name):
27         key_types = KeyTypes(self.api, [name])
28         if not key_types:
29             raise PLCInvalidArgument("No such key type")
30         key_type = key_types[0]
31
32         key_type.delete()
33
34         return 1