diff --git a/gns3server/controller/gns3vm/__init__.py b/gns3server/controller/gns3vm/__init__.py index 6a745d15..c18e60a4 100644 --- a/gns3server/controller/gns3vm/__init__.py +++ b/gns3server/controller/gns3vm/__init__.py @@ -49,6 +49,7 @@ class GNS3VM: "headless": False, "enable": False, "engine": "vmware", + "allocate_vcpus_ram": True, "ram": 2048, "vcpus": 1, "port": 80, @@ -311,6 +312,7 @@ class GNS3VM: if self._settings["vmname"] is None: return log.info("Start the GNS3 VM") + engine.allocate_vcpus_ram = self._settings["allocate_vcpus_ram"] engine.vmname = self._settings["vmname"] engine.ram = self._settings["ram"] engine.vcpus = self._settings["vcpus"] diff --git a/gns3server/controller/gns3vm/base_gns3_vm.py b/gns3server/controller/gns3vm/base_gns3_vm.py index c111989a..14d8aae4 100644 --- a/gns3server/controller/gns3vm/base_gns3_vm.py +++ b/gns3server/controller/gns3vm/base_gns3_vm.py @@ -30,6 +30,7 @@ class BaseGNS3VM: self._ip_address = None self._port = 80 # value not used, will be overwritten self._headless = False + self._allocate_vcpus_ram = True self._vcpus = 1 self._ram = 1024 self._user = "" @@ -203,6 +204,26 @@ class BaseGNS3VM: self._headless = value + @property + def allocate_vcpus_ram(self): + """ + Returns whether VCPUs and RAM settings should be configured for the GNS3 VM. + + :returns: boolean + """ + + return self._allocate_vcpus_ram + + @allocate_vcpus_ram.setter + def allocate_vcpus_ram(self, value): + """ + Sets whether VCPUs and RAM settings should be configured for the GNS3 VM. + + :param value: boolean + """ + + self._allocate_vcpus_ram = value + @property def vcpus(self): """ diff --git a/gns3server/controller/gns3vm/hyperv_gns3_vm.py b/gns3server/controller/gns3vm/hyperv_gns3_vm.py index e756635c..45186cdf 100644 --- a/gns3server/controller/gns3vm/hyperv_gns3_vm.py +++ b/gns3server/controller/gns3vm/hyperv_gns3_vm.py @@ -251,9 +251,10 @@ class HyperVGNS3VM(BaseGNS3VM): raise GNS3VMError("Could not find Hyper-V VM {}".format(self.vmname)) if not self._is_running(): - log.info("Update GNS3 VM settings (CPU and RAM)") - # set the number of vCPUs and amount of RAM - self._set_vcpus_ram(self.vcpus, self.ram) + if self.allocate_vcpus_ram: + log.info("Update GNS3 VM settings (CPU and RAM)") + # set the number of vCPUs and amount of RAM + self._set_vcpus_ram(self.vcpus, self.ram) # start the VM try: diff --git a/gns3server/controller/gns3vm/remote_gns3_vm.py b/gns3server/controller/gns3vm/remote_gns3_vm.py index 48a89d53..386c0a20 100644 --- a/gns3server/controller/gns3vm/remote_gns3_vm.py +++ b/gns3server/controller/gns3vm/remote_gns3_vm.py @@ -15,8 +15,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import asyncio - from .base_gns3_vm import BaseGNS3VM from .gns3_vm_error import GNS3VMError diff --git a/gns3server/controller/gns3vm/virtualbox_gns3_vm.py b/gns3server/controller/gns3vm/virtualbox_gns3_vm.py index 874cca36..ddb6b3ea 100644 --- a/gns3server/controller/gns3vm/virtualbox_gns3_vm.py +++ b/gns3server/controller/gns3vm/virtualbox_gns3_vm.py @@ -259,9 +259,12 @@ class VirtualBoxGNS3VM(BaseGNS3VM): log.info('"{}" state is {}'.format(self._vmname, vm_state)) if vm_state == "poweroff": - log.info("Update GNS3 VM settings (CPU, RAM and Hardware Virtualization)") - await self.set_vcpus(self.vcpus) - await self.set_ram(self.ram) + if self.allocate_vcpus_ram: + log.info("Update GNS3 VM vCPUs and RAM settings") + await self.set_vcpus(self.vcpus) + await self.set_ram(self.ram) + + log.info("Update GNS3 VM Hardware Virtualization setting") await self.enable_nested_hw_virt() if vm_state in ("poweroff", "saved"): diff --git a/gns3server/controller/gns3vm/vmware_gns3_vm.py b/gns3server/controller/gns3vm/vmware_gns3_vm.py index a7a03e8e..44bc38f3 100644 --- a/gns3server/controller/gns3vm/vmware_gns3_vm.py +++ b/gns3server/controller/gns3vm/vmware_gns3_vm.py @@ -148,9 +148,12 @@ class VMwareGNS3VM(BaseGNS3VM): except VMwareError as e: raise GNS3VMError("Could not list VMware VMs: {}".format(str(e))) if not running: - log.info("Update GNS3 VM settings (CPU, RAM and Hardware Virtualization)") # set the number of vCPUs and amount of RAM - await self._set_vcpus_ram(self.vcpus, self.ram) + if self.allocate_vcpus_ram: + log.info("Update GNS3 VM vCPUs and RAM settings") + await self._set_vcpus_ram(self.vcpus, self.ram) + + log.info("Update GNS3 VM Hardware Virtualization setting") await self._set_extra_options() # start the VM diff --git a/gns3server/schemas/gns3vm.py b/gns3server/schemas/gns3vm.py index c713c8d2..32367eb8 100644 --- a/gns3server/schemas/gns3vm.py +++ b/gns3server/schemas/gns3vm.py @@ -41,6 +41,10 @@ GNS3VM_SETTINGS_SCHEMA = { "description": "The engine to use for the VM. Null to disable", "enum": ["vmware", "virtualbox", None] }, + "allocate_vcpus_ram": { + "description": "Allocate vCPUS and RAM settings", + "type": "boolean" + }, "vcpus": { "description": "Number of vCPUS affected to the VM", "type": "integer"