mechboxes / mech

Easy command line virtual machines for VMWare
https://mechboxes.github.io/mech/
MIT License
311 stars 49 forks source link

Wrong IP after certain VMs boot #6

Closed ColdHeat closed 6 years ago

ColdHeat commented 7 years ago

https://github.com/vmware/open-vm-tools/issues/93

ColdHeat commented 6 years ago

This issue is undoubtedly the single most annoying issue I run into with mech. If I install docker inside of a virtual machine, vmrun will no longer find the IP address correctly and you end up having to go into Fusion to get the actual IP address

❯ mech up
Bringing machine up...
Getting IP address...
Sharing current folder...
VM started on 172.17.0.1
Kronuz commented 6 years ago

I was checking how this is done in Vagrant, it seems it also suffers from the same problem, they had/have (https://github.com/hashicorp/vagrant/issues/6580) and they added enable_vmrun_ip_lookup, which must be using a script to get the IP, somehow. I wonder how they’re doing it...

ColdHeat commented 6 years ago

This problem was getting annoying so I looked into it.

        vmrun.user = 'vagrant'
        vmrun.password = 'vagrant'
        vmrun.runScriptInGuest('/bin/sh', "hostname -I > /tmp/ip_address")
        with tempfile.NamedTemporaryFile() as fp:
            vmrun.copyFileFromGuestToHost('/tmp/ip_address', fp.name)
            fp.seek(0)
            ip_addresses = fp.read()
            if ip_addresses:
                print(ip_addresses.split()[0])

This code works although the hostname man page says we can't rely on its order for output. Perhaps a better way is to use a more advanced command or test the IPs?

ColdHeat commented 6 years ago

I don't like my current approach (changes to getGuestIPAddress), do you think this should be a change in vmrun or higher in mech/utils?

ColdHeat commented 6 years ago

I implemented an enable_ip_lookup as of https://github.com/mechboxes/mech/commit/e77d319abb0f552aa077d908b513eee5af155ebd