From b5db9395ed576ef97b1692ca66c00900c532d6a1 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Wed, 19 Jun 2024 20:16:05 -0500 Subject: migration: T6007: convert all migration scripts to load as module (cherry picked from commit 26740a8d583f64dc0a27b59dd4ae303056972c0b) --- src/migration-scripts/firewall/15-to-16 | 39 +++++++++------------------------ 1 file changed, 10 insertions(+), 29 deletions(-) mode change 100755 => 100644 src/migration-scripts/firewall/15-to-16 (limited to 'src/migration-scripts/firewall/15-to-16') diff --git a/src/migration-scripts/firewall/15-to-16 b/src/migration-scripts/firewall/15-to-16 old mode 100755 new mode 100644 index 28df1256e..8e28bba6f --- a/src/migration-scripts/firewall/15-to-16 +++ b/src/migration-scripts/firewall/15-to-16 @@ -18,39 +18,20 @@ # from: set system conntrack timeout .. # to: set firewall global-options timeout ... -from sys import argv -from sys import exit - from vyos.configtree import ConfigTree -if len(argv) < 2: - print("Must specify file name!") - exit(1) - -file_name = argv[1] - -with open(file_name, 'r') as f: - config_file = f.read() - firewall_base = ['firewall', 'global-options'] conntrack_base = ['system', 'conntrack', 'timeout'] -config = ConfigTree(config_file) - -if not config.exists(conntrack_base): - # Nothing to do - exit(0) -for protocol in ['icmp', 'tcp', 'udp', 'other']: - if config.exists(conntrack_base + [protocol]): - if not config.exists(firewall_base + ['timeout']): - config.set(firewall_base + ['timeout']) +def migrate(config: ConfigTree) -> None: + if not config.exists(conntrack_base): + # Nothing to do + return - config.copy(conntrack_base + [protocol], firewall_base + ['timeout', protocol]) - config.delete(conntrack_base + [protocol]) + for protocol in ['icmp', 'tcp', 'udp', 'other']: + if config.exists(conntrack_base + [protocol]): + if not config.exists(firewall_base + ['timeout']): + config.set(firewall_base + ['timeout']) -try: - with open(file_name, 'w') as f: - f.write(config.to_string()) -except OSError as e: - print("Failed to save the modified config: {}".format(e)) - exit(1) + config.copy(conntrack_base + [protocol], firewall_base + ['timeout', protocol]) + config.delete(conntrack_base + [protocol]) -- cgit v1.2.3