Merge from trunk
[plcapi.git] / trunk / PLC / Methods / DeleteNetworkMethod.py
diff --git a/trunk/PLC/Methods/DeleteNetworkMethod.py b/trunk/PLC/Methods/DeleteNetworkMethod.py
new file mode 100644 (file)
index 0000000..d0f982e
--- /dev/null
@@ -0,0 +1,35 @@
+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 DeleteNetworkMethod(Method):
+    """
+    Deletes a network method.
+
+    WARNING: This will cause the deletion of all network interfaces
+    that use this 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_methods = NetworkMethods(self.api, [name])
+        if not network_methods:
+            raise PLCInvalidArgument, "No such network method"
+        network_method = network_methods[0]
+
+        network_method.delete()
+
+        return 1