From 10645a412b65b6f90e4a661a3306522238fa0fd6 Mon Sep 17 00:00:00 2001 From: grossmj Date: Tue, 5 May 2020 12:40:50 +0930 Subject: [PATCH] Default port set to 80 for server running in the GNS3 VM. Fixes #1737 --- gns3server/controller/__init__.py | 7 ++++- gns3server/controller/gns3vm/__init__.py | 28 ++++++++++--------- gns3server/controller/gns3vm/base_gns3_vm.py | 3 +- .../controller/gns3vm/virtualbox_gns3_vm.py | 5 ++-- gns3server/schemas/gns3vm.py | 6 ++++ 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/gns3server/controller/__init__.py b/gns3server/controller/__init__.py index a1640fa1..36f6422b 100644 --- a/gns3server/controller/__init__.py +++ b/gns3server/controller/__init__.py @@ -205,7 +205,12 @@ class Controller: # load GNS3 VM settings if "gns3vm" in controller_settings: - self.gns3vm.settings = controller_settings["gns3vm"] + gns3_vm_settings = controller_settings["gns3vm"] + if "port" not in gns3_vm_settings: + # port setting was added in version 2.2.8 + # the default port was 3080 before this + gns3_vm_settings["port"] = 3080 + self.gns3vm.settings = gns3_vm_settings # load the IOU license settings if "iou_license" in controller_settings: diff --git a/gns3server/controller/gns3vm/__init__.py b/gns3server/controller/gns3vm/__init__.py index 885916e1..795e15a8 100644 --- a/gns3server/controller/gns3vm/__init__.py +++ b/gns3server/controller/gns3vm/__init__.py @@ -39,7 +39,7 @@ class GNS3VM: Proxy between the controller and the GNS3 VM engine """ - def __init__(self, controller, settings={}): + def __init__(self, controller): self._controller = controller # Keep instance of the loaded engines self._engines = {} @@ -50,9 +50,9 @@ class GNS3VM: "enable": False, "engine": "vmware", "ram": 2048, - "vcpus": 1 + "vcpus": 1, + "port": 80, } - self.settings = settings def engine_list(self): """ @@ -72,10 +72,11 @@ class GNS3VM: else: vmware_info["name"] = "VMware Workstation / Player (recommended)" + download_url = "https://github.com/GNS3/gns3-gui/releases/download/v{version}/GNS3.VM.Hyper-V.{version}.zip".format(version=__version__) hyperv_info = { "engine_id": "hyper-v", "name": "Hyper-V", - "description": 'Hyper-V support (Windows 10/Server 2016 and above). Nested virtualization must be supported and enabled (Intel processor only)', + "description": 'Hyper-V support (Windows 10/Server 2016 and above). Nested virtualization must be supported and enabled (Intel processor only)
The GNS3 VM can be downloaded here'.format(download_url), "support_when_exit": True, "support_headless": False, "support_ram": True @@ -85,7 +86,7 @@ class GNS3VM: virtualbox_info = { "engine_id": "virtualbox", "name": "VirtualBox", - "description": 'VirtualBox doesn\'t support nested virtualization, this means Qemu based VMs will run extremely slowly.
The GNS3 VM can be downloaded here'.format(download_url), + "description": 'VirtualBox support. Nested virtualization for both Intel and AMD processors is supported since version 6.1
The GNS3 VM can be downloaded here'.format(download_url), "support_when_exit": True, "support_headless": True, "support_ram": True @@ -278,9 +279,9 @@ class GNS3VM: # User will receive the error later when they will try to use the node try: compute = await self._controller.add_compute(compute_id="vm", - name="GNS3 VM ({})".format(self.current_engine().vmname), - host=None, - force=True) + name="GNS3 VM ({})".format(self.current_engine().vmname), + host=None, + force=True) compute.set_last_error(str(e)) except aiohttp.web.HTTPConflict: @@ -313,6 +314,7 @@ class GNS3VM: engine.ram = self._settings["ram"] engine.vcpus = self._settings["vcpus"] engine.headless = self._settings["headless"] + engine.port = self._settings["port"] compute = await self._controller.add_compute(compute_id="vm", name="GNS3 VM is starting ({})".format(engine.vmname), host=None, @@ -329,11 +331,11 @@ class GNS3VM: raise e await compute.connect() # we can connect now that the VM has started await compute.update(name="GNS3 VM ({})".format(engine.vmname), - protocol=self.protocol, - host=self.ip_address, - port=self.port, - user=self.user, - password=self.password) + protocol=self.protocol, + host=self.ip_address, + port=self.port, + user=self.user, + password=self.password) # check if the VM is in the same subnet as the local server, start 10 seconds later to give # some time for the compute in the VM to be ready for requests diff --git a/gns3server/controller/gns3vm/base_gns3_vm.py b/gns3server/controller/gns3vm/base_gns3_vm.py index 64305573..c111989a 100644 --- a/gns3server/controller/gns3vm/base_gns3_vm.py +++ b/gns3server/controller/gns3vm/base_gns3_vm.py @@ -15,7 +15,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import asyncio import psutil import logging @@ -29,7 +28,7 @@ class BaseGNS3VM: self._controller = controller self._vmname = None self._ip_address = None - self._port = 3080 + self._port = 80 # value not used, will be overwritten self._headless = False self._vcpus = 1 self._ram = 1024 diff --git a/gns3server/controller/gns3vm/virtualbox_gns3_vm.py b/gns3server/controller/gns3vm/virtualbox_gns3_vm.py index 8561fe5d..9a656955 100644 --- a/gns3server/controller/gns3vm/virtualbox_gns3_vm.py +++ b/gns3server/controller/gns3vm/virtualbox_gns3_vm.py @@ -285,13 +285,12 @@ class VirtualBoxGNS3VM(BaseGNS3VM): log.info("Removing GNS3VM NAT port forwarding rule from interface {}".format(nat_interface_number)) await self._execute("controlvm", [self._vmname, "natpf{}".format(nat_interface_number), "delete", "GNS3VM"]) - # add a GNS3VM NAT port forwarding rule to redirect 127.0.0.1 with random port to port 3080 in the VM + # add a GNS3VM NAT port forwarding rule to redirect 127.0.0.1 with random port to the port in the VM log.info("Adding GNS3VM NAT port forwarding rule with port {} to interface {}".format(api_port, nat_interface_number)) await self._execute("controlvm", [self._vmname, "natpf{}".format(nat_interface_number), - "GNS3VM,tcp,{},{},,3080".format(ip_address, api_port)]) + "GNS3VM,tcp,{},{},,{}".format(ip_address, api_port, self.port)]) self.ip_address = await self._get_ip(hostonly_interface_number, api_port) - self.port = 3080 log.info("GNS3 VM has been started with IP {}".format(self.ip_address)) self.running = True diff --git a/gns3server/schemas/gns3vm.py b/gns3server/schemas/gns3vm.py index 98c73273..c713c8d2 100644 --- a/gns3server/schemas/gns3vm.py +++ b/gns3server/schemas/gns3vm.py @@ -48,6 +48,12 @@ GNS3VM_SETTINGS_SCHEMA = { "ram": { "description": "Amount of ram affected to the VM", "type": "integer" + }, + "port": { + "description": "Server port", + "type": "integer", + "minimum": 1, + "maximum": 65535 } }, "additionalProperties": False