mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-04 14:31:13 +02:00
Fixing race condition when starting the GNS3 VM.
This commit is contained in:
1 parent
5f14f8eb46
commit
f9c7c15f95
4 files changed
+41
-31
No files matched your search
@@ -27,6 +27,7 @@ from .virtualbox_gns3_vm import VirtualBoxGNS3VM
|
||||
from .remote_gns3_vm import RemoteGNS3VM
|
||||
from .gns3_vm_error import GNS3VMError
|
||||
from ...version import __version__
|
||||
from ..compute import ComputeError
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -281,7 +282,8 @@ class GNS3VM:
|
||||
compute = yield from self._controller.add_compute(compute_id="vm",
|
||||
name="GNS3 VM is starting ({})".format(engine.vmname),
|
||||
host=None,
|
||||
force=True)
|
||||
force=True,
|
||||
connect=False)
|
||||
|
||||
try:
|
||||
yield from engine.start()
|
||||
@@ -290,6 +292,7 @@ class GNS3VM:
|
||||
log.error("Can't start the GNS3 VM: {}".format(str(e)))
|
||||
yield from compute.update(name="GNS3 VM ({})".format(engine.vmname))
|
||||
raise e
|
||||
yield from compute.connect() # we can connect now that the VM has started
|
||||
yield from compute.update(name="GNS3 VM ({})".format(engine.vmname),
|
||||
protocol=self.protocol,
|
||||
host=self.ip_address,
|
||||
@@ -297,7 +300,9 @@ class GNS3VM:
|
||||
user=self.user,
|
||||
password=self.password)
|
||||
|
||||
yield from self._check_network(compute)
|
||||
# check if the VM is in the same subnet as the local server, start 10 seconds later to give
|
||||
# some time for the compute in the VM to be ready for requests
|
||||
asyncio.get_event_loop().call_later(10, lambda: asyncio.async(self._check_network(compute)))
|
||||
|
||||
@asyncio.coroutine
|
||||
def _check_network(self, compute):
|
||||
@@ -305,28 +310,32 @@ class GNS3VM:
|
||||
Check that the VM is in the same subnet as the local server
|
||||
"""
|
||||
|
||||
vm_interfaces = yield from compute.interfaces()
|
||||
vm_interface_netmask = None
|
||||
for interface in vm_interfaces:
|
||||
if interface["ip_address"] == self.ip_address:
|
||||
vm_interface_netmask = interface["netmask"]
|
||||
break
|
||||
if vm_interface_netmask:
|
||||
vm_network = ipaddress.ip_interface("{}/{}".format(compute.host_ip, vm_interface_netmask)).network
|
||||
for compute_id in self._controller.computes:
|
||||
if compute_id == "local":
|
||||
compute = self._controller.get_compute(compute_id)
|
||||
interfaces = yield from compute.interfaces()
|
||||
netmask = None
|
||||
for interface in interfaces:
|
||||
if interface["ip_address"] == compute.host_ip:
|
||||
netmask = interface["netmask"]
|
||||
break
|
||||
if netmask:
|
||||
compute_network = ipaddress.ip_interface("{}/{}".format(compute.host_ip, netmask)).network
|
||||
if vm_network.compare_networks(compute_network) != 0:
|
||||
msg = "The GNS3 VM ({}) is not on the same network as the {} server ({}), please make sure the local server binding is in the same network as the GNS3 VM".format(vm_network, compute_id, compute_network)
|
||||
self._controller.notification.emit("log.warning", {"message": msg})
|
||||
try:
|
||||
vm_interfaces = yield from compute.interfaces()
|
||||
vm_interface_netmask = None
|
||||
for interface in vm_interfaces:
|
||||
if interface["ip_address"] == self.ip_address:
|
||||
vm_interface_netmask = interface["netmask"]
|
||||
break
|
||||
if vm_interface_netmask:
|
||||
vm_network = ipaddress.ip_interface("{}/{}".format(compute.host_ip, vm_interface_netmask)).network
|
||||
for compute_id in self._controller.computes:
|
||||
if compute_id == "local":
|
||||
compute = self._controller.get_compute(compute_id)
|
||||
interfaces = yield from compute.interfaces()
|
||||
netmask = None
|
||||
for interface in interfaces:
|
||||
if interface["ip_address"] == compute.host_ip:
|
||||
netmask = interface["netmask"]
|
||||
break
|
||||
if netmask:
|
||||
compute_network = ipaddress.ip_interface("{}/{}".format(compute.host_ip, netmask)).network
|
||||
if vm_network.compare_networks(compute_network) != 0:
|
||||
msg = "The GNS3 VM ({}) is not on the same network as the {} server ({}), please make sure the local server binding is in the same network as the GNS3 VM".format(
|
||||
vm_network, compute_id, compute_network)
|
||||
self._controller.notification.emit("log.warning", {"message": msg})
|
||||
except ComputeError as e:
|
||||
log.warning("Could not check the VM is in the same subnet as the local server: {}".format(e))
|
||||
|
||||
@locked_coroutine
|
||||
def _suspend(self):
|
||||
|
||||
@@ -171,7 +171,7 @@ class VMwareGNS3VM(BaseGNS3VM):
|
||||
trial -= 1
|
||||
# If ip not found fallback on old method
|
||||
if trial == 0:
|
||||
log.warn("No IP found for the VM via readVariable fallback to getGuestIPAddress")
|
||||
log.warning("No IP found for the VM via readVariable fallback to getGuestIPAddress")
|
||||
guest_ip_address = yield from self._execute("getGuestIPAddress", [self._vmx_path, "-wait"], timeout=120)
|
||||
break
|
||||
yield from asyncio.sleep(1)
|
||||
|
||||
Reference in new issue
Block a user