Skip to content

Commit

Permalink
[openwrt] Added support for "ip6gw" option #86
Browse files Browse the repository at this point in the history
- updated tests
- updated docs

Closes #86
  • Loading branch information
nemesifier committed Jun 15, 2017
1 parent 2ffe2de commit 4f8d105
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
14 changes: 9 additions & 5 deletions docs/source/backends/openwrt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ Code example:
"type": "ethernet",
"addresses": [
{
"address": "192.168.1.1",
"address": "192.168.1.2",
"gateway": "192.168.1.1",
"mask": 24,
"proto": "static",
"family": "ipv4"
Expand All @@ -67,8 +68,9 @@ Code example:
"family": "ipv4"
},
{
"address": "fd87::1",
"mask": 128,
"address": "fd87::2",
"gateway": "fd87::1",
"mask": 64,
"proto": "static",
"family": "ipv6"
}
Expand All @@ -83,9 +85,11 @@ Will return the following output::
package network

config interface 'eth0_1'
option gateway '192.168.1.1'
option ifname 'eth0.1'
option ip6addr 'fd87::1/128'
list ipaddr '192.168.1.1/24'
option ip6addr 'fd87::2/64'
option ip6gw 'fd87::1'
list ipaddr '192.168.1.2/24'
list ipaddr '192.168.2.1/24'
option proto 'static'

Expand Down
5 changes: 4 additions & 1 deletion netjsonconfig/backends/openwrt/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ def __get_addresses(self, interface):
address['proto'] = 'dhcp' if family == 'ipv4' else 'dhcpv6'
dhcp.append(self.__del_address_keys(address))
continue
if 'gateway' in address:
uci_key = 'gateway' if family == 'ipv4' else 'ip6gw'
interface[uci_key] = address['gateway']
# static
address_key = 'ipaddr' if family == 'ipv4' else 'ip6addr'
static.setdefault(address_key, [])
Expand Down Expand Up @@ -178,7 +181,7 @@ def __get_interface(self, interface, uci_name):
del interface['addresses']
return interface

_address_keys = ['address', 'mask', 'family']
_address_keys = ['address', 'mask', 'family', 'gateway']

def __del_address_keys(self, address):
"""
Expand Down
24 changes: 14 additions & 10 deletions tests/openwrt/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,28 @@ def test_multiple_ip(self):
"autostart": True,
"addresses": [
{
"address": "192.168.1.1",
"address": "192.168.1.2",
"gateway": "192.168.1.1",
"mask": 24,
"proto": "static",
"family": "ipv4"
},
{
"address": "192.168.2.1",
"address": "192.168.2.3",
"mask": 24,
"proto": "static",
"family": "ipv4"
},
{
"address": "fd87::1",
"mask": 128,
"address": "fd87::2",
"gateway": "fd87::1",
"mask": 64,
"proto": "static",
"family": "ipv6"
},
{
"address": "fd87::2",
"mask": 128,
"address": "fd87::3",
"mask": 64,
"proto": "static",
"family": "ipv6"
}
Expand All @@ -75,11 +77,13 @@ def test_multiple_ip(self):
config interface 'eth0_1'
option auto '1'
option gateway '192.168.1.1'
option ifname 'eth0.1'
list ip6addr 'fd87::1/128'
list ip6addr 'fd87::2/128'
list ipaddr '192.168.1.1/24'
list ipaddr '192.168.2.1/24'
list ip6addr 'fd87::2/64'
list ip6addr 'fd87::3/64'
option ip6gw 'fd87::1'
list ipaddr '192.168.1.2/24'
list ipaddr '192.168.2.3/24'
option proto 'static'
""")
self.assertEqual(o.render(), expected)
Expand Down

0 comments on commit 4f8d105

Please sign in to comment.