mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-13 20:08:55 +00:00
Support RAM setting for VirtualBox VMs.
This commit is contained in:
parent
a81d2274cd
commit
4ccca5dc99
@ -73,6 +73,11 @@ class VirtualBoxHandler:
|
||||
if "enable_remote_console" in request.json:
|
||||
yield from vm.set_enable_remote_console(request.json.pop("enable_remote_console"))
|
||||
|
||||
if "ram" in request.json:
|
||||
ram = request.json.pop("ram")
|
||||
if ram != vm.ram:
|
||||
yield from vm.set_ram(ram)
|
||||
|
||||
for name, value in request.json.items():
|
||||
if hasattr(vm, name) and getattr(vm, name) != value:
|
||||
setattr(vm, name, value)
|
||||
@ -134,6 +139,11 @@ class VirtualBoxHandler:
|
||||
if adapters != vm.adapters:
|
||||
yield from vm.set_adapters(adapters)
|
||||
|
||||
if "ram" in request.json:
|
||||
ram = request.json.pop("ram")
|
||||
if ram != vm.ram:
|
||||
yield from vm.set_ram(ram)
|
||||
|
||||
for name, value in request.json.items():
|
||||
if hasattr(vm, name) and getattr(vm, name) != value:
|
||||
setattr(vm, name, value)
|
||||
|
@ -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):
|
||||
"""
|
||||
|
@ -70,6 +70,12 @@ VBOX_CREATE_SCHEMA = {
|
||||
"description": "enable the remote console",
|
||||
"type": "boolean"
|
||||
},
|
||||
"ram": {
|
||||
"description": "Amount of RAM",
|
||||
"minimum": 0,
|
||||
"maximum": 65535,
|
||||
"type": "integer"
|
||||
},
|
||||
"headless": {
|
||||
"description": "headless mode",
|
||||
"type": "boolean"
|
||||
@ -119,6 +125,12 @@ VBOX_UPDATE_SCHEMA = {
|
||||
"description": "enable the remote console",
|
||||
"type": "boolean"
|
||||
},
|
||||
"ram": {
|
||||
"description": "Amount of RAM",
|
||||
"minimum": 0,
|
||||
"maximum": 65535,
|
||||
"type": "integer"
|
||||
},
|
||||
"headless": {
|
||||
"description": "headless mode",
|
||||
"type": "boolean"
|
||||
@ -240,6 +252,12 @@ VBOX_OBJECT_SCHEMA = {
|
||||
"maximum": 65535,
|
||||
"type": "integer"
|
||||
},
|
||||
"ram": {
|
||||
"description": "Amount of RAM",
|
||||
"minimum": 0,
|
||||
"maximum": 65535,
|
||||
"type": "integer"
|
||||
},
|
||||
},
|
||||
"additionalProperties": False,
|
||||
"required": ["name", "vm_id", "project_id"]
|
||||
|
Loading…
Reference in New Issue
Block a user