Skip to content

Commit

Permalink
[chores] Fixed complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Sep 3, 2024
1 parent d25527e commit 734a613
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
5 changes: 2 additions & 3 deletions netjsonconfig/backends/openwrt/converters/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,13 +493,12 @@ def __netjson_dsa_interface(self, interface):
if option in device_config:
interface[option] = device_config.pop(option)
# if device_config is empty but the interface references it
elif 'device' in interface:
elif 'device' in interface and 'ifname' not in interface:
# .name may have '.' substituted with _,
# which will yield unexpected results
# for this reason we use the name stored
# in the device property before removing it
if 'ifname' not in interface:
interface['ifname'] = interface.pop('device')
interface['ifname'] = interface.pop('device')
return interface

def __netjson_device(self, interface):
Expand Down
43 changes: 24 additions & 19 deletions netjsonconfig/backends/openwrt/converters/wireless.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,35 @@ def __intermediate_wireless(self, interface):
encryption = self.__intermediate_encryption(wireless)
wireless.update(encryption)
wireless = self.__intermediate_roaming(wireless)
wireless = self.__intermediate_auto_network(wireless, interface)
wireless['network'] = (
' '.join(wireless['network']).replace('.', '_').replace('-', '_')
)
return self.sorted_dict(wireless)

def __intermediate_auto_network(self, wireless, interface):
# attached networks (openwrt specific)
# by default the wifi interface is attached
# to its defining interface
# but this behaviour can be overridden
if not wireless.get('network'):
# try to automatically determine whether
# we should attach this interface to a bridge
try:
bridges = self._bridged_wifi[interface['name']]
except KeyError:
# if interface has any address specified,
# we need to attach it in the OpenWrt config
if interface.get('addresses', []):
network = [interface['name']]
else:
# don't bridge to anything unless explicitly specified
network = []
if wireless.get('network'):
return wireless
# try to automatically determine whether
# we should attach this interface to a bridge
try:
bridges = self._bridged_wifi[interface['name']]
except KeyError:
# if interface has any address specified,
# we need to attach it in the OpenWrt config
if interface.get('addresses', []):
network = [interface['name']]
else:
network = bridges
wireless['network'] = network
wireless['network'] = (
' '.join(wireless['network']).replace('.', '_').replace('-', '_')
)
return self.sorted_dict(wireless)
# don't bridge to anything unless explicitly specified
network = []
else:
network = bridges
wireless['network'] = network
return wireless

def __get_auto_name(self, interface):
wifi_name = self._get_uci_name(interface['name'])
Expand Down

0 comments on commit 734a613

Please sign in to comment.