Skip to content

Commit

Permalink
[schema] Improved address definition #45
Browse files Browse the repository at this point in the history
Closes #45
  • Loading branch information
nemesifier committed Mar 20, 2016
1 parent 171511a commit 848e71e
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 63 deletions.
65 changes: 38 additions & 27 deletions netjsonconfig/backends/openwrt/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,43 @@

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": {
Expand All @@ -19,33 +56,7 @@
},
"addresses": {
"items": {
"properties": {
"proto": {
"enum": [
'dhcpv6',
'ppp',
'pppoe',
'pppoa',
'3g',
'qmi',
'ncm',
'hnet',
'pptp',
'6in4',
'aiccu',
'6to4',
'6rd',
'dslite',
'l2tp',
'relay',
'gre',
'gretap',
'grev6',
'grev6tap',
'none'
]
}
}
"oneOf": [{"$ref": "#/definitions/other_address"}]
}
}
}
Expand Down
160 changes: 124 additions & 36 deletions netjsonconfig/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,125 @@
"type": "object",
"additionalProperties": True,
"definitions": {
"base_address": {
"type": "object",
"additionalProperties": True,
"required": [
"proto",
"family",
],
"properties": {
"proto": {
"title": "protocol",
"type": "string",
"propertyOrder": 1,
},
"family": {
"type": "string",
"propertyOrder": 2,
}
}
},
"static_address": {
"type": "object",
"required": [
"address",
"mask"
],
"properties": {
"address": {
"type": "string",
"propertyOrder": 3,
},
"mask": {
"type": "integer",
"propertyOrder": 4,
},
"gateway": {
"type": "string",
"propertyOrder": 5,
}
}
},
"ipv4_address": {
"type": "object",
"title": "ipv4",
"allOf": [
{"$ref": "#/definitions/base_address"},
{"$ref": "#/definitions/static_address"},
{
"type": "object",
"properties": {
"proto": {"enum": ["static"]},
"family": {"enum": ["ipv4"]},
"address": {
"minLength": 8,
"maxLength": 16,
"format": "ipv4",
},
"mask": {
"minimum": 8,
"maxmium": 32,
"default": 24,
},
"gateway": {
"minLength": 8,
"maxLength": 16,
"format": "ipv4",
}
}
}
]
},
"ipv6_address": {
"type": "object",
"title": "ipv6",
"allOf": [
{"$ref": "#/definitions/base_address"},
{"$ref": "#/definitions/static_address"},
{
"type": "object",
"required": [
"address",
"mask"
],
"properties": {
"proto": {"enum": ["static"]},
"family": {"enum": ["ipv6"]},
"address": {
"minLength": 3,
"maxLength": 45,
"format": "ipv6",
"propertyOrder": 3,
},
"mask": {
"minimum": 4,
"maxmium": 128,
"default": 64,
},
"gateway": {
"minLength": 3,
"maxLength": 45,
"format": "ipv6",
}
}
}
]
},
"dhcp_address": {
"type": "object",
"title": "DHCP",
"allOf": [
{"$ref": "#/definitions/base_address"},
{
"type": "object",
"properties": {
"proto": {"enum": ["dhcp"]},
"family": {"enum": ["ipv4", "ipv6"]}
}
}
]
},
"interface_settings": {
"type": "object",
"title": "Interface settings",
Expand Down Expand Up @@ -55,43 +174,12 @@
"additionalItems": True,
"propertyOrder": 20,
"items": {
"type": "object",
"title": "Address",
"additionalProperties": True,
"required": [
"proto",
"family"
],
"properties": {
"proto": {
"type": "string",
"enum": [
"static",
"dhcp"
],
"propertyOrder": 1,
},
"family": {
"type": "string",
"enum": [
"ipv4",
"ipv6"
],
"propertyOrder": 2,
},
"address": {
"type": "string",
"propertyOrder": 3,
},
"mask": {
"type": "integer",
"propertyOrder": 4,
},
"gateway": {
"type": "string",
"propertyOrder": 5,
}
}
"oneOf": [
{"$ref": "#/definitions/dhcp_address"},
{"$ref": "#/definitions/ipv4_address"},
{"$ref": "#/definitions/ipv6_address"},
]
}
}
}
Expand Down

0 comments on commit 848e71e

Please sign in to comment.