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:
parent
6e29e7711c
commit
fa978b6a28
@ -62,7 +62,12 @@ class VirtualBoxHandler:
|
|||||||
request.json.get("uuid"),
|
request.json.get("uuid"),
|
||||||
request.json["vmname"],
|
request.json["vmname"],
|
||||||
request.json["linked_clone"],
|
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.set_status(201)
|
||||||
response.json(vm)
|
response.json(vm)
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ import asyncio
|
|||||||
from pkg_resources import parse_version
|
from pkg_resources import parse_version
|
||||||
from .virtualbox_error import VirtualBoxError
|
from .virtualbox_error import VirtualBoxError
|
||||||
from ..adapters.ethernet_adapter import EthernetAdapter
|
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
|
from ..base_vm import BaseVM
|
||||||
|
|
||||||
if sys.platform.startswith('win'):
|
if sys.platform.startswith('win'):
|
||||||
@ -47,7 +47,7 @@ class VirtualBoxVM(BaseVM):
|
|||||||
VirtualBox VM implementation.
|
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)
|
super().__init__(name, uuid, project, manager)
|
||||||
|
|
||||||
@ -58,7 +58,8 @@ class VirtualBoxVM(BaseVM):
|
|||||||
self._serial_pipe = None
|
self._serial_pipe = None
|
||||||
|
|
||||||
# VirtualBox settings
|
# VirtualBox settings
|
||||||
self._console = console
|
self._console = None
|
||||||
|
self._adapters = adapters
|
||||||
self._ethernet_adapters = []
|
self._ethernet_adapters = []
|
||||||
self._headless = False
|
self._headless = False
|
||||||
self._enable_remote_console = False
|
self._enable_remote_console = False
|
||||||
@ -78,10 +79,9 @@ class VirtualBoxVM(BaseVM):
|
|||||||
"console": self.console,
|
"console": self.console,
|
||||||
"project_uuid": self.project.uuid,
|
"project_uuid": self.project.uuid,
|
||||||
"vmname": self.vmname,
|
"vmname": self.vmname,
|
||||||
"linked_clone": self.linked_clone,
|
|
||||||
"headless": self.headless,
|
"headless": self.headless,
|
||||||
"enable_remote_console": self.enable_remote_console,
|
"enable_remote_console": self.enable_remote_console,
|
||||||
"adapters": self.adapters,
|
"adapters": self._adapters,
|
||||||
"adapter_type": self.adapter_type,
|
"adapter_type": self.adapter_type,
|
||||||
"adapter_start_index": self.adapter_start_index}
|
"adapter_start_index": self.adapter_start_index}
|
||||||
|
|
||||||
@ -152,8 +152,7 @@ class VirtualBoxVM(BaseVM):
|
|||||||
else:
|
else:
|
||||||
yield from self._create_linked_clone()
|
yield from self._create_linked_clone()
|
||||||
|
|
||||||
# set 2 adapters by default
|
yield from self.set_adapters(self._adapters)
|
||||||
# yield from self.set_adapters(2)
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def start(self):
|
def start(self):
|
||||||
@ -432,26 +431,6 @@ class VirtualBoxVM(BaseVM):
|
|||||||
# yield from self._modify_vm('--name "{}"'.format(vmname))
|
# yield from self._modify_vm('--name "{}"'.format(vmname))
|
||||||
self._vmname = 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
|
@asyncio.coroutine
|
||||||
def set_adapters(self, adapters):
|
def set_adapters(self, adapters):
|
||||||
"""
|
"""
|
||||||
@ -472,6 +451,7 @@ class VirtualBoxVM(BaseVM):
|
|||||||
continue
|
continue
|
||||||
self._ethernet_adapters.append(EthernetAdapter())
|
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,
|
log.info("VirtualBox VM '{name}' [{uuid}]: number of Ethernet adapters changed to {adapters}".format(name=self.name,
|
||||||
uuid=self.uuid,
|
uuid=self.uuid,
|
||||||
adapters=adapters))
|
adapters=adapters))
|
||||||
|
@ -21,6 +21,28 @@ VBOX_CREATE_SCHEMA = {
|
|||||||
"description": "Request validation to create a new VirtualBox VM instance",
|
"description": "Request validation to create a new VirtualBox VM instance",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"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": {
|
"name": {
|
||||||
"description": "VirtualBox VM instance name",
|
"description": "VirtualBox VM instance name",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@ -31,27 +53,22 @@ VBOX_CREATE_SCHEMA = {
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"minLength": 1,
|
"minLength": 1,
|
||||||
},
|
},
|
||||||
"linked_clone": {
|
"adapters": {
|
||||||
"description": "either the VM is a linked clone or not",
|
"description": "number of adapters",
|
||||||
"type": "boolean"
|
"type": "integer",
|
||||||
|
"minimum": 0,
|
||||||
|
"maximum": 36, # maximum given by the ICH9 chipset in VirtualBox
|
||||||
},
|
},
|
||||||
"vbox_id": {
|
"adapter_start_index": {
|
||||||
"description": "VirtualBox VM instance ID (for project created before GNS3 1.3)",
|
"description": "adapter index from which to start using adapters",
|
||||||
"type": "integer"
|
"type": "integer",
|
||||||
|
"minimum": 0,
|
||||||
|
"maximum": 35, # maximum given by the ICH9 chipset in VirtualBox
|
||||||
},
|
},
|
||||||
"uuid": {
|
"adapter_type": {
|
||||||
"description": "VirtualBox VM instance UUID",
|
"description": "VirtualBox adapter type",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"minLength": 36,
|
"minLength": 1,
|
||||||
"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}$"
|
|
||||||
},
|
},
|
||||||
"console": {
|
"console": {
|
||||||
"description": "console TCP port",
|
"description": "console TCP port",
|
||||||
@ -59,6 +76,14 @@ VBOX_CREATE_SCHEMA = {
|
|||||||
"maximum": 65535,
|
"maximum": 65535,
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
"enable_remote_console": {
|
||||||
|
"description": "enable the remote console",
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"headless": {
|
||||||
|
"description": "headless mode",
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
"required": ["name", "vmname", "linked_clone", "project_uuid"],
|
"required": ["name", "vmname", "linked_clone", "project_uuid"],
|
||||||
@ -198,10 +223,6 @@ VBOX_OBJECT_SCHEMA = {
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"minLength": 1,
|
"minLength": 1,
|
||||||
},
|
},
|
||||||
"linked_clone": {
|
|
||||||
"description": "either the VM is a linked clone or not",
|
|
||||||
"type": "boolean"
|
|
||||||
},
|
|
||||||
"enable_remote_console": {
|
"enable_remote_console": {
|
||||||
"description": "enable the remote console",
|
"description": "enable the remote console",
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
|
Loading…
Reference in New Issue
Block a user