1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-18 06:18:08 +00:00

Improve process to get guest IP address from GNS3 VM running in VMware workstation/player. Ref https://github.com/GNS3/gns3-gui/issues/2866

This commit is contained in:
grossmj 2019-10-08 17:58:27 +08:00
parent 09d05accc1
commit 6ae7ef8a2e
2 changed files with 16 additions and 11 deletions

View File

@ -279,7 +279,7 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
pass
remaining_try -= 1
await asyncio.sleep(1)
raise GNS3VMError("Could not get the GNS3 VM ip make sure the VM receive an IP from VirtualBox")
raise GNS3VMError("Could not find guest IP address for {}".format(self.vmname))
async def suspend(self):
"""

View File

@ -164,17 +164,22 @@ class VMwareGNS3VM(BaseGNS3VM):
guest_ip_address = ""
log.info("Waiting for GNS3 VM IP")
while True:
guest_ip_address = await self._execute("readVariable", [self._vmx_path, "guestVar", "gns3.eth0"], timeout=120, log_level=logging.DEBUG)
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:
log.warning("No IP found for the VM via readVariable fallback to getGuestIPAddress")
guest_ip_address = await self._execute("getGuestIPAddress", [self._vmx_path, "-wait"], timeout=120)
break
try:
guest_ip_address = await self._execute("readVariable", [self._vmx_path, "guestVar", "gns3.eth0"], timeout=120, log_level=logging.DEBUG)
guest_ip_address = guest_ip_address.strip()
if len(guest_ip_address) != 0:
break
trial -= 1
# If IP address not found then fallback an old method
if trial == 0:
log.warning("No IP found for the VM via readVariable fallback to getGuestIPAddress")
guest_ip_address = await self._execute("getGuestIPAddress", [self._vmx_path, "-wait"], timeout=120)
break
except GNS3VMError as e:
log.debug("{}".format(e))
await asyncio.sleep(1)
if not guest_ip_address:
raise GNS3VMError("Could not find guest IP address for {}".format(self.vmname))
self.ip_address = guest_ip_address
log.info("GNS3 VM IP address set to {}".format(guest_ip_address))
self.running = True