1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-13 20:08:55 +00:00

Support for "usage" for "Cloud" nodes. Fixes https://github.com/GNS3/gns3-gui/issues/2887

Allow "usage" for all builtin nodes (not exposed in Ui).
This commit is contained in:
grossmj 2020-07-15 19:15:51 +09:30
parent d11897c1ec
commit dff035d957
26 changed files with 100 additions and 35 deletions

View File

@ -85,6 +85,7 @@ class Cloud(BaseNode):
"special": interface["special"]})
return {"name": self.name,
"usage": self.usage,
"node_id": self.id,
"project_id": self.project.id,
"remote_console_host": self.remote_console_host,

View File

@ -41,6 +41,7 @@ class EthernetHub(BaseNode):
def __json__(self):
return {"name": self.name,
"usage": self.usage,
"node_id": self.id,
"project_id": self.project.id}

View File

@ -41,6 +41,7 @@ class EthernetSwitch(BaseNode):
def __json__(self):
return {"name": self.name,
"usage": self.usage,
"node_id": self.id,
"project_id": self.project.id}

View File

@ -75,6 +75,7 @@ class Nat(Cloud):
def __json__(self):
return {
"name": self.name,
"usage": self.usage,
"node_id": self.id,
"project_id": self.project.id,
"status": "started",

View File

@ -59,6 +59,7 @@ class ATMSwitch(Device):
mappings[source] = destination
return {"name": self.name,
"usage": self.usage,
"node_id": self.id,
"project_id": self.project.id,
"mappings": mappings,

View File

@ -31,6 +31,7 @@ class Device:
def __init__(self, name, node_id, project, manager, hypervisor=None):
self._name = name
self._usage = ""
self._id = node_id
self._project = project
self._manager = manager
@ -76,6 +77,26 @@ class Device:
self._name = new_name
@property
def usage(self):
"""
Returns the usage for this device.
:returns: usage
"""
return self._usage
@usage.setter
def usage(self, new_usage):
"""
Sets the usage of this device.
:param new_usage: usage
"""
self._usage = new_usage
@property
def id(self):
"""

View File

@ -57,6 +57,7 @@ class EthernetHub(Bridge):
def __json__(self):
return {"name": self.name,
"usage": self.usage,
"node_id": self.id,
"project_id": self.project.id,
"ports_mapping": self._ports,

View File

@ -109,6 +109,7 @@ class EthernetSwitch(Device):
def __json__(self):
ethernet_switch_info = {"name": self.name,
"usage": self.usage,
"console": self.console,
"console_type": self.console_type,
"node_id": self.id,

View File

@ -58,6 +58,7 @@ class FrameRelaySwitch(Device):
mappings[source] = destination
return {"name": self.name,
"usage": self.usage,
"node_id": self.id,
"project_id": self.project.id,
"mappings": mappings,

View File

@ -53,17 +53,17 @@ class CloudHandler:
builtin_manager = Builtin.instance()
node = await builtin_manager.create_node(request.json.pop("name"),
request.match_info["project_id"],
request.json.get("node_id"),
node_type="cloud",
ports=request.json.get("ports_mapping"))
request.match_info["project_id"],
request.json.get("node_id"),
node_type="cloud",
ports=request.json.get("ports_mapping"))
# add the remote console settings
node.remote_console_host = request.json.get("remote_console_host", node.remote_console_host)
node.remote_console_port = request.json.get("remote_console_port", node.remote_console_port)
node.remote_console_type = request.json.get("remote_console_type", node.remote_console_type)
node.remote_console_http_path = request.json.get("remote_console_http_path", node.remote_console_http_path)
node.usage = request.json.get("usage", "")
response.set_status(201)
response.json(node)

View File

@ -27,6 +27,10 @@ ATM_SWITCH_CREATE_SCHEMA = {
"type": "string",
"minLength": 1,
},
"usage": {
"description": "How to use the ATM switch",
"type": "string",
},
"node_id": {
"description": "Node UUID",
"oneOf": [
@ -55,6 +59,10 @@ ATM_SWITCH_OBJECT_SCHEMA = {
"type": "string",
"minLength": 1,
},
"usage": {
"description": "How to use the ATM switch",
"type": "string",
},
"node_id": {
"description": "Node UUID",
"type": "string",

View File

@ -53,6 +53,10 @@ CLOUD_CREATE_SCHEMA = {
"type": "string",
"minLength": 1,
},
"usage": {
"description": "How to use the cloud",
"type": "string",
},
"node_id": {
"description": "Node UUID",
"oneOf": [
@ -113,6 +117,10 @@ CLOUD_OBJECT_SCHEMA = {
"type": "string",
"minLength": 1,
},
"usage": {
"description": "How to use the cloud",
"type": "string",
},
"node_id": {
"description": "Node UUID",
"type": "string",

View File

@ -26,11 +26,6 @@ DOCKER_TEMPLATE_PROPERTIES = {
"type": "string",
"minLength": 1
},
"usage": {
"description": "How to use the Docker container",
"type": "string",
"default": ""
},
"adapters": {
"description": "Number of adapters",
"type": "integer",

View File

@ -30,11 +30,6 @@ DYNAMIPS_TEMPLATE_PROPERTIES = {
"type": "string",
"minLength": 1
},
"usage": {
"description": "How to use the Dynamips VM",
"type": "string",
"default": ""
},
"mmap": {
"description": "MMAP feature",
"type": "boolean",

View File

@ -46,6 +46,10 @@ ETHERNET_HUB_CREATE_SCHEMA = {
"type": "string",
"minLength": 1,
},
"usage": {
"description": "How to use the hub",
"type": "string",
},
"node_id": {
"description": "Node UUID",
"oneOf": [
@ -98,6 +102,10 @@ ETHERNET_HUB_OBJECT_SCHEMA = {
"type": "string",
"minLength": 1,
},
"usage": {
"description": "How to use the hub",
"type": "string",
},
"node_id": {
"description": "Node UUID",
"type": "string",

View File

@ -58,6 +58,10 @@ ETHERNET_SWITCH_CREATE_SCHEMA = {
"type": "string",
"minLength": 1,
},
"usage": {
"description": "How to use the switch",
"type": "string",
},
"console": {
"description": "Console TCP port",
"minimum": 1,
@ -132,6 +136,10 @@ ETHERNET_SWITCH_OBJECT_SCHEMA = {
"type": "string",
"minLength": 1,
},
"usage": {
"description": "How to use the switch",
"type": "string",
},
"node_id": {
"description": "Node UUID",
"type": "string",

View File

@ -27,6 +27,10 @@ FRAME_RELAY_SWITCH_CREATE_SCHEMA = {
"type": "string",
"minLength": 1,
},
"usage": {
"description": "How to use the Frame Relay switch",
"type": "string",
},
"node_id": {
"description": "Node UUID",
"oneOf": [
@ -55,6 +59,10 @@ FRAME_RELAY_SWITCH_OBJECT_SCHEMA = {
"type": "string",
"minLength": 1,
},
"usage": {
"description": "How to use the Frame Relay switch",
"type": "string",
},
"node_id": {
"description": "Node UUID",
"type": "string",

View File

@ -25,11 +25,6 @@ IOU_TEMPLATE_PROPERTIES = {
"type": "string",
"minLength": 1
},
"usage": {
"description": "How to use the IOU VM",
"type": "string",
"default": ""
},
"ethernet_adapters": {
"description": "Number of ethernet adapters",
"type": "integer",

View File

@ -28,6 +28,10 @@ NAT_OBJECT_SCHEMA = {
"type": "string",
"minLength": 1,
},
"usage": {
"description": "How to use the Nat instance",
"type": "string",
},
"node_id": {
"description": "Node UUID",
"type": "string",

View File

@ -27,11 +27,6 @@ QEMU_TEMPLATE_PROPERTIES = {
"type": "string",
"default": ""
},
"usage": {
"description": "How to use the Qemu VM",
"type": "string",
"default": ""
},
"platform": {
"description": "Platform to emulate",
"enum": QEMU_PLATFORMS,

View File

@ -35,6 +35,11 @@ BASE_TEMPLATE_PROPERTIES = {
"type": "string",
"minLength": 1,
},
"usage": {
"description": "How to use this template",
"type": "string",
"default": ""
},
"compute_id": {
"description": "Compute identifier",
"type": ["null", "string"]

View File

@ -26,11 +26,6 @@ VIRTUALBOX_TEMPLATE_PROPERTIES = {
"type": "string",
"minLength": 1,
},
"usage": {
"description": "How to use the VirtualBox VM",
"type": "string",
"default": ""
},
"ram": {
"description": "Amount of RAM",
"minimum": 0,

View File

@ -26,11 +26,6 @@ VMWARE_TEMPLATE_PROPERTIES = {
"type": "string",
"minLength": 1,
},
"usage": {
"description": "How to use the VMware VM",
"type": "string",
"default": ""
},
"linked_clone": {
"description": "Whether the VM is a linked clone or not",
"type": "boolean",

View File

@ -26,6 +26,10 @@ VPCS_CREATE_SCHEMA = {
"type": "string",
"minLength": 1,
},
"usage": {
"description": "How to use the VPCS VM",
"type": "string",
},
"node_id": {
"description": "Node UUID",
"oneOf": [
@ -65,6 +69,10 @@ VPCS_UPDATE_SCHEMA = {
"type": ["string", "null"],
"minLength": 1,
},
"usage": {
"description": "How to use the VPCS VM",
"type": "string",
},
"console": {
"description": "Console TCP port",
"minimum": 1,
@ -89,6 +97,10 @@ VPCS_OBJECT_SCHEMA = {
"type": "string",
"minLength": 1,
},
"usage": {
"description": "How to use the VPCS VM",
"type": "string",
},
"node_id": {
"description": "Node UUID",
"type": "string",

View File

@ -51,6 +51,7 @@ async def test_json_with_ports(on_gns3vm, compute_project, manager):
cloud = Cloud("cloud1", str(uuid.uuid4()), compute_project, manager, ports=ports)
assert cloud.__json__() == {
"name": "cloud1",
"usage": "",
"node_id": cloud.id,
"project_id": compute_project.id,
"remote_console_host": "",
@ -83,6 +84,7 @@ def test_json_without_ports(on_gns3vm, compute_project, manager):
cloud = Cloud("cloud1", str(uuid.uuid4()), compute_project, manager, ports=None)
assert cloud.__json__() == {
"name": "cloud1",
"usage": "",
"node_id": cloud.id,
"project_id": compute_project.id,
"remote_console_host": "",

View File

@ -26,6 +26,7 @@ def test_json_gns3vm(on_gns3vm, compute_project):
nat = Nat("nat1", str(uuid.uuid4()), compute_project, MagicMock())
assert nat.__json__() == {
"name": "nat1",
"usage": "",
"node_id": nat.id,
"project_id": compute_project.id,
"status": "started",
@ -48,6 +49,7 @@ def test_json_darwin(darwin_platform, compute_project):
nat = Nat("nat1", str(uuid.uuid4()), compute_project, MagicMock())
assert nat.__json__() == {
"name": "nat1",
"usage": "",
"node_id": nat.id,
"project_id": compute_project.id,
"status": "started",
@ -68,6 +70,7 @@ def test_json_windows_with_full_name_of_interface(windows_platform, project):
nat = Nat("nat1", str(uuid.uuid4()), project, MagicMock())
assert nat.__json__() == {
"name": "nat1",
"usage": "",
"node_id": nat.id,
"project_id": project.id,
"status": "started",