From 1f017a0d1d8d65e93cc99c8555fc9ac05c23551e Mon Sep 17 00:00:00 2001 From: grossmj Date: Sun, 10 Jun 2018 17:43:29 +0700 Subject: [PATCH] Console support for clouds (to connect to external devices or services). --- gns3server/compute/builtin/nodes/cloud.py | 88 +++++++++++++++++++ .../handlers/api/compute/cloud_handler.py | 7 ++ gns3server/schemas/cloud.py | 36 ++++++++ 3 files changed, 131 insertions(+) diff --git a/gns3server/compute/builtin/nodes/cloud.py b/gns3server/compute/builtin/nodes/cloud.py index fd428d73..15bd544c 100644 --- a/gns3server/compute/builtin/nodes/cloud.py +++ b/gns3server/compute/builtin/nodes/cloud.py @@ -46,6 +46,10 @@ class Cloud(BaseNode): super().__init__(name, node_id, project, manager) self._nios = {} + self._remote_console_host = "" + self._remote_console_port = 23 + self._remote_console_type = "none" + self._remote_console_http_path = "/" # Populate the cloud with host interfaces if it is not configured if not ports or len(ports) == 0: @@ -84,12 +88,96 @@ class Cloud(BaseNode): return {"name": self.name, "node_id": self.id, "project_id": self.project.id, + "remote_console_host": self.remote_console_host, + "remote_console_port": self.remote_console_port, + "remote_console_type": self.remote_console_type, + "remote_console_http_path": self.remote_console_http_path, "ports_mapping": self._ports_mapping, "interfaces": host_interfaces, "status": self.status, "node_directory": self.working_path } + @property + def remote_console_host(self): + """ + Returns the remote console host for this cloud. + + :returns: remote console host + """ + + return self._remote_console_host + + @remote_console_host.setter + def remote_console_host(self, remote_console_host): + """ + Sets the remote console host for this cloud. + + :param remote_console_host: remote console host + """ + + self._remote_console_host = remote_console_host + + @property + def remote_console_port(self): + """ + Returns the remote console port for this cloud. + + :returns: remote console port + """ + + return self._remote_console_port + + @remote_console_port.setter + def remote_console_port(self, remote_console_port): + """ + Sets the remote console port for this cloud. + + :param remote_console_port: remote console port + """ + + self._remote_console_port = remote_console_port + + @property + def remote_console_type(self): + """ + Returns the remote console type for this cloud. + + :returns: remote console host + """ + + return self._remote_console_type + + @remote_console_type.setter + def remote_console_type(self, remote_console_type): + """ + Sets the remote console type for this cloud. + + :param remote_console_type: remote console type + """ + + self._remote_console_type = remote_console_type + + @property + def remote_console_http_path(self): + """ + Returns the remote console HTTP path for this cloud. + + :returns: remote console HTTP path + """ + + return self._remote_console_http_path + + @remote_console_http_path.setter + def remote_console_http_path(self, remote_console_http_path): + """ + Sets the remote console HTTP path for this cloud. + + :param remote_console_http_path: remote console HTTP path + """ + + self._remote_console_http_path = remote_console_http_path + @property def ports_mapping(self): """ diff --git a/gns3server/handlers/api/compute/cloud_handler.py b/gns3server/handlers/api/compute/cloud_handler.py index d29a4eeb..f4bd1db3 100644 --- a/gns3server/handlers/api/compute/cloud_handler.py +++ b/gns3server/handlers/api/compute/cloud_handler.py @@ -57,6 +57,13 @@ class CloudHandler: 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) + response.set_status(201) response.json(node) diff --git a/gns3server/schemas/cloud.py b/gns3server/schemas/cloud.py index aaf58467..190a5e6d 100644 --- a/gns3server/schemas/cloud.py +++ b/gns3server/schemas/cloud.py @@ -62,6 +62,24 @@ CLOUD_CREATE_SCHEMA = { "pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"} ] }, + "remote_console_host": { + "description": "Remote console host or IP", + "type": ["string"] + }, + "remote_console_port": { + "description": "Console TCP port", + "minimum": 1, + "maximum": 65535, + "type": ["integer", "null"] + }, + "remote_console_type": { + "description": "Console type", + "enum": ["telnet", "vnc", "spice", "http", "https", "none"] + }, + "remote_console_http_path": { + "description": "Path of the remote web interface", + "type": "string", + }, "ports_mapping": { "type": "array", "items": [ @@ -109,6 +127,24 @@ CLOUD_OBJECT_SCHEMA = { "maxLength": 36, "pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" }, + "remote_console_host": { + "description": "Remote console host or IP", + "type": ["string"] + }, + "remote_console_port": { + "description": "Console TCP port", + "minimum": 1, + "maximum": 65535, + "type": ["integer", "null"] + }, + "remote_console_type": { + "description": "Console type", + "enum": ["telnet", "vnc", "spice", "http", "https", "none"] + }, + "remote_console_http_path": { + "description": "Path of the remote web interface", + "type": "string", + }, "ports_mapping": { "type": "array", "items": [