Skip to content

Commit

Permalink
fix: using a default when upgrading the module
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaile committed Dec 13, 2024
1 parent 365a280 commit 7459de4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
3 changes: 1 addition & 2 deletions imageroot/bin/expand-config
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ with open("dnsmasq.d/00config.conf", "w") as file:
# write dhcp-server configuration
if config["dhcp-server"]["enabled"]:
file.write("dhcp-range=set:default," + config["dhcp-server"]["start"] + "," + config["dhcp-server"]["end"] + "," + str(config["dhcp-server"]["lease"]) + "h\n")
# due to gateway field introduced in later releases, we need to check if it's present
if 'gateway' in config ['dhcp-server'] and config["dhcp-server"]["gateway"] != "":
if config["dhcp-server"]["gateway"] != "":
file.write("dhcp-option=tag:default,option:router," + config["dhcp-server"]["gateway"] + "\n")

# write dns-server configuration, if no local Samba DC is present
Expand Down
19 changes: 19 additions & 0 deletions imageroot/update-module.d/20gateway_default
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python3

#
# Copyright (C) 2024 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#

import json

config = json.load(open('config.json'))

if config['dhcp-server']['enabled']:
if 'gateway' not in config['dhcp-server'] and config['dhcp-server']['gateway'] == '':
# the field is left empty, to avoid assigning a default value
# this is because if in any case the interface the dhcp-server is running
# has two or more ips, a default gateway might cause way too many issues
config['dhcp-server']['gateway'] = ''

json.dump(config, fp=open('config.json', 'w'))

0 comments on commit 7459de4

Please sign in to comment.