X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfatables%2Fcommands%2FDelete.py;h=b1dff42765a3f465b96b4fe0ed245640f99df3d9;hb=4a9e6751f9f396f463932133b9d62fc925a99ef6;hp=e59da62c1228a688acf035386bcc628c19ffaf29;hpb=f5194b0cf1858313770d6796411fec30190b5522;p=sfa.git diff --git a/sfatables/commands/Delete.py b/sfatables/commands/Delete.py index e59da62c..b1dff427 100644 --- a/sfatables/commands/Delete.py +++ b/sfatables/commands/Delete.py @@ -1,7 +1,8 @@ import os, time -from sfa.sfatables.command import Add +from sfatables.globals import sfatables_config +from sfatables.command import Command -class Add(Command): +class Delete(Command): options = [('-D','--delete')] help = 'Delete a rule from a chain' key='delete_rule' @@ -11,9 +12,21 @@ class Add(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.") + return + + 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)