Skip to content

Commit

Permalink
Some sanity checks. Fix #1423.
Browse files Browse the repository at this point in the history
  • Loading branch information
kiarn committed Feb 7, 2023
1 parent e1aece9 commit c3cf1b8
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions plugins/network/managers/ubuntu_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,23 @@ def get_config(self):
ifaces = []
netplan_files = [join(self.path,f) for f in os.listdir(self.path) if isfile(join(self.path, f))]
for path in netplan_files:
config = yaml.load(open(path), Loader=yaml.SafeLoader)['network']['ethernets']
for key in config:
addresses = config[key].get('adresses', None)
try:
with open(path, 'r') as netplan_config:
config = yaml.load(netplan_config, Loader=yaml.SafeLoader) or {}
network_config = config.get('network', {})
ethernet_config = network_config.get('ethernets', {})
except KeyError:
# Maybe there are some others files in /etc/netplan
continue
for key in ethernet_config:
addresses = ethernet_config[key].get('adresses', None)
if addresses is None:
# DHCP
ip, mask = ifconfig_get_ip4_mask(key)
gateway = ifconfig_get_gateway(key)
else:
ip, mask = config[key]['addresses'][0].split('/')
gateway = config[key].get('gateway4', None)
ip, mask = ethernet_config[key]['addresses'][0].split('/')
gateway = ethernet_config[key].get('gateway4', None)
iface = {
'name': key,
'family': None,
Expand Down

0 comments on commit c3cf1b8

Please sign in to comment.