Skip to content

Commit 07af239

Browse files
committed
[airos] added radio module for radio configuration generation
1 parent 795fe50 commit 07af239

2 files changed

Lines changed: 56 additions & 11 deletions

File tree

netjsonconfig/backends/airos/converters.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
from ...utils import get_copy
55
from ..base.converter import BaseConverter
66
from .aaa import bridge_devname, profile_from_interface, status_from_interface
7-
from .interface import autonegotiation, bridge, bssid, flowcontrol, hidden_ssid, protocol, radio, split_cidr, ssid, stp, vlan, wireless
7+
from .interface import autonegotiation, bridge, bssid, flowcontrol, hidden_ssid, mode, protocol, radio, split_cidr, ssid, stp, vlan, wireless
8+
from .radio import radio_available_mode, radio_configuration
89
from .radius import radius_from_interface
910
from .schema import default_ntp_servers
10-
from .radio import radio_device_base, radio_configuration
1111
from .wpasupplicant import available_mode_authentication
1212

1313

@@ -352,18 +352,24 @@ def to_intermediate(self):
352352
class Radio(AirOsConverter):
353353
netjson_key = 'radios'
354354

355+
@property
356+
def radio(self):
357+
return get_copy(self.netjson, self.netjson_key, [])
358+
359+
@property
360+
def wireless(self):
361+
return wireless(get_copy(self.netjson, 'interfaces', []))
362+
355363
def to_intermediate(self):
356364
result = []
357-
original = get_copy(self.netjson, self.netjson_key, [])
358365
radios = []
359-
for r in original:
360-
base = radio_device_base.copy()
361-
user_configs = {
362-
'devname': r['name'],
363-
'txpower': r.get('tx_power', 24),
364-
}
365-
base.update(user_configs)
366-
radios.append(base)
366+
wireless = {radio(w): w for w in self.wireless}
367+
for logic in self.radio:
368+
w = wireless.get(logic['name'])
369+
if w:
370+
user_config = radio_available_mode[mode(w)](logic)
371+
radios.append(user_config)
372+
367373
result.append(radios)
368374
result.append(radio_configuration)
369375
return (('radio', result),)

netjsonconfig/backends/airos/radio.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,42 @@
5252
'status': 'enabled',
5353
'countrycode': 380,
5454
}
55+
56+
57+
def access_point(radio):
58+
"""
59+
Return the configuration for a radio device whose wireless
60+
interface is in ``access_point`` mode
61+
"""
62+
base = _radio_device_base.copy()
63+
base.update({
64+
'devname': radio['name'],
65+
'chanbw': 80,
66+
'ieee_mode': '11acvht80',
67+
'mode': 'master',
68+
})
69+
return base
70+
71+
72+
def station(radio):
73+
"""
74+
Return the configuration for a radio device whose wireless
75+
interface is in ``station`` mode
76+
"""
77+
base = _radio_device_base.copy()
78+
base.update({
79+
'devname': radio['name'],
80+
'txpower': radio.get('tx_power', 24),
81+
})
82+
return base
83+
84+
85+
radio_available_mode = {
86+
'access_point': access_point,
87+
'station': station,
88+
}
89+
90+
__all__ = [
91+
radio_available_mode,
92+
radio_configuration,
93+
]

0 commit comments

Comments
 (0)