summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-02-04 17:41:16 +0100
committerChristian Poessinger <christian@poessinger.com>2021-02-04 19:16:35 +0100
commit830688d0c523d6209091ed2fc9160e6ca70e62b9 (patch)
treede25c5fed1e637b772a1dcb45e5f9360ef151a75
parent7288d31824cba80e99a66b2484feac7d0f46aacc (diff)
downloadvyos-1x-830688d0c523d6209091ed2fc9160e6ca70e62b9.tar.gz
vyos-1x-830688d0c523d6209091ed2fc9160e6ca70e62b9.zip
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.
-rwxr-xr-xsrc/migration-scripts/interfaces/18-to-1923
1 files changed, 22 insertions, 1 deletions
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 <http://www.gnu.org/licenses/>.
-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())