From 830688d0c523d6209091ed2fc9160e6ca70e62b9 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Thu, 4 Feb 2021 17:41:16 +0100 Subject: migrator: ospf: T3267: cleanup empty interface "ip" nodes When per interface OSPF configuration is migrated into "protocols ospf interface" we should cleanup and empty ip {} node unter the individual interface. This makes the config look more nicely. --- src/migration-scripts/interfaces/18-to-19 | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/migration-scripts/interfaces') diff --git a/src/migration-scripts/interfaces/18-to-19 b/src/migration-scripts/interfaces/18-to-19 index e24421c90..965b76a04 100755 --- a/src/migration-scripts/interfaces/18-to-19 +++ b/src/migration-scripts/interfaces/18-to-19 @@ -14,7 +14,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from sys import exit, argv +from sys import argv +from sys import exit from vyos.configtree import ConfigTree if __name__ == '__main__': @@ -41,6 +42,11 @@ if __name__ == '__main__': config.copy(ip_ospf, ['protocols', 'ospf', 'interface', interface]) config.delete(ip_ospf) + # if "ip ospf" was the only setting, we can clean out the empty + # ip node afterwards + if len(config.list_nodes(ip_ospf[:-1])) == 0: + config.delete(ip_ospf[:-1]) + vif_path = ['interfaces', type, interface, 'vif'] if config.exists(vif_path): for vif in config.list_nodes(vif_path): @@ -51,6 +57,11 @@ if __name__ == '__main__': config.copy(vif_ospf_path, ['protocols', 'ospf', 'interface', f'{interface}.{vif}']) config.delete(vif_ospf_path) + # if "ip ospf" was the only setting, we can clean out the empty + # ip node afterwards + if len(config.list_nodes(vif_ospf_path[:-1])) == 0: + config.delete(vif_ospf_path[:-1]) + vif_s_path = ['interfaces', type, interface, 'vif-s'] if config.exists(vif_s_path): for vif_s in config.list_nodes(vif_s_path): @@ -70,8 +81,18 @@ if __name__ == '__main__': config.copy(vif_c_ospf_path, ['protocols', 'ospf', 'interface', f'{interface}.{vif_s}.{vif_c}']) config.delete(vif_c_ospf_path) + # if "ip ospf" was the only setting, we can clean out the empty + # ip node afterwards + if len(config.list_nodes(vif_c_ospf_path[:-1])) == 0: + config.delete(vif_c_ospf_path[:-1]) + config.delete(vif_s_ospf_path) + # if "ip ospf" was the only setting, we can clean out the empty + # ip node afterwards + if len(config.list_nodes(vif_s_ospf_path[:-1])) == 0: + config.delete(vif_s_ospf_path[:-1]) + try: with open(file_name, 'w') as f: f.write(config.to_string()) -- cgit v1.2.3