Added Delete command
Sapan Bhatia [Tue, 15 Sep 2009 15:59:34 +0000 (15:59 +0000)]
sfatables/commands/Delete.py
sfatables/commands/List.py
sfatables/xmlrule.py

index cac5445..d90c583 100644 (file)
@@ -1,4 +1,5 @@
 import os, time
+from sfatables.globals import *
 from sfatables.command import Command
 
 class Delete(Command):
@@ -11,9 +12,20 @@ class Delete(Command):
     def __init__(self):
         return
 
-    def call(self):
-        # Override this function
-        return True
+    def call(self, command_options, match_options, target_options):
+
+        if (len(command_options.args)<2):
+            print "Please specify the chain and the rule number to delete, e.g. sfatables -D INCOMING 1"
+
+        chain = command_options.args[0]
+
+
+        rule_number = command_options.args[1]
+        chain_dir = sfatables_config + "/" + chain
+
+        match_path = chain_dir + "/" + "sfatables-%s-match"%rule_number
+        target_path = chain_dir + "/" + "sfatables-%s-target"%rule_number
+
+        os.unlink(match_path)
+        os.unlink(target_path)
 
-    def __call__(self, option, opt_str, value, parser, *args, **kwargs):
-        return self.call(option)
index e3c124e..1c383a1 100644 (file)
@@ -16,7 +16,6 @@ class List(Command):
     def __init__(self):
         return
 
-
     def get_info(self, type, xmlextension_path):
         xmldoc = libxml2.parseFile(xmlextension_path)
         p = xmldoc.xpathNewContext()
index 258e75a..b0f6fde 100644 (file)
@@ -1,4 +1,5 @@
 import libxml2
+import libxslt
 from sfatables.globals import *
 
 class XMLRule:
@@ -18,11 +19,11 @@ class XMLRule:
         filepath = 'processors/' + processor
         # XXX
 
-        styledoc = libxml2.parseFile(processor)
+        styledoc = libxml2.parseFile(filepath)
         style = libxslt.parseStylesheetDoc(styledoc)
         doc = libxml2.parseDoc(rspec)
         result = style.applyStylesheet(doc, None)
-        processed_result = style.saveResultToString(result, 0)
+        stylesheet_result = style.saveResultToString(result)
         style.freeStylesheet()
         doc.freeDoc()
         result.freeDoc()