Merge from trunk
[plcapi.git] / trunk / PLC / Methods / AddNetworkMethod.py
diff --git a/trunk/PLC/Methods/AddNetworkMethod.py b/trunk/PLC/Methods/AddNetworkMethod.py
new file mode 100644 (file)
index 0000000..11f3845
--- /dev/null
@@ -0,0 +1,29 @@
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.NetworkMethods import NetworkMethod, NetworkMethods
+from PLC.Auth import Auth
+
+class AddNetworkMethod(Method):
+    """
+    Adds a new network method.
+
+    Returns 1 if successful, faults otherwise.
+    """
+
+    roles = ['admin']
+
+    accepts = [
+        Auth(),
+        NetworkMethod.fields['method']
+        ]
+
+    returns = Parameter(int, '1 if successful')
+
+
+    def call(self, auth, name):
+        network_method = NetworkMethod(self.api)
+        network_method['method'] = name
+        network_method.sync(insert = True)
+
+        return 1