Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[OpenWrt] Simplified definition of custom interface "proto" options
Backward incompatible change.
- Loading branch information
|
@@ -59,8 +59,7 @@ def _get_interfaces(self): |
|
|
# default values |
|
|
address_key = None |
|
|
address_value = None |
|
|
# proto defaults to static |
|
|
proto = address.get('proto', 'static') |
|
|
proto = self.__get_proto(uci_interface, address) |
|
|
# add suffix if there is more than one config block |
|
|
if counter > 1: |
|
|
name = '{name}_{counter}'.format(name=uci_name, counter=counter) |
|
@@ -117,6 +116,16 @@ def _get_interfaces(self): |
|
|
counter += 1 |
|
|
return uci_interfaces |
|
|
|
|
|
def __get_proto(self, interface, address): |
|
|
""" |
|
|
determines interface "proto" option |
|
|
""" |
|
|
if 'proto' not in interface: |
|
|
# proto defaults to static |
|
|
return address.get('proto', 'static') |
|
|
else: |
|
|
# allow override |
|
|
return interface['proto'] |
|
|
def _get_routes(self): |
|
|
routes = self.config.get('routes', []) |
|
|
# results container |
|
|
|
@@ -9,55 +9,13 @@ |
|
|
|
|
|
schema = merge_config(default_schema, { |
|
|
"definitions": { |
|
|
"other_address": { |
|
|
"type": "object", |
|
|
"title": "other", |
|
|
"allOf": [ |
|
|
{"$ref": "#/definitions/base_address"}, |
|
|
{ |
|
|
"type": "object", |
|
|
"properties": { |
|
|
"family": {"enum": ["ipv4", "ipv6"]}, |
|
|
"proto": { |
|
|
"enum": [ |
|
|
'ppp', |
|
|
'pppoe', |
|
|
'pppoa', |
|
|
'3g', |
|
|
'qmi', |
|
|
'ncm', |
|
|
'hnet', |
|
|
'pptp', |
|
|
'6in4', |
|
|
'aiccu', |
|
|
'6to4', |
|
|
'6rd', |
|
|
'dslite', |
|
|
'l2tp', |
|
|
'relay', |
|
|
'gre', |
|
|
'gretap', |
|
|
'grev6', |
|
|
'grev6tap', |
|
|
'none' |
|
|
] |
|
|
} |
|
|
} |
|
|
} |
|
|
] |
|
|
}, |
|
|
"interface_settings": { |
|
|
"properties": { |
|
|
"network": { |
|
|
"type": "string", |
|
|
"maxLength": 15, |
|
|
"pattern": "^[a-zA-z0-9_\\.\\-]*$", |
|
|
"propertyOrder": 7 |
|
|
}, |
|
|
"addresses": { |
|
|
"items": { |
|
|
"oneOf": [{"$ref": "#/definitions/other_address"}] |
|
|
} |
|
|
} |
|
|
} |
|
|
}, |
|
|
|
@@ -261,26 +261,31 @@ def test_ipv6_routes(self): |
|
|
""") |
|
|
self.assertEqual(o.render(), expected) |
|
|
|
|
|
def test_additional_proto(self): |
|
|
def test_custom_proto(self): |
|
|
o = OpenWrt({ |
|
|
"interfaces": [ |
|
|
{ |
|
|
"name": "mobile0", |
|
|
"type": "wireless", |
|
|
"addresses": [ |
|
|
{ |
|
|
"proto": "3g", |
|
|
"family": "ipv4" |
|
|
} |
|
|
] |
|
|
"name": "ppp0", |
|
|
"type": "other", |
|
|
"proto": "ppp", |
|
|
"device": "/dev/usb/modem1", |
|
|
"username": "user1", |
|
|
"password": "pwd0123", |
|
|
"keepalive": 3, |
|
|
"ipv6": True |
|
|
} |
|
|
] |
|
|
}) |
|
|
expected = self._tabs("""package network |
|
|
|
|
|
config interface 'mobile0' |
|
|
option ifname 'mobile0' |
|
|
option proto '3g' |
|
|
config interface 'ppp0' |
|
|
option device '/dev/usb/modem1' |
|
|
option ifname 'ppp0' |
|
|
option ipv6 '1' |
|
|
option keepalive '3' |
|
|
option password 'pwd0123' |
|
|
option proto 'ppp' |
|
|
option username 'user1' |
|
|
""") |
|
|
self.assertEqual(o.render(), expected) |
|
|
|
|
@@ -312,12 +317,7 @@ def test_interface_custom_attrs(self): |
|
|
"mtu": 1400, |
|
|
"custom_attr": "yes", |
|
|
"empty": "", |
|
|
"addresses": [ |
|
|
{ |
|
|
"proto": "3g", |
|
|
"family": "ipv4" |
|
|
} |
|
|
] |
|
|
"proto": "3g", |
|
|
} |
|
|
] |
|
|
}) |
|
|