Merge from trunk
[plcapi.git] / trunk / PLC / Methods / AddKeyType.py
diff --git a/trunk/PLC/Methods/AddKeyType.py b/trunk/PLC/Methods/AddKeyType.py
new file mode 100644 (file)
index 0000000..b3690a8
--- /dev/null
@@ -0,0 +1,29 @@
+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 AddKeyType(Method):
+    """
+    Adds a new key 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_type = KeyType(self.api)
+        key_type['key_type'] = name
+        key_type.sync(insert = True)
+
+        return 1