mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 09:18:08 +00:00
Support configuration of ram and vcpus of GNS3 VM in setup wizard
Ref #1445
This commit is contained in:
parent
d2b0321419
commit
896d279ded
@ -44,7 +44,9 @@ class GNS3VM:
|
||||
"when_exit": "stop",
|
||||
"headless": False,
|
||||
"enable": False,
|
||||
"engine": "vmware"
|
||||
"engine": "vmware",
|
||||
"ram": 2048,
|
||||
"vcpus": 1
|
||||
}
|
||||
self.settings = settings
|
||||
|
||||
@ -178,7 +180,12 @@ class GNS3VM:
|
||||
yield from self._stop()
|
||||
self._settings = settings
|
||||
self._controller.save()
|
||||
yield from self.auto_start_vm()
|
||||
if self.enable:
|
||||
yield from self.start()
|
||||
else:
|
||||
# When user fix something on his system and try again
|
||||
if not self._current_engine().running and self.enable:
|
||||
yield from self.auto_start_vm()
|
||||
|
||||
def _get_engine(self, engine):
|
||||
"""
|
||||
@ -247,6 +254,8 @@ class GNS3VM:
|
||||
if not engine.running:
|
||||
log.info("Start the GNS3 VM")
|
||||
engine.vmname = self._settings["vmname"]
|
||||
engine.ram = self._settings["ram"]
|
||||
engine.vpcus = self._settings["vcpus"]
|
||||
yield from engine.start()
|
||||
yield from self._controller.add_compute(compute_id="vm",
|
||||
name="GNS3 VM ({})".format(engine.vmname),
|
||||
|
@ -174,6 +174,11 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
|
||||
|
||||
vm_state = yield from self._get_state()
|
||||
log.info('"{}" state is {}'.format(self._vmname, vm_state))
|
||||
|
||||
if vm_state == "poweroff":
|
||||
yield from self.set_vcpus(self.vpcus)
|
||||
yield from self.set_ram(self.ram)
|
||||
|
||||
if vm_state in ("poweroff", "saved"):
|
||||
# start the VM if it is not running
|
||||
args = [self._vmname]
|
||||
@ -272,7 +277,7 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
|
||||
:param vcpus: number of vCPU cores
|
||||
"""
|
||||
|
||||
yield from self.execute("modifyvm", [self._vmname, "--cpus", str(vcpus)], timeout=3)
|
||||
yield from self._execute("modifyvm", [self._vmname, "--cpus", str(vcpus)], timeout=3)
|
||||
log.info("GNS3 VM vCPU count set to {}".format(vcpus))
|
||||
|
||||
@asyncio.coroutine
|
||||
|
@ -48,6 +48,13 @@ class VMwareGNS3VM(BaseGNS3VM):
|
||||
except VMwareError as e:
|
||||
raise GNS3VMError("Error while executing VMware command: {}".format(e))
|
||||
|
||||
@asyncio.coroutine
|
||||
def _is_running(self):
|
||||
result = yield from self._vmware_manager.execute("list", [])
|
||||
if self._vmx_path in result:
|
||||
return True
|
||||
return False
|
||||
|
||||
@asyncio.coroutine
|
||||
def _set_vcpus_ram(self, vcpus, ram):
|
||||
"""
|
||||
@ -62,7 +69,6 @@ class VMwareGNS3VM(BaseGNS3VM):
|
||||
raise GNS3VMError("You have allocated too much memory ({} MB) for the GNS3 VM! (available memory is {} MB)".format(ram, available_ram))
|
||||
|
||||
# memory must be a multiple of 4 (VMware requirement)
|
||||
|
||||
if ram % 4 != 0:
|
||||
raise GNS3VMError("Allocated memory for the GNS3 VM must be a multiple of 4".format(available_ram))
|
||||
|
||||
@ -105,21 +111,23 @@ class VMwareGNS3VM(BaseGNS3VM):
|
||||
if not os.path.exists(self._vmx_path):
|
||||
raise GNS3VMError("VMware VMX file {} doesn't exist".format(self._vmx_path))
|
||||
|
||||
# set the number of vCPUs and amount of RAM
|
||||
#yield from self._set_vcpus_ram(self.vcpus, self.ram)
|
||||
|
||||
# start the VM
|
||||
args = [self._vmx_path]
|
||||
if self._headless:
|
||||
args.extend(["nogui"])
|
||||
yield from self._execute("start", args)
|
||||
log.info("GNS3 VM has been started")
|
||||
|
||||
# check if the VMware guest tools are installed
|
||||
vmware_tools_state = yield from self._execute("checkToolsState", [self._vmx_path])
|
||||
if vmware_tools_state not in ("installed", "running"):
|
||||
raise GNS3VMError("VMware tools are not installed in {}".format(self.vmname))
|
||||
|
||||
running = yield from self._is_running()
|
||||
if not running:
|
||||
log.info("Update GNS3 VM settings")
|
||||
# set the number of vCPUs and amount of RAM
|
||||
yield from self._set_vcpus_ram(self.vcpus, self.ram)
|
||||
|
||||
# start the VM
|
||||
args = [self._vmx_path]
|
||||
if self._headless:
|
||||
args.extend(["nogui"])
|
||||
yield from self._execute("start", args)
|
||||
log.info("GNS3 VM has been started")
|
||||
# get the guest IP address (first adapter only)
|
||||
guest_ip_address = yield from self._execute("getGuestIPAddress", [self._vmx_path, "-wait"], timeout=120)
|
||||
self.ip_address = guest_ip_address
|
||||
|
@ -40,6 +40,14 @@ GNS3VM_SETTINGS_SCHEMA = {
|
||||
"engine": {
|
||||
"description": "The engine to use for the VM. Null to disable",
|
||||
"enum": ["vmware", "virtualbox", None]
|
||||
},
|
||||
"vcpus": {
|
||||
"description": "Number of VPCUS affected to the VM",
|
||||
"type": "integer"
|
||||
},
|
||||
"ram": {
|
||||
"description": "Amount of ram affected to the VM",
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"additionalProperties": False
|
||||
|
Loading…
Reference in New Issue
Block a user