From a5650abb6d575de2f696a934d52468992ac9f1e9 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Fri, 1 May 2020 16:46:06 +0200 Subject: nat: T2198: migrate to common template for source/destination NAT --- src/conf_mode/nat.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/conf_mode/nat.py b/src/conf_mode/nat.py index 538999f9a..b4e8c2053 100755 --- a/src/conf_mode/nat.py +++ b/src/conf_mode/nat.py @@ -19,6 +19,7 @@ from sys import exit from netifaces import interfaces from vyos.config import Config +from vyos.util import call from vyos.template import render from vyos import ConfigError @@ -27,8 +28,7 @@ default_config_data = { 'destination': [] } -nat_source_config = '/tmp/nat_source' -nat_destination_config = '/tmp/nat_destination' +iptables_nat_config = '/tmp/iptables_nat_config' def parse_source_destination(conf, source_dest): """ Common wrapper to read in both NAT source and destination CLI """ @@ -128,12 +128,14 @@ def generate(nat): if not nat: return None - render(nat_source_config, 'nat/nat-source.tmpl', nat, trim_blocks=True) - render(nat_destination_config, 'nat/nat-destination.tmpl', nat, trim_blocks=True) - + render(iptables_nat_config, 'nat/iptables-restore.tmpl', nat, trim_blocks=True) return None def apply(nat): + if not nat: + return None + + call(f'iptables-restore --test < {iptables_nat_config}') return None -- cgit v1.2.3