1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-24 15:58:08 +00:00

Send all VirtualBox settings when creating the VM.

This commit is contained in:
Jeremy 2015-01-30 19:36:05 -07:00
parent 6e29e7711c
commit fa978b6a28
3 changed files with 56 additions and 50 deletions

View File

@ -62,7 +62,12 @@ class VirtualBoxHandler:
request.json.get("uuid"),
request.json["vmname"],
request.json["linked_clone"],
console=request.json.get("console"))
adapters=request.json.get("adapters", 0))
for name, value in request.json.items():
if hasattr(vm, name) and getattr(vm, name) != value:
setattr(vm, name, value)
response.set_status(201)
response.json(vm)

View File

@ -31,7 +31,7 @@ import asyncio
from pkg_resources import parse_version
from .virtualbox_error import VirtualBoxError
from ..adapters.ethernet_adapter import EthernetAdapter
from .telnet_server import TelnetServer # port TelnetServer to asyncio
from .telnet_server import TelnetServer # TODO: port TelnetServer to asyncio
from ..base_vm import BaseVM
if sys.platform.startswith('win'):
@ -47,7 +47,7 @@ class VirtualBoxVM(BaseVM):
VirtualBox VM implementation.
"""
def __init__(self, name, uuid, project, manager, vmname, linked_clone, console=None):
def __init__(self, name, uuid, project, manager, vmname, linked_clone, adapters=0):
super().__init__(name, uuid, project, manager)
@ -58,7 +58,8 @@ class VirtualBoxVM(BaseVM):
self._serial_pipe = None
# VirtualBox settings
self._console = console
self._console = None
self._adapters = adapters
self._ethernet_adapters = []
self._headless = False
self._enable_remote_console = False
@ -78,10 +79,9 @@ class VirtualBoxVM(BaseVM):
"console": self.console,
"project_uuid": self.project.uuid,
"vmname": self.vmname,
"linked_clone": self.linked_clone,
"headless": self.headless,
"enable_remote_console": self.enable_remote_console,
"adapters": self.adapters,
"adapters": self._adapters,
"adapter_type": self.adapter_type,
"adapter_start_index": self.adapter_start_index}
@ -152,8 +152,7 @@ class VirtualBoxVM(BaseVM):
else:
yield from self._create_linked_clone()
# set 2 adapters by default
# yield from self.set_adapters(2)
yield from self.set_adapters(self._adapters)
@asyncio.coroutine
def start(self):
@ -432,26 +431,6 @@ class VirtualBoxVM(BaseVM):
# yield from self._modify_vm('--name "{}"'.format(vmname))
self._vmname = vmname
@property
def linked_clone(self):
"""
Returns either the VM is a linked clone.
:returns: boolean
"""
return self._linked_clone
@property
def adapters(self):
"""
Returns the number of Ethernet adapters for this VirtualBox VM instance.
:returns: number of adapters
"""
return len(self._ethernet_adapters)
@asyncio.coroutine
def set_adapters(self, adapters):
"""
@ -472,6 +451,7 @@ class VirtualBoxVM(BaseVM):
continue
self._ethernet_adapters.append(EthernetAdapter())
self._adapters = len(self._ethernet_adapters)
log.info("VirtualBox VM '{name}' [{uuid}]: number of Ethernet adapters changed to {adapters}".format(name=self.name,
uuid=self.uuid,
adapters=adapters))

View File

@ -21,6 +21,28 @@ VBOX_CREATE_SCHEMA = {
"description": "Request validation to create a new VirtualBox VM instance",
"type": "object",
"properties": {
"uuid": {
"description": "VirtualBox VM instance UUID",
"type": "string",
"minLength": 36,
"maxLength": 36,
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
},
"vbox_id": {
"description": "VirtualBox VM instance ID (for project created before GNS3 1.3)",
"type": "integer"
},
"project_uuid": {
"description": "Project UUID",
"type": "string",
"minLength": 36,
"maxLength": 36,
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
},
"linked_clone": {
"description": "either the VM is a linked clone or not",
"type": "boolean"
},
"name": {
"description": "VirtualBox VM instance name",
"type": "string",
@ -31,27 +53,22 @@ VBOX_CREATE_SCHEMA = {
"type": "string",
"minLength": 1,
},
"linked_clone": {
"description": "either the VM is a linked clone or not",
"type": "boolean"
"adapters": {
"description": "number of adapters",
"type": "integer",
"minimum": 0,
"maximum": 36, # maximum given by the ICH9 chipset in VirtualBox
},
"vbox_id": {
"description": "VirtualBox VM instance ID (for project created before GNS3 1.3)",
"type": "integer"
"adapter_start_index": {
"description": "adapter index from which to start using adapters",
"type": "integer",
"minimum": 0,
"maximum": 35, # maximum given by the ICH9 chipset in VirtualBox
},
"uuid": {
"description": "VirtualBox VM instance UUID",
"adapter_type": {
"description": "VirtualBox adapter type",
"type": "string",
"minLength": 36,
"maxLength": 36,
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
},
"project_uuid": {
"description": "Project UUID",
"type": "string",
"minLength": 36,
"maxLength": 36,
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
"minLength": 1,
},
"console": {
"description": "console TCP port",
@ -59,6 +76,14 @@ VBOX_CREATE_SCHEMA = {
"maximum": 65535,
"type": "integer"
},
"enable_remote_console": {
"description": "enable the remote console",
"type": "boolean"
},
"headless": {
"description": "headless mode",
"type": "boolean"
},
},
"additionalProperties": False,
"required": ["name", "vmname", "linked_clone", "project_uuid"],
@ -198,10 +223,6 @@ VBOX_OBJECT_SCHEMA = {
"type": "string",
"minLength": 1,
},
"linked_clone": {
"description": "either the VM is a linked clone or not",
"type": "boolean"
},
"enable_remote_console": {
"description": "enable the remote console",
"type": "boolean"