1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-24 15:58:08 +00:00

Fix Ethernet switch and Ethernet hub port validations. Fixes #2334

This commit is contained in:
grossmj 2024-01-11 22:40:38 +11:00
parent b4edbbbaa7
commit 13d9afd8bc
No known key found for this signature in database
GPG Key ID: 0A2D76AC45EA25CD
2 changed files with 64 additions and 116 deletions

View File

@ -17,28 +17,30 @@
import copy import copy
ETHERNET_HUB_PORT_SCHEMA = {
"description": "Ethernet port",
"properties": {
"name": {
"description": "Port name",
"type": "string",
"minLength": 1,
},
"port_number": {
"description": "Port number",
"type": "integer",
"minimum": 0
},
},
"required": ["name", "port_number"],
"additionalProperties": False
}
ETHERNET_HUB_CREATE_SCHEMA = { ETHERNET_HUB_CREATE_SCHEMA = {
"$schema": "http://json-schema.org/draft-04/schema#", "$schema": "http://json-schema.org/draft-04/schema#",
"description": "Request validation to create a new Ethernet hub instance", "description": "Request validation to create a new Ethernet hub instance",
"type": "object", "type": "object",
"definitions": { "definitions": {
"EthernetHubPort": { "EthernetHubPort": ETHERNET_HUB_PORT_SCHEMA
"description": "Ethernet port",
"properties": {
"name": {
"description": "Port name",
"type": "string",
"minLength": 1,
},
"port_number": {
"description": "Port number",
"type": "integer",
"minimum": 0
},
},
"required": ["name", "port_number"],
"additionalProperties": False
},
}, },
"properties": { "properties": {
"name": { "name": {
@ -57,12 +59,9 @@ ETHERNET_HUB_CREATE_SCHEMA = {
}, },
"ports_mapping": { "ports_mapping": {
"type": "array", "type": "array",
"items": [ "items": {
{"type": "object", "$ref": "#/definitions/EthernetHubPort"
"oneOf": [ }
{"$ref": "#/definitions/EthernetHubPort"}
]},
]
}, },
}, },
"additionalProperties": False, "additionalProperties": False,
@ -74,23 +73,7 @@ ETHERNET_HUB_OBJECT_SCHEMA = {
"description": "Ethernet hub instance", "description": "Ethernet hub instance",
"type": "object", "type": "object",
"definitions": { "definitions": {
"EthernetHubPort": { "EthernetHubPort": ETHERNET_HUB_PORT_SCHEMA
"description": "Ethernet port",
"properties": {
"name": {
"description": "Port name",
"type": "string",
"minLength": 1,
},
"port_number": {
"description": "Port number",
"type": "integer",
"minimum": 0
},
},
"required": ["name", "port_number"],
"additionalProperties": False
},
}, },
"properties": { "properties": {
"name": { "name": {
@ -114,12 +97,9 @@ ETHERNET_HUB_OBJECT_SCHEMA = {
}, },
"ports_mapping": { "ports_mapping": {
"type": "array", "type": "array",
"items": [ "items": {
{"type": "object", "$ref": "#/definitions/EthernetHubPort"
"oneOf": [ }
{"$ref": "#/definitions/EthernetHubPort"}
]},
]
}, },
"status": { "status": {
"description": "Node status", "description": "Node status",

View File

@ -17,40 +17,42 @@
import copy import copy
ETHERNET_SWITCH_PORT_SCHEMA = {
"description": "Ethernet switch port",
"properties": {
"name": {
"description": "Port name",
"type": "string",
"minLength": 1,
},
"port_number": {
"description": "Port number",
"type": "integer",
"minimum": 0
},
"type": {
"description": "Port type",
"enum": ["access", "dot1q", "qinq"],
},
"vlan": {"description": "VLAN number",
"type": "integer",
"minimum": 1
},
"ethertype": {
"description": "QinQ Ethertype",
"enum": ["", "0x8100", "0x88A8", "0x9100", "0x9200"],
},
},
"required": ["name", "port_number", "type"],
"additionalProperties": False
}
ETHERNET_SWITCH_CREATE_SCHEMA = { ETHERNET_SWITCH_CREATE_SCHEMA = {
"$schema": "http://json-schema.org/draft-04/schema#", "$schema": "http://json-schema.org/draft-04/schema#",
"description": "Request validation to create a new Ethernet switch instance", "description": "Request validation to create a new Ethernet switch instance",
"type": "object", "type": "object",
"definitions": { "definitions": {
"EthernetSwitchPort": { "EthernetSwitchPort": ETHERNET_SWITCH_PORT_SCHEMA
"description": "Ethernet port",
"properties": {
"name": {
"description": "Port name",
"type": "string",
"minLength": 1,
},
"port_number": {
"description": "Port number",
"type": "integer",
"minimum": 0
},
"type": {
"description": "Port type",
"enum": ["access", "dot1q", "qinq"],
},
"vlan": {"description": "VLAN number",
"type": "integer",
"minimum": 1
},
"ethertype": {
"description": "QinQ Ethertype",
"enum": ["", "0x8100", "0x88A8", "0x9100", "0x9200"],
},
},
"required": ["name", "port_number", "type"],
"additionalProperties": False
},
}, },
"properties": { "properties": {
"name": { "name": {
@ -79,12 +81,9 @@ ETHERNET_SWITCH_CREATE_SCHEMA = {
}, },
"ports_mapping": { "ports_mapping": {
"type": "array", "type": "array",
"items": [ "items": {
{"type": "object", "$ref": "#/definitions/EthernetSwitchPort"
"oneOf": [ }
{"$ref": "#/definitions/EthernetSwitchPort"}
]},
]
}, },
}, },
"additionalProperties": False, "additionalProperties": False,
@ -96,35 +95,7 @@ ETHERNET_SWITCH_OBJECT_SCHEMA = {
"description": "Ethernet switch instance", "description": "Ethernet switch instance",
"type": "object", "type": "object",
"definitions": { "definitions": {
"EthernetSwitchPort": { "EthernetSwitchPort": ETHERNET_SWITCH_PORT_SCHEMA
"description": "Ethernet port",
"properties": {
"name": {
"description": "Port name",
"type": "string",
"minLength": 1,
},
"port_number": {
"description": "Port number",
"type": "integer",
"minimum": 0
},
"type": {
"description": "Port type",
"enum": ["access", "dot1q", "qinq"],
},
"vlan": {"description": "VLAN number",
"type": "integer",
"minimum": 1
},
"ethertype": {
"description": "QinQ Ethertype",
"enum": ["", "0x8100", "0x88A8", "0x9100", "0x9200"],
},
},
"required": ["name", "port_number", "type"],
"additionalProperties": False
},
}, },
"properties": { "properties": {
"name": { "name": {
@ -148,12 +119,9 @@ ETHERNET_SWITCH_OBJECT_SCHEMA = {
}, },
"ports_mapping": { "ports_mapping": {
"type": "array", "type": "array",
"items": [ "items": {
{"type": "object", "$ref": "#/definitions/EthernetSwitchPort"
"oneOf": [ }
{"$ref": "#/definitions/EthernetSwitchPort"}
]},
]
}, },
"status": { "status": {
"description": "Node status", "description": "Node status",