Skip to content

Commit 586e4bc

Browse files
authored
[feature] Allowed defining VXLAN interface in VXLAN over WireGuard backend
1 parent 9dbbbf0 commit 586e4bc

4 files changed

Lines changed: 67 additions & 11 deletions

File tree

netjsonconfig/backends/openwrt/openwrt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def vxlan_wireguard_auto_client(cls, **kwargs):
124124
config = cls.wireguard_auto_client(**kwargs)
125125
vxlan_config = VxlanWireguard.auto_client(**kwargs)
126126
vxlan_interface = {
127-
'name': 'vxlan',
127+
'name': vxlan_config['name'],
128128
'type': 'vxlan',
129129
'vtep': vxlan_config['server_ip_address'],
130130
'port': 4789,
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from copy import deepcopy
2+
3+
from ..wireguard.schema import schema as base_schema
4+
5+
base_vxlan_properties = {
6+
"vxlan": {
7+
"type": "array",
8+
"title": "VXLAN",
9+
"uniqueItems": True,
10+
"additionalItems": True,
11+
"propertyOrder": 13,
12+
"items": {
13+
"type": "object",
14+
"title": "VXLAN tunnel",
15+
"additionalProperties": True,
16+
"properties": {
17+
"name": {
18+
"title": "interface name",
19+
"description": "VXLAN interface name",
20+
"type": "string",
21+
"minLength": 2,
22+
"maxLength": 15,
23+
"pattern": "^[^\\s]*$",
24+
"propertyOrder": 1,
25+
},
26+
"vni": {
27+
"propertyOrder": 2,
28+
"title": "VNI",
29+
"oneOf": [
30+
{
31+
"title": "VNI (auto)",
32+
"description": "Auto-generate (different for each tunnel)",
33+
"type": "string",
34+
"enum": [""],
35+
"options": {"enum_titles": ["auto"]},
36+
"readonly": True,
37+
},
38+
{
39+
"title": "VNI (manual)",
40+
"type": "integer",
41+
"default": 1,
42+
"minimum": 0,
43+
"maximum": 16777216,
44+
},
45+
],
46+
},
47+
},
48+
},
49+
}
50+
}
51+
52+
53+
schema = deepcopy(base_schema)
54+
schema['properties'].update(base_vxlan_properties)
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
from ..wireguard.wireguard import Wireguard
2+
from .schema import schema
23

34

45
class VxlanWireguard(Wireguard):
6+
schema = schema
7+
58
@classmethod
6-
def auto_client(cls, vni=0, server_ip_address='', **kwargs):
9+
def auto_client(cls, vni=0, server_ip_address='', vxlan=None, **kwargs):
710
"""
811
Returns a configuration dictionary representing VXLAN configuration
912
that is compatible with the passed server configuration.
@@ -12,8 +15,10 @@ def auto_client(cls, vni=0, server_ip_address='', **kwargs):
1215
:param server_ip_address: server internal tunnel address
1316
:returns: dictionary representing VXLAN properties
1417
"""
18+
vxlan = vxlan or {}
1519
config = {
1620
'server_ip_address': server_ip_address,
1721
'vni': vni,
22+
'name': vxlan.get('name', 'vxlan'),
1823
}
1924
return config

tests/vxlan/test_vxlan_wireguard.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,17 @@
66
class TestBackend(unittest.TestCase):
77
def test_auto_client(self):
88
with self.subTest('No arguments are provided'):
9-
expected = {
10-
'server_ip_address': '',
11-
'vni': 0,
12-
}
9+
expected = {'server_ip_address': '', 'vni': 0, 'name': 'vxlan'}
1310
self.assertDictEqual(VxlanWireguard.auto_client(), expected)
1411

1512
with self.subTest('All arguments are provided'):
16-
expected = {
17-
'server_ip_address': '10.0.0.1',
18-
'vni': 1,
19-
}
13+
expected = {'server_ip_address': '10.0.0.1', 'vni': 1, 'name': 'vxlan1'}
2014
self.assertDictEqual(
2115
VxlanWireguard.auto_client(
22-
vni=1, server_ip_address='10.0.0.1', server={}
16+
vni=1,
17+
server_ip_address='10.0.0.1',
18+
server={},
19+
vxlan={'name': 'vxlan1'},
2320
),
2421
expected,
2522
)

0 commit comments

Comments
 (0)