Skip to content

Commit

Permalink
T6255: static-routing: Create migrator to replace whitespace in exist…
Browse files Browse the repository at this point in the history
…ing descriptions
  • Loading branch information
Embezzle committed Apr 22, 2024
1 parent ac4fc09 commit ebf0adc
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- include start from include/version/static-routing-version.xml.i -->
<syntaxVersion component='static-routing' version='1'></syntaxVersion>
<!-- include end -->
1 change: 1 addition & 0 deletions interface-definitions/xml-component-version.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <include/version/snmp-version.xml.i>
#include <include/version/ssh-version.xml.i>
#include <include/version/sstp-version.xml.i>
#include <include/version/static-routing-version.xml.i>
#include <include/version/system-version.xml.i>
#include <include/version/vrf-version.xml.i>
#include <include/version/vrrp-version.xml.i>
Expand Down
52 changes: 52 additions & 0 deletions src/migration-scripts/static-routing/0-to-1
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python3
#
# Copyright (C) 2024 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# T6255: static-routing: replace whitespace in "static table description" with underscores

import re
import sys
from vyos.configtree import ConfigTree


if len(sys.argv) < 2:
print("Must specify file name!")
sys.exit(1)

file_name = sys.argv[1]

with open(file_name, 'r') as f:
config_file = f.read()

config = ConfigTree(config_file)

base = ['protocols', 'static', 'table']
if not config.exists(base):
# Nothing to do
sys.exit(0)

for table_number in config.list_nodes(base):
description_path = base + [table_number, 'description']

if config.exists(description_path):
new_description = re.sub(r'\s', "_", config.return_value(description_path))
config.set(description_path, new_description, True)

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))
sys.exit(1)

0 comments on commit ebf0adc

Please sign in to comment.