Skip to content

Commit

Permalink
[change] Included configuration suffix in backend render
Browse files Browse the repository at this point in the history
- Added propertyOrder to schema.
  • Loading branch information
Aryamanz29 committed Jun 5, 2023
1 parent c78e68b commit 0c2031c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
4 changes: 2 additions & 2 deletions netjsonconfig/backends/zerotier/parser.py
Expand Up @@ -2,9 +2,9 @@

from ..base.parser import BaseParser

vpn_pattern = re.compile('^// zerotier config:\s', flags=re.MULTILINE)
vpn_pattern = re.compile('^// zerotier controller config:\s', flags=re.MULTILINE)
config_pattern = re.compile('^([^\s]*) ?(.*)$')
config_suffix = '.json'
config_suffix = ''


class ZeroTierParser(BaseParser):
Expand Down
28 changes: 28 additions & 0 deletions netjsonconfig/backends/zerotier/schema.py
Expand Up @@ -19,9 +19,11 @@
"title": "ZeroTier",
"uniqueItems": True,
"additionalItems": True,
"propertyOrder": 12,
"items": {
"type": "object",
"title": "ZeroTier Network",
"uniqueItems": True,
"additionalProperties": True,
"required": ["name"],
"properties": {
Expand All @@ -31,56 +33,65 @@
# Since it is intended to be set by
# the VPN backend's name field, it is read-only
"readOnly": True,
"propertyOrder": 1,
"example": "openwisp-wifi-network",
"description": "Name of the network",
},
"id": {
"type": "string",
"maxLength": 16,
"readOnly": True,
"propertyOrder": 2,
"example": "3e245e31af000001",
"description": "Network ID",
},
"nwid": {
"type": "string",
"maxLength": 16,
"readOnly": True,
"propertyOrder": 3,
"example": "3e245e31af000001",
"description": "Network ID legacy field (same as 'id')",
},
"objtype": {
"type": "string",
"readOnly": True,
"propertyOrder": 4,
"default": "network",
"example": "network",
},
"revision": {
"type": "integer",
"example": 1,
"readOnly": True,
"propertyOrder": 5,
"description": "The revision number of the network configuration",
},
"creationTime": {
"type": "number",
"readOnly": True,
"propertyOrder": 6,
"example": 1623101592,
"description": "Time when the network was created",
},
# Configurable properties
"private": {
"type": "boolean",
"default": True,
"propertyOrder": 7,
"description": (
"Whether or not the network is private "
"If false, members will NOT need to be authorized to join"
),
},
"enableBroadcast": {
"type": "boolean",
"propertyOrder": 8,
"description": "Enable broadcast packets on the network",
},
"v4AssignMode": {
"type": "object",
"propertyOrder": 9,
"properties": {
"zt": {
"type": "boolean",
Expand All @@ -90,6 +101,7 @@
},
"v6AssignMode": {
"type": "object",
"propertyOrder": 11,
"properties": {
"6plane": {
"type": "boolean",
Expand All @@ -107,11 +119,13 @@
},
"mtu": {
"type": "integer",
"propertyOrder": 12,
"example": 2800,
"description": "MTU to set on the client virtual network adapter",
},
"multicastLimit": {
"type": "integer",
"propertyOrder": 13,
"example": 32,
"description": (
"Maximum number of recipients per multicast or broadcast."
Expand All @@ -120,16 +134,19 @@
},
"routes": {
"type": "array",
"propertyOrder": 14,
"items": {
"type": "object",
"properties": {
"target": {
"type": "string",
"propertyOrder": 1,
"example": "192.168.192.0/24",
"description": "The target IP address range for the route",
},
"via": {
"type": "string",
"propertyOrder": 2,
"example": "192.168.192.1",
"description": "The IP address of the next hop for the route",
},
Expand All @@ -139,16 +156,19 @@
},
"ipAssignmentPools": {
"type": "array",
"propertyOrder": 15,
"items": {
"type": "object",
"properties": {
"ipRangeStart": {
"type": "string",
"example": "192.168.192.1",
"propertyOrder": 1,
"description": "The starting IP address of the pool range",
},
"ipRangeEnd": {
"type": "string",
"propertyOrder": 2,
"example": "192.168.192.254",
"description": "The ending IP address of the pool range",
},
Expand All @@ -158,14 +178,17 @@
},
"dns": {
"type": "object",
"propertyOrder": 16,
"properties": {
"domain": {
"type": "string",
"propertyOrder": 1,
"example": "zerotier.openwisp.io",
"description": "The domain for DNS resolution",
},
"servers": {
"type": "array",
"propertyOrder": 2,
"items": {
"type": "string",
"example": "10.147.20.3",
Expand All @@ -177,25 +200,30 @@
"rules": {
"type": "array",
"items": {"type": "object"},
"propertyOrder": 17,
"description": "Array of network rule objects",
},
"capabilities": {
"type": "array",
"items": {"type": "object"},
"propertyOrder": 18,
"description": "Array of network capabilities",
},
"tags": {
"type": "array",
"items": {"type": "object"},
"propertyOrder": 19,
"description": "Array of network tag objects",
},
"remoteTraceTarget": {
"type": "string",
"propertyOrder": 20,
"example": "7f5d90eb87",
"description": "The remote target ID for network tracing",
},
"remoteTraceLevel": {
"type": "integer",
"propertyOrder": 21,
"description": "The level of network tracing",
},
},
Expand Down
2 changes: 1 addition & 1 deletion netjsonconfig/backends/zerotier/templates/zerotier.jinja2
@@ -1,5 +1,5 @@
{% for vpn in data.zerotier %}
// zerotier config: {{ vpn.nwid }}
// zerotier controller config: {{ vpn.nwid }}.json

{{ vpn | tojson(indent=2)}}

Expand Down
4 changes: 2 additions & 2 deletions tests/zerotier/test_backend.py
Expand Up @@ -92,7 +92,7 @@ def test_test_schema(self):

def test_confs(self):
c = ZeroTier(self._TEST_CONFIG)
expected = """// zerotier config: 9536600adf654321
expected = """// zerotier controller config: 9536600adf654321.json
{
"capabilities": [
Expand Down Expand Up @@ -166,7 +166,7 @@ def test_confs(self):
}
}
// zerotier config: 9536600adf654322
// zerotier controller config: 9536600adf654322.json
{
"creationTime": 1632012345,
Expand Down

0 comments on commit 0c2031c

Please sign in to comment.