Skip to content

Commit

Permalink
[airos] check for interface without address definition
Browse files Browse the repository at this point in the history
  • Loading branch information
edoput committed Jun 22, 2017
1 parent 90d6523 commit 427392e
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions netjsonconfig/backends/airos/converters.py
Expand Up @@ -181,27 +181,32 @@ def to_intermediate(self):
if interface['type'] == 'wireless':
base['devname'] = interface['wireless']['radio']

addresses = interface.get('addresses', [])

for addr in addresses:
temp = {
'devname': interface['name'],
'status': 'enabled', # can't disable interfaces
'up': status(interface),
'mut': interface.get('mtu', 1500),
}
if addr['proto'] == 'dhcp':
temp['autoip'] = {}
temp['autoip']['status'] = 'enabled'
else:
network = ip_interface('%s/%d' % (addr['address'],addr['mask']))
temp['ip'] = str(network.ip)
temp['netmask'] = str(network.netmask)

if interface['type'] == 'wireless':
temp['devname'] = interface['wireless']['radio']

interfaces.append(temp)
addresses = interface.get('addresses')

if addresses:
# for every address policy put a
# configuration
for addr in addresses:
temp = deepcopy(base)

# handle explicit address policy
if addr['proto'] == 'dhcp':
temp['autoip'] = {}
temp['autoip']['status'] = 'enabled'
else:
ip_and_mask = '%s/%d' % (addr['address'], addr['mask'])
network = ip_interface(ip_and_mask)
temp['ip'] = str(network.ip)
temp['netmask'] = str(network.netmask)

interfaces.append(temp)
else:
# an interface without address
# is still valid with these defaults values
base['autoip'] = {
'status': 'disabled',
}
interfaces.append(base)

result.append(interfaces)
result.append({
Expand Down

0 comments on commit 427392e

Please sign in to comment.