@ -27,6 +27,7 @@ from .virtualbox_gns3_vm import VirtualBoxGNS3VM
from . remote_gns3_vm import RemoteGNS3VM
from . remote_gns3_vm import RemoteGNS3VM
from . gns3_vm_error import GNS3VMError
from . gns3_vm_error import GNS3VMError
from . . . version import __version__
from . . . version import __version__
from . . compute import ComputeError
import logging
import logging
log = logging . getLogger ( __name__ )
log = logging . getLogger ( __name__ )
@ -281,7 +282,8 @@ class GNS3VM:
compute = yield from self . _controller . add_compute ( compute_id = " vm " ,
compute = yield from self . _controller . add_compute ( compute_id = " vm " ,
name = " GNS3 VM is starting ( {} ) " . format ( engine . vmname ) ,
name = " GNS3 VM is starting ( {} ) " . format ( engine . vmname ) ,
host = None ,
host = None ,
force = True )
force = True ,
connect = False )
try :
try :
yield from engine . start ( )
yield from engine . start ( )
@ -290,6 +292,7 @@ class GNS3VM:
log . error ( " Can ' t start the GNS3 VM: {} " . format ( str ( e ) ) )
log . error ( " Can ' t start the GNS3 VM: {} " . format ( str ( e ) ) )
yield from compute . update ( name = " GNS3 VM ( {} ) " . format ( engine . vmname ) )
yield from compute . update ( name = " GNS3 VM ( {} ) " . format ( engine . vmname ) )
raise e
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 ) ,
yield from compute . update ( name = " GNS3 VM ( {} ) " . format ( engine . vmname ) ,
protocol = self . protocol ,
protocol = self . protocol ,
host = self . ip_address ,
host = self . ip_address ,
@ -297,7 +300,9 @@ class GNS3VM:
user = self . user ,
user = self . user ,
password = self . password )
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
@asyncio.coroutine
def _check_network ( self , compute ) :
def _check_network ( self , compute ) :
@ -305,6 +310,7 @@ class GNS3VM:
Check that the VM is in the same subnet as the local server
Check that the VM is in the same subnet as the local server
"""
"""
try :
vm_interfaces = yield from compute . interfaces ( )
vm_interfaces = yield from compute . interfaces ( )
vm_interface_netmask = None
vm_interface_netmask = None
for interface in vm_interfaces :
for interface in vm_interfaces :
@ -325,8 +331,11 @@ class GNS3VM:
if netmask :
if netmask :
compute_network = ipaddress . ip_interface ( " {} / {} " . format ( compute . host_ip , netmask ) ) . network
compute_network = ipaddress . ip_interface ( " {} / {} " . format ( compute . host_ip , netmask ) ) . network
if vm_network . compare_networks ( compute_network ) != 0 :
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 )
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 } )
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
@locked_coroutine
def _suspend ( self ) :
def _suspend ( self ) :