mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Support RAM setting for VirtualBox VMs.
This commit is contained in:
1 parent
a81d2274cd
commit
4ccca5dc99
4 files changed
+70
-1
No files matched your search
@@ -124,7 +124,17 @@ class VirtualBox(BaseManager):
|
||||
continue # ignore inaccessible VMs
|
||||
extra_data = yield from self.execute("getextradata", [vmname, "GNS3/Clone"])
|
||||
if not extra_data[0].strip() == "Value: yes":
|
||||
vms.append(vmname)
|
||||
# get the amount of RAM
|
||||
info_results = yield from self.execute("showvminfo", [vmname, "--machinereadable"])
|
||||
for info in info_results:
|
||||
try:
|
||||
name, value = info.split('=', 1)
|
||||
if name.strip() == "memory":
|
||||
ram = int(value.strip())
|
||||
break
|
||||
except ValueError:
|
||||
continue
|
||||
vms.append({"vmname": vmname, "ram": ram})
|
||||
return vms
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -67,6 +67,7 @@ class VirtualBoxVM(BaseVM):
|
||||
self._enable_remote_console = False
|
||||
self._vmname = vmname
|
||||
self._use_any_adapter = False
|
||||
self._ram = 0
|
||||
self._adapter_type = "Intel PRO/1000 MT Desktop (82540EM)"
|
||||
|
||||
def __json__(self):
|
||||
@@ -80,6 +81,7 @@ class VirtualBoxVM(BaseVM):
|
||||
"enable_remote_console": self.enable_remote_console,
|
||||
"adapters": self._adapters,
|
||||
"adapter_type": self.adapter_type,
|
||||
"ram": self.ram,
|
||||
"use_any_adapter": self.use_any_adapter}
|
||||
|
||||
@asyncio.coroutine
|
||||
@@ -152,6 +154,9 @@ class VirtualBoxVM(BaseVM):
|
||||
if self._adapters:
|
||||
yield from self.set_adapters(self._adapters)
|
||||
|
||||
vm_info = yield from self._get_vm_info()
|
||||
self._ram = int(vm_info["memory"])
|
||||
|
||||
@asyncio.coroutine
|
||||
def start(self):
|
||||
"""
|
||||
@@ -407,6 +412,32 @@ class VirtualBoxVM(BaseVM):
|
||||
self._stop_remote_console()
|
||||
self._enable_remote_console = enable_remote_console
|
||||
|
||||
@property
|
||||
def ram(self):
|
||||
"""
|
||||
Returns the amount of RAM allocated to this VirtualBox VM.
|
||||
|
||||
:returns: amount RAM in MB (integer)
|
||||
"""
|
||||
|
||||
return self._ram
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_ram(self, ram):
|
||||
"""
|
||||
Set the amount of RAM allocated to this VirtualBox VM.
|
||||
|
||||
:param ram: amount RAM in MB (integer)
|
||||
"""
|
||||
|
||||
if ram == 0:
|
||||
return
|
||||
|
||||
yield from self._modify_vm('--memory {}'.format(ram))
|
||||
|
||||
log.info("VirtualBox VM '{name}' [{id}] has set amount of RAM to {ram}".format(name=self.name, id=self.id, ram=ram))
|
||||
self._ram = ram
|
||||
|
||||
@property
|
||||
def vmname(self):
|
||||
"""
|
||||
|
||||
Reference in new issue
Block a user