List<SimpleIptablesRule> correct = checkMatchingRules(matches, protocol);
if (correct.isEmpty()) {
String ruleSpec = buildRuleSpec(protocol);
Command command = SimpleIptablesRules.buildCommand(transport, chain);
command.addLiteral("-A").addLiteral(ruleSpec);
command.addLiteral("-m").addLiteral("comment");
command.addLiteral("--comment").addQuoted(comment);
target.executeCommand(command);
} else {
log.info("Found existing rule: " + Joiner.on("\n").join(matches));
}
}
if (OpsContext.isDelete()) {
if (!matches.isEmpty()) {
for (SimpleIptablesRule rule : matches) {
log.info("Deleting rule: " + rule);
String deleteRuleSpec = rule.convertToDeleteSpec();
Command command = SimpleIptablesRules.buildCommand(transport, chain);
command.addLiteral(deleteRuleSpec);
target.executeCommand(command);
}
}
}
}