diff options
author | Simon <965089+sarthurdev@users.noreply.github.com> | 2024-01-11 06:46:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-11 06:46:33 +0100 |
commit | ee494c3a1dbfca3457bcaffe89d45971348e4848 (patch) | |
tree | 4e29926fae96e8837e6b903fc46478a92e6890da /src/migration-scripts/dhcpv6-server/3-to-4 | |
parent | 7c6cb9829356d07c3cfa865eff7f60c24d982d6e (diff) | |
download | vyos-1x-ee494c3a1dbfca3457bcaffe89d45971348e4848.tar.gz vyos-1x-ee494c3a1dbfca3457bcaffe89d45971348e4848.zip |
dhcp: dhcpv6: T3316: Add `subnet-id` so leases remain mapped to entries in the lease file (#2796)
Diffstat (limited to 'src/migration-scripts/dhcpv6-server/3-to-4')
-rwxr-xr-x | src/migration-scripts/dhcpv6-server/3-to-4 | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/migration-scripts/dhcpv6-server/3-to-4 b/src/migration-scripts/dhcpv6-server/3-to-4 new file mode 100755 index 000000000..c065e3d43 --- /dev/null +++ b/src/migration-scripts/dhcpv6-server/3-to-4 @@ -0,0 +1,55 @@ +#!/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/>. + +# T3316: +# - Add subnet IDs to existing subnets + +import sys +import re +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() + +base = ['service', 'dhcpv6-server', 'shared-network-name'] +config = ConfigTree(config_file) + +if not config.exists(base): + # Nothing to do + sys.exit(0) + +subnet_id = 1 + +for network in config.list_nodes(base): + if config.exists(base + [network, 'subnet']): + for subnet in config.list_nodes(base + [network, 'subnet']): + base_subnet = base + [network, 'subnet', subnet] + + config.set(base_subnet + ['subnet-id'], value=subnet_id) + subnet_id += 1 + +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) |