Merge from trunk
[plcapi.git] / trunk / PLC / Methods / DeleteKeyType.py
diff --git a/trunk/PLC/Methods/DeleteKeyType.py b/trunk/PLC/Methods/DeleteKeyType.py
new file mode 100644 (file)
index 0000000..e09e5c5
--- /dev/null
@@ -0,0 +1,34 @@
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.KeyTypes import KeyType, KeyTypes
+from PLC.Auth import Auth
+
+class DeleteKeyType(Method):
+    """
+    Deletes a key type.
+
+    WARNING: This will cause the deletion of all keys of this type.
+
+    Returns 1 if successful, faults otherwise.
+    """
+
+    roles = ['admin']
+
+    accepts = [
+        Auth(),
+        KeyType.fields['key_type']
+        ]
+
+    returns = Parameter(int, '1 if successful')
+    
+    
+    def call(self, auth, name):
+        key_types = KeyTypes(self.api, [name])
+        if not key_types:
+            raise PLCInvalidArgument, "No such key type"
+        key_type = key_types[0]
+
+        key_type.delete()
+
+        return 1