Page Menu
Home
VyOS Platform
Search
Configure Global Search
Log In
Files
F118414505
Vyos 1.4 DHCP config migrate.txt
All Users
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Chynnon
Fri, Oct 16, 1:19 AM
2026-10-16 01:19:00 (UTC+0)
Size
13 KB
Referenced Files
None
Subscribers
None
Vyos 1.4 DHCP config migrate.txt
View Options
vyos@R1:/opt/vyatta/etc/config-migrate/migrate/dhcp-server$ cat 4-to-5
#!/usr/bin/env python3
# Removes boolean operator from:
# - "set service dhcp-server shared-network-name <xyz> subnet 172.31.0.0/24 ip-forwarding enable (true|false)"
# - "set service dhcp-server shared-network-name <xyz> authoritative (true|false)"
# - "set service dhcp-server disabled (true|false)"
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)
if not config.exists(['service', 'dhcp-server']):
# Nothing to do
sys.exit(0)
else:
base = ['service', 'dhcp-server']
# Make node "set service dhcp-server dynamic-dns-update enable (true|false)" valueless
if config.exists(base + ['dynamic-dns-update']):
bool_val = config.return_value(base + ['dynamic-dns-update', 'enable'])
# Delete the node with the old syntax
config.delete(base + ['dynamic-dns-update'])
if str(bool_val) == 'true':
# Enable dynamic-dns-update with new syntax
config.set(base + ['dynamic-dns-update'], value=None)
# Make node "set service dhcp-server disabled (true|false)" valueless
if config.exists(base + ['disabled']):
bool_val = config.return_value(base + ['disabled'])
# Delete the node with the old syntax
config.delete(base + ['disabled'])
if str(bool_val) == 'true':
# Now disable DHCP server with the new syntax
config.set(base + ['disable'], value=None)
# Make node "set service dhcp-server hostfile-update (enable|disable) valueless
if config.exists(base + ['hostfile-update']):
bool_val = config.return_value(base + ['hostfile-update'])
# Delete the node with the old syntax incl. all subnodes
config.delete(base + ['hostfile-update'])
if str(bool_val) == 'enable':
# Enable hostfile update with new syntax
config.set(base + ['hostfile-update'], value=None)
# Run this for every instance if 'shared-network-name'
for network in config.list_nodes(base + ['shared-network-name']):
base_network = base + ['shared-network-name', network]
# format as tag node to avoid loading problems
config.set_tag(base + ['shared-network-name'])
# Run this for every specified 'subnet'
for subnet in config.list_nodes(base_network + ['subnet']):
base_subnet = base_network + ['subnet', subnet]
# format as tag node to avoid loading problems
config.set_tag(base_network + ['subnet'])
# Make node "set service dhcp-server shared-network-name <xyz> subnet 172.31.0.0/24 ip-forwarding enable" valueless
if config.exists(base_subnet + ['ip-forwarding', 'enable']):
bool_val = config.return_value(base_subnet + ['ip-forwarding', 'enable'])
# Delete the node with the old syntax
config.delete(base_subnet + ['ip-forwarding'])
if str(bool_val) == 'true':
# Recreate node with new syntax
config.set(base_subnet + ['ip-forwarding'], value=None)
# Rename node "set service dhcp-server shared-network-name <xyz> subnet 172.31.0.0/24 start <172.16.0.4> stop <172.16.0.9>
if config.exists(base_subnet + ['start']):
# This is the new "range" id for DHCP lease ranges
r_id = 0
for range in config.list_nodes(base_subnet + ['start']):
range_start = range
range_stop = config.return_value(base_subnet + ['start', range_start, 'stop'])
# Delete the node with the old syntax
config.delete(base_subnet + ['start', range_start])
# Create the node for the new syntax
# Note: range is a tag node, counter is its child, not a value
config.set(base_subnet + ['range', r_id])
config.set(base_subnet + ['range', r_id, 'start'], value=range_start)
config.set(base_subnet + ['range', r_id, 'stop'], value=range_stop)
# format as tag node to avoid loading problems
config.set_tag(base_subnet + ['range'])
# increment range id for possible next range definition
r_id += 1
# Delete the node with the old syntax
config.delete(['service', 'dhcp-server', 'shared-network-name', network, 'subnet', subnet, 'start'])
# Make node "set service dhcp-server shared-network-name <xyz> authoritative" valueless
if config.exists(['service', 'dhcp-server', 'shared-network-name', network, 'authoritative']):
authoritative = config.return_value(['service', 'dhcp-server', 'shared-network-name', network, 'authoritative'])
# Delete the node with the old syntax
config.delete(['service', 'dhcp-server', 'shared-network-name', network, 'authoritative'])
# Recreate node with new syntax - if required
if authoritative == "enable":
config.set(['service', 'dhcp-server', 'shared-network-name', network, 'authoritative'])
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)
vyos@R1:/opt/vyatta/etc/config-migrate/migrate/dhcp-server$ cat 5-to-6
#!/usr/bin/env python3
#
# Copyright (C) 2021 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/>.
# T1968: allow multiple static-routes to be configured
# T3838: rename dns-server -> name-server
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()
base = ['service', 'dhcp-server']
config = ConfigTree(config_file)
if not config.exists(base + ['shared-network-name']):
# Nothing to do
exit(0)
# Run this for every instance if 'shared-network-name'
for network in config.list_nodes(base + ['shared-network-name']):
base_network = base + ['shared-network-name', network]
if not config.exists(base_network + ['subnet']):
continue
# Run this for every specified 'subnet'
for subnet in config.list_nodes(base_network + ['subnet']):
base_subnet = base_network + ['subnet', subnet]
# T1968: allow multiple static-routes to be configured
if config.exists(base_subnet + ['static-route']):
prefix = config.return_value(base_subnet + ['static-route', 'destination-subnet'])
router = config.return_value(base_subnet + ['static-route', 'router'])
config.delete(base_subnet + ['static-route'])
config.set(base_subnet + ['static-route', prefix, 'next-hop'], value=router)
config.set_tag(base_subnet + ['static-route'])
# T3838: rename dns-server -> name-server
if config.exists(base_subnet + ['dns-server']):
config.rename(base_subnet + ['dns-server'], 'name-server')
# T3672: ISC DHCP server only supports one failover peer
if config.exists(base_subnet + ['failover']):
# There can only be one failover configuration, if none is present
# we add the first one
if not config.exists(base + ['failover']):
local = config.return_value(base_subnet + ['failover', 'local-address'])
remote = config.return_value(base_subnet + ['failover', 'peer-address'])
status = config.return_value(base_subnet + ['failover', 'status'])
name = config.return_value(base_subnet + ['failover', 'name'])
config.set(base + ['failover', 'remote'], value=remote)
config.set(base + ['failover', 'source-address'], value=local)
config.set(base + ['failover', 'status'], value=status)
config.set(base + ['failover', 'name'], value=name)
config.delete(base_subnet + ['failover'])
config.set(base_subnet + ['enable-failover'])
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)
vyos@R1:/opt/vyatta/etc/config-migrate/migrate/dhcp-server$ cat 6-to-7
#!/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/>.
# T6079: Disable duplicate static mappings
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()
base = ['service', 'dhcp-server']
config = ConfigTree(config_file)
if not config.exists(base + ['shared-network-name']):
# Nothing to do
exit(0)
# Run this for every instance if 'shared-network-name'
for network in config.list_nodes(base + ['shared-network-name']):
base_network = base + ['shared-network-name', network]
if not config.exists(base_network + ['subnet']):
continue
for subnet in config.list_nodes(base_network + ['subnet']):
base_subnet = base_network + ['subnet', subnet]
if config.exists(base_subnet + ['static-mapping']):
used_mac = []
used_ip = []
for mapping in config.list_nodes(base_subnet + ['static-mapping']):
base_mapping = base_subnet + ['static-mapping', mapping]
if config.exists(base_mapping + ['mac-address']):
mac = config.return_value(base_mapping + ['mac-address'])
if mac in used_mac:
config.set(base_mapping + ['disable'])
else:
used_mac.append(mac)
if config.exists(base_mapping + ['ip-address']):
ip = config.return_value(base_mapping + ['ip-address'])
if ip in used_ip:
config.set(base_subnet + ['static-mapping', mapping, 'disable'])
else:
used_ip.append(ip)
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)
vyos@R1:/opt/vyatta/etc/config-migrate/migrate/dhcp-server$ cat 7-to-8
#!/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/>.
# T6171: rename "service dhcp-server failover" to "service dhcp-server high-availability"
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()
base = ['service', 'dhcp-server']
config = ConfigTree(config_file)
if not config.exists(base):
# Nothing to do
exit(0)
if config.exists(base + ['failover']):
config.rename(base + ['failover'],'high-availability')
try:
with open(file_name, 'w') as f:
f.write(config.to_string())
except OSError as e:
print(f'Failed to save the modified config: {e}')
exit(1)vyos@R1:/opt/vyatta/etc/config-migrate/migrate/dhcp-server$
File Metadata
Details
Attached
Mime Type
text/x-script.python
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4424864
Default Alt Text
Vyos 1.4 DHCP config migrate.txt (13 KB)
Attached To
Mode
T6285: Listen-address in DHCP-server when going VyOS 1.4 to 1.5 will cause problems
Attached
Detach File
Event Timeline
Log In to Comment