Try a different method in order to retrieve IP from VMware

Ref https://github.com/GNS3/gns3-gui/issues/1589
pull/774/head
Julien Duponchelle 8 years ago
parent 1f44e08cdd
commit 9e861a7340
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8

@ -128,8 +128,21 @@ class VMwareGNS3VM(BaseGNS3VM):
args.extend(["nogui"])
yield from self._execute("start", args)
log.info("GNS3 VM has been started")
# get the guest IP address (first adapter only)
guest_ip_address = yield from self._execute("getGuestIPAddress", [self._vmx_path, "-wait"], timeout=120)
trial = 120
guest_ip_address = ""
while True:
guest_ip_address = yield from self._execute("readVariable", [self._vmx_path, "guestVar", "gns3.eth0"], timeout=120)
guest_ip_address = guest_ip_address.strip()
if len(guest_ip_address) != 0:
break
trial -= 1
# If ip not found fallback on old method
if trial == 0:
guest_ip_address = yield from self._execute("getGuestIPAddress", [self._vmx_path, "-wait"], timeout=120)
break
yield from asyncio.sleep(1)
self.ip_address = guest_ip_address
log.info("GNS3 VM IP address set to {}".format(guest_ip_address))
self.running = True

@ -26,8 +26,10 @@ import datetime
import sys
import locale
import argparse
import shutil
import psutil
import asyncio
import subprocess
from gns3server.web.web_server import WebServer
@ -199,6 +201,29 @@ def kill_ghosts():
pass
def set_vmware_gns3vm_ip():
"""
For the GNS3 VM on VMware we need to get the ip of eth0.
vmrun getGuestIPAddress is not reliable because it's return a
random ip from one of the available interfaces.
We need to set a VMware variable with the value and this
will allow the VM host machine to retrieve it
"""
vmtoolsd = shutil.which("vmtoolsd")
if not vmtoolsd:
return
ip = None
try:
for a in psutil.net_if_addrs()["eth0"]:
if ":" not in a.address:
ip = a.address
except (KeyError, IndexError):
return
if ip:
subprocess.call(["vmtoolsd", "--cmd", "info-set guestinfo.gns3.eth0 {}".format(ip)])
def run():
args = parse_arguments(sys.argv[1:])
@ -222,6 +247,8 @@ def run():
for config_file in Config.instance().get_config_files():
user_log.info("Config file {} loaded".format(config_file))
set_vmware_gns3vm_ip()
set_config(args)
server_config = Config.instance().get_section_config("Server")

Loading…
Cancel
Save