mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 14:01:15 +02:00
8 files changed
+114
-42
No files matched your search
@@ -40,7 +40,7 @@ class GNS3VM:
|
||||
self._engines = {}
|
||||
self._settings = {
|
||||
"vmname": None,
|
||||
"auto_stop": True,
|
||||
"when_exit": "stop",
|
||||
"headless": False,
|
||||
"enable": False,
|
||||
"engine": "vmware"
|
||||
@@ -54,7 +54,7 @@ class GNS3VM:
|
||||
vmware_informations = {
|
||||
"engine_id": "vmware",
|
||||
"description": "VMware is the recommended choice for best performances.",
|
||||
"support_auto_stop": True,
|
||||
"support_when_exit": True,
|
||||
"support_headless": True
|
||||
}
|
||||
if sys.platform.startswith("darwin"):
|
||||
@@ -66,7 +66,7 @@ class GNS3VM:
|
||||
"engine_id": "virtualbox",
|
||||
"name": "VirtualBox",
|
||||
"description": "VirtualBox doesn't support nested virtualization, this means running Qemu based VM could be very slow.",
|
||||
"support_auto_stop": True,
|
||||
"support_when_exit": True,
|
||||
"support_headless": True
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ class GNS3VM:
|
||||
"engine_id": "remote",
|
||||
"name": "Remote",
|
||||
"description": "Use a remote GNS3 server as the GNS3 VM.",
|
||||
"support_auto_stop": False,
|
||||
"support_when_exit": False,
|
||||
"support_headless": False
|
||||
}
|
||||
|
||||
@@ -149,11 +149,11 @@ class GNS3VM:
|
||||
return self._settings.get("enable", False)
|
||||
|
||||
@property
|
||||
def auto_stop(self):
|
||||
def when_exit(self):
|
||||
"""
|
||||
The GNSVM should auto stop
|
||||
What should be done when exit
|
||||
"""
|
||||
return self._settings["auto_stop"]
|
||||
return self._settings["when_exit"]
|
||||
|
||||
@property
|
||||
def settings(self):
|
||||
@@ -224,10 +224,13 @@ class GNS3VM:
|
||||
force=True)
|
||||
|
||||
@asyncio.coroutine
|
||||
def auto_stop_vm(self):
|
||||
if self.enable and self.auto_stop:
|
||||
def exit_vm(self):
|
||||
if self.enable:
|
||||
try:
|
||||
yield from self._stop()
|
||||
if self._settings["when_exit"] == "stop":
|
||||
yield from self._stop()
|
||||
elif self._settings["when_exit"] == "suspend":
|
||||
yield from self._suspend()
|
||||
except GNS3VMError as e:
|
||||
log.warn(str(e))
|
||||
|
||||
@@ -250,6 +253,18 @@ class GNS3VM:
|
||||
password=self.password,
|
||||
force=True)
|
||||
|
||||
@locked_coroutine
|
||||
def _suspend(self):
|
||||
"""
|
||||
Suspend the GNS3 VM
|
||||
"""
|
||||
engine = self._current_engine()
|
||||
if "vm" in self._controller.computes:
|
||||
yield from self._controller.delete_compute("vm")
|
||||
if engine.running:
|
||||
log.info("Suspend the GNS3 VM")
|
||||
yield from engine.suspend()
|
||||
|
||||
@locked_coroutine
|
||||
def _stop(self):
|
||||
"""
|
||||
|
||||
@@ -28,7 +28,6 @@ class BaseGNS3VM:
|
||||
|
||||
self._controller = controller
|
||||
self._vmname = None
|
||||
self._auto_stop = False
|
||||
self._ip_address = None
|
||||
self._port = 3080
|
||||
self._headless = False
|
||||
@@ -245,26 +244,6 @@ class BaseGNS3VM:
|
||||
|
||||
self._ram = new_ram
|
||||
|
||||
@property
|
||||
def auto_stop(self):
|
||||
"""
|
||||
Returns whether the VM should automatically be stopped when GNS3 quit
|
||||
|
||||
:returns: boolean
|
||||
"""
|
||||
|
||||
return self._auto_start
|
||||
|
||||
@auto_stop.setter
|
||||
def auto_stop(self, new_auto_stop):
|
||||
"""
|
||||
Set whether the VM should automatically be stopped when GNS3 quit
|
||||
|
||||
:param new_auto_stop: boolean
|
||||
"""
|
||||
|
||||
self._auto_stop = new_auto_stop
|
||||
|
||||
@property
|
||||
def engine(self):
|
||||
"""
|
||||
@@ -291,6 +270,14 @@ class BaseGNS3VM:
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
@asyncio.coroutine
|
||||
def suspend(self):
|
||||
"""
|
||||
Suspend the GNS3 VM.
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
@asyncio.coroutine
|
||||
def stop(self, force=False):
|
||||
"""
|
||||
|
||||
@@ -63,6 +63,13 @@ class RemoteGNS3VM(BaseGNS3VM):
|
||||
return
|
||||
raise GNS3VMError("Can't start the GNS3 VM remote VM {} not found".format(self.vmname))
|
||||
|
||||
@asyncio.coroutine
|
||||
def suspend(self):
|
||||
"""
|
||||
Suspend do nothing for remote server
|
||||
"""
|
||||
self.running = False
|
||||
|
||||
@asyncio.coroutine
|
||||
def stop(self):
|
||||
"""
|
||||
|
||||
@@ -180,7 +180,9 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
|
||||
if self._headless:
|
||||
args.extend(["--type", "headless"])
|
||||
yield from self._execute("startvm", args)
|
||||
|
||||
elif vm_state == "paused":
|
||||
args = [self._vmname, "resume"]
|
||||
yield from self._execute("controlvm", args)
|
||||
ip_address = "127.0.0.1"
|
||||
try:
|
||||
# get a random port on localhost
|
||||
@@ -221,7 +223,7 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
|
||||
try:
|
||||
resp = None
|
||||
resp = yield from session.get('http://127.0.0.1:{}/v2/compute/network/interfaces'.format(api_port))
|
||||
except OSError:
|
||||
except (OSError, aiohttp.errors.ClientHttpProcessingError):
|
||||
pass
|
||||
|
||||
if resp:
|
||||
@@ -242,6 +244,16 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
|
||||
yield from asyncio.sleep(1)
|
||||
raise GNS3VMError("Could not get the GNS3 VM ip make sure the VM receive an IP from VirtualBox")
|
||||
|
||||
@asyncio.coroutine
|
||||
def suspend(self):
|
||||
"""
|
||||
Suspend the GNS3 VM.
|
||||
"""
|
||||
|
||||
yield from self._execute("controlvm", [self._vmname, "savestate"], timeout=3)
|
||||
log.info("GNS3 VM has been suspend")
|
||||
self.running = False
|
||||
|
||||
@asyncio.coroutine
|
||||
def stop(self):
|
||||
"""
|
||||
@@ -249,7 +261,7 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
|
||||
"""
|
||||
|
||||
yield from self._execute("controlvm", [self._vmname, "acpipowerbutton"], timeout=3)
|
||||
log.info("GNS3 VM hsd been stopped")
|
||||
log.info("GNS3 VM has been stopped")
|
||||
self.running = False
|
||||
|
||||
@asyncio.coroutine
|
||||
|
||||
@@ -126,6 +126,21 @@ class VMwareGNS3VM(BaseGNS3VM):
|
||||
log.info("GNS3 VM IP address set to {}".format(guest_ip_address))
|
||||
self.running = True
|
||||
|
||||
@asyncio.coroutine
|
||||
def suspend(self):
|
||||
"""
|
||||
Suspend the GNS3 VM.
|
||||
"""
|
||||
|
||||
if self._vmx_path is None:
|
||||
raise GNS3VMError("No VMX path configured, can't suspend the VM")
|
||||
try:
|
||||
yield from self._execute("suspend", [self._vmx_path])
|
||||
except GNS3VMError as e:
|
||||
log.warning("Error when suspending the VM: {}".format(str(e)))
|
||||
log.info("GNS3 VM has been suspended")
|
||||
self.running = False
|
||||
|
||||
@asyncio.coroutine
|
||||
def stop(self):
|
||||
"""
|
||||
|
||||
Reference in new issue
Block a user