1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 03:08:14 +00:00

Option to allocate or not the vCPUs and RAM settings for the GNS3 VM. Fixes https://github.com/GNS3/gns3-gui/issues/3069

This commit is contained in:
grossmj 2020-11-05 11:13:57 +10:30
parent e182f53d69
commit d16cb5ef89
7 changed files with 42 additions and 10 deletions

View File

@ -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"]

View File

@ -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):
"""

View File

@ -251,6 +251,7 @@ class HyperVGNS3VM(BaseGNS3VM):
raise GNS3VMError("Could not find Hyper-V VM {}".format(self.vmname))
if not self._is_running():
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)

View File

@ -15,8 +15,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import asyncio
from .base_gns3_vm import BaseGNS3VM
from .gns3_vm_error import GNS3VMError

View File

@ -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)")
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"):

View File

@ -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
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

View File

@ -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"