nsidc / vagrant-vsphere

VMware vSphere provider for Vagrant
Other
607 stars 166 forks source link

Plugin returning incorrect ssh address for machines with bridge network adapters #192

Closed Jkovarik closed 8 years ago

Jkovarik commented 8 years ago

The VM 'ip address' being returned from the vSphere API (via rbvmomi) is incorrect in cases where Docker (or presumably other packages/user provisioning) assigns a 'virtual' bridge interface and/or other container interfaces.

For example, for a VM with the following interfaces:

$ ifconfig
br-8f298e586cb6 Link encap:Ethernet  HWaddr 02:42:3f:eb:d0:72
          inet addr:172.19.0.1  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:3fff:feeb:d072/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:733 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1101 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:3000143 (3.0 MB)  TX bytes:111909 (111.9 KB)

docker0   Link encap:Ethernet  HWaddr 02:42:0b:01:d7:3f
          inet addr:172.17.0.1  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:bff:fe01:d73f/64 Scope:Link
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:1149 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1243 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:77513 (77.5 KB)  TX bytes:21234189 (21.2 MB)

eth0      Link encap:Ethernet  HWaddr 00:50:56:85:0c:0c
          inet addr:172.18.226.128  Bcast:172.18.227.255  Mask:255.255.254.0
          inet6 addr: fe80::250:56ff:fe85:c0c/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:671010 errors:0 dropped:11704 overruns:0 frame:0
          TX packets:58592 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:861499015 (861.4 MB)  TX bytes:8214502 (8.2 MB)

Vsphere assumes the machine default API is '172.19.0.1' (a bridge adapter IP created by docker compose in this case), attempts to reprovision/ssh/etc the VM will fail as the bridge interface isn't accessible outside the VM.

Inspecting the values coming back up from the api (through rbvmomi):

[3] pry(#<VagrantPlugins::VSphere::Action::GetSshInfo>)> vm.guest.ipAddress
=> "172.19.0.1"
 [9] pry(#<VagrantPlugins::VSphere::Action::GetSshInfo>)> vm.guest.net
  => [GuestNicInfo(
     connected: true,
     deviceConfigId: -1,
     dynamicProperty: [],
     ipAddress: ["172.19.0.1", "fe80::42:3fff:feeb:d072"],
     ipConfig: NetIpConfigInfo(
       dynamicProperty: [],
       ipAddress: [NetIpConfigInfoIpAddress( dynamicProperty: [], ipAddress: "172.19.0.1", prefixLength: 16, state: "preferred" ), NetIpConfigInfoIpAddress( dynamicProperty: [], ipAddress: "fe80::42:3fff:feeb:d072", prefixLength: 64, state: "unknown" )]
     ),
     macAddress: "02:42:3f:eb:d0:72"
   ),
   GuestNicInfo(
     connected: true,
     deviceConfigId: -1,
     dynamicProperty: [],
     ipAddress: ["fe80::c4dd:4bff:fece:6a47"],
     ipConfig: NetIpConfigInfo( dynamicProperty: [], ipAddress: [NetIpConfigInfoIpAddress( dynamicProperty: [], ipAddress: "fe80::c4dd:4bff:fece:6a47", prefixLength: 64, state: "unknown" )] ),
     macAddress: "c6:dd:4b:ce:6a:47"
   ),
   GuestNicInfo(
     connected: true,
     deviceConfigId: 4000,
     dynamicProperty: [],
     ipAddress: ["172.18.226.128", "fe80::250:56ff:fe85:c0c"],
     ipConfig: NetIpConfigInfo(
       dynamicProperty: [],
       ipAddress: [NetIpConfigInfoIpAddress( dynamicProperty: [], ipAddress: "172.18.226.128", prefixLength: 23, state: "preferred" ), NetIpConfigInfoIpAddress( dynamicProperty: [], ipAddress: "fe80::250:56ff:fe85:c0c", prefixLength: 64, state: "unknown" )]
     ),
     macAddress: "00:50:56:85:0c:0c",
     network: "APP-10 172.18.226"
   ),
   GuestNicInfo(
     connected: true,
     deviceConfigId: -1,
     dynamicProperty: [],
     ipAddress: ["fe80::f03e:36ff:fec2:6676"],
     ipConfig: NetIpConfigInfo( dynamicProperty: [], ipAddress: [NetIpConfigInfoIpAddress( dynamicProperty: [], ipAddress: "fe80::f03e:36ff:fec2:6676", prefixLength: 64, state: "unknown" )] ),
     macAddress: "f2:3e:36:c2:66:76"
   ),
   GuestNicInfo(
     connected: true,
     deviceConfigId: -1,
     dynamicProperty: [],
     ipAddress: ["172.17.0.1", "fe80::42:bff:fe01:d73f"],
     ipConfig: NetIpConfigInfo(
       dynamicProperty: [],
       ipAddress: [NetIpConfigInfoIpAddress( dynamicProperty: [], ipAddress: "172.17.0.1", prefixLength: 16, state: "preferred" ), NetIpConfigInfoIpAddress( dynamicProperty: [], ipAddress: "fe80::42:bff:fe01:d73f", prefixLength: 64, state: "unknown" )]
     ),
     macAddress: "02:42:0b:01:d7:3f"
   )]

Given I believe this is a vsphere api issue, we should (optionally) handle this in the plugin.

Jkovarik commented 8 years ago

PR: https://github.com/nsidc/vagrant-vsphere/pull/193