Skip to content

Commit

Permalink
Remove netplan update in linuxmuster-import-subnets.
Browse files Browse the repository at this point in the history
  • Loading branch information
HappyBasher committed Jul 25, 2023
1 parent 8984415 commit 4866dc9
Showing 1 changed file with 1 addition and 41 deletions.
42 changes: 1 addition & 41 deletions sbin/linuxmuster-import-subnets
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# linuxmuster-import-subnets
# thomas@linuxmuster.net
# 20211219
# 20230725
#

import ast
Expand Down Expand Up @@ -84,43 +84,6 @@ nat_rule_xml = nat_rule_xml.replace(


# functions begin
# update static routes in netplan configuration
def updateNetplan(subnets):
printScript('Processing netplan configuration:')
cfgfile = constants.NETCFG
# read netplan config file
with open(cfgfile) as config:
netcfg = yaml.safe_load(config)
iface = str(netcfg['network']['ethernets']).split('\'')[1]
ifcfg = netcfg['network']['ethernets'][iface]
# first delete the old routes if there are any
try:
del ifcfg['routes']
changed = True
printScript('* Removed old routes.')
except:
changed = False
# only if there are subnets beside server network
if len(subnets) > 0:
changed = True
ifcfg['routes'] = []
for item in subnets:
subnet = item.split(':')[0]
# tricky: concenate dict object for yaml using eval
subroute = eval('{"to": ' + '\'' + subnet + '\''
+ ', "via": ' + '\'' + servernet_router + '\'' + '}')
ifcfg['routes'].append(subroute)
printScript('* Added new routes for all subnets.')
# save netcfg
if changed:
with open(cfgfile, 'w') as config:
config.write(yaml.dump(netcfg, default_flow_style=False))
os.system('netplan apply')
printScript('* Applied new configuration.')
# send changed configuration back and apply it
return changed


# update vlan gateway on firewall
def updateFwGw(servernet_router, content):
soup = BeautifulSoup(content, 'lxml')
Expand Down Expand Up @@ -360,9 +323,6 @@ else:

os.system('systemctl restart isc-dhcp-server.service')

# update netplan config with new routes for server (localhost)
changed = updateNetplan(subnets)

# update firewall
if not skipfw:
changed = updateFw(subnets, firewallip, ipnet_setup,
Expand Down

0 comments on commit 4866dc9

Please sign in to comment.