diff --git a/builder/vmware/common/driver.go b/builder/vmware/common/driver.go index 1098e591f..fa2cc0c03 100644 --- a/builder/vmware/common/driver.go +++ b/builder/vmware/common/driver.go @@ -235,8 +235,8 @@ type VmwareDriver struct { /// files so that the address detection (ip and ethernet) machinery /// works. DhcpLeasesPath func(string) string - VmnetnatConfPath func() string - DhcpConfPath func() string + DhcpConfPath func(string) string + VmnetnatConfPath func(string) string NetmapConfPath func() string } @@ -359,19 +359,20 @@ func (d *VmwareDriver) HostAddress(state multistep.StateBag) (string,error) { netmap,err := readNetmapConfig(pathNetmap) if err != nil { return "",err } + // convert network to name + network := state.Get("vmnetwork").(string) + device,err := netmap.NameIntoDevice(network) + if err != nil { return "", err } + // parse dhcpd configuration - pathDhcpConfig := d.DhcpConfPath() + pathDhcpConfig := d.DhcpConfPath(device) if _, err := os.Stat(pathDhcpConfig); err != nil { return "", fmt.Errorf("Could not find vmnetdhcp conf file: %s", pathDhcpConfig) } + config,err := readDhcpConfig(pathDhcpConfig) if err != nil { return "",err } - // convert network to name - network := state.Get("vmnetwork").(string) - device,err := netmap.NameIntoDevice(network) - if err != nil { return "", err } - // find the entry configured in the dhcpd interfaceConfig,err := config.HostByName(device) if err != nil { return "", err } @@ -404,19 +405,19 @@ func (d *VmwareDriver) HostIP(state multistep.StateBag) (string,error) { netmap,err := readNetmapConfig(pathNetmap) if err != nil { return "",err } + // convert network to name + network := state.Get("vmnetwork").(string) + device,err := netmap.NameIntoDevice(network) + if err != nil { return "", err } + // parse dhcpd configuration - pathDhcpConfig := d.DhcpConfPath() + pathDhcpConfig := d.DhcpConfPath(device) if _, err := os.Stat(pathDhcpConfig); err != nil { return "", fmt.Errorf("Could not find vmnetdhcp conf file: %s", pathDhcpConfig) } config,err := readDhcpConfig(pathDhcpConfig) if err != nil { return "",err } - // convert network to name - network := state.Get("vmnetwork").(string) - device,err := netmap.NameIntoDevice(network) - if err != nil { return "", err } - // find the entry configured in the dhcpd interfaceConfig,err := config.HostByName(device) if err != nil { return "", err } diff --git a/builder/vmware/common/driver_mock.go b/builder/vmware/common/driver_mock.go index 15e006403..da28cd474 100644 --- a/builder/vmware/common/driver_mock.go +++ b/builder/vmware/common/driver_mock.go @@ -78,12 +78,15 @@ type DriverMock struct { DhcpLeasesPathDevice string DhcpLeasesPathResult string - NetmapPathCalled bool - NetmapPathResult string - DhcpConfPathCalled bool DhcpConfPathResult string + VmnetnatConfPathCalled bool + VmnetnatConfPathResult string + + NetmapConfPathCalled bool + NetmapConfPathResult string + VerifyCalled bool VerifyErr error } @@ -184,16 +187,21 @@ func (d *DriverMock) DhcpLeasesPath(device string) string { return d.DhcpLeasesPathResult } -func (d *DriverMock) NetmapPath(device string) string { - d.NetmapPathCalled = true - return d.NetmapPathResult -} - func (d *DriverMock) DhcpConfPath(device string) string { d.DhcpConfPathCalled = true return d.DhcpConfPathResult } +func (d *DriverMock) VmnetnatConfPath(device string) string { + d.VmnetnatConfPathCalled = true + return d.VmnetnatConfPathResult +} + +func (d *DriverMock) NetmapConfPath() string { + d.NetmapConfPathCalled = true + return d.NetmapConfPathResult +} + func (d *DriverMock) Verify() error { d.VerifyCalled = true return d.VerifyErr diff --git a/builder/vmware/common/driver_player5.go b/builder/vmware/common/driver_player5.go index 9dce9540c..240b44a11 100644 --- a/builder/vmware/common/driver_player5.go +++ b/builder/vmware/common/driver_player5.go @@ -187,16 +187,18 @@ func (d *Player5Driver) Verify() error { d.VmwareDriver.DhcpLeasesPath = func(device string) string { return playerDhcpLeasesPath(device) } - d.VmwareDriver.VmnetnatConfPath = func() string { - return playerVmnetnatConfPath() + + d.VmwareDriver.DhcpConfPath = func(device string) string { + return playerVmDhcpConfPath(device) } - d.VmwareDriver.DhcpConfPath = func() string { - return playerVmDhcpConfPath() + + d.VmwareDriver.VmnetnatConfPath = func(device string) string { + return playerVmnetnatConfPath(device) } + d.VmwareDriver.NetmapConfPath = func() string { return playerNetmapConfPath() } - return nil } diff --git a/builder/vmware/common/driver_player5_windows.go b/builder/vmware/common/driver_player5_windows.go index 6ca065792..790a4c46c 100644 --- a/builder/vmware/common/driver_player5_windows.go +++ b/builder/vmware/common/driver_player5_windows.go @@ -57,15 +57,11 @@ func playerDhcpLeasesPath(device string) string { } else if _, err := os.Stat(path); err == nil { return path } - return findFile("vmnetdhcp.leases", playerDataFilePaths()) } -func playerVmnetnatConfPath() string { - return findFile("vmnetnat.conf", playerDataFilePaths()) -} - -func playerVmDhcpConfPath() string { +func playerVmDhcpConfPath(device string) string { + // the device isn't actually used on windows hosts path, err := playerDhcpConfigPathRegistry() if err != nil { log.Printf("Error finding configuration in registry: %s", err) @@ -75,6 +71,11 @@ func playerVmDhcpConfPath() string { return findFile("vmnetdhcp.conf", playerDataFilePaths()) } +func playerVmnetnatConfPath(device string) string { + // the device isn't actually used on windows hosts + return findFile("vmnetnat.conf", playerDataFilePaths()) +} + func playerNetmapConfPath() string { return findFile("netmap.conf", playerDataFilePaths()) } diff --git a/builder/vmware/common/driver_player_unix.go b/builder/vmware/common/driver_player_unix.go index 0c2cc8635..01b877d92 100644 --- a/builder/vmware/common/driver_player_unix.go +++ b/builder/vmware/common/driver_player_unix.go @@ -10,6 +10,7 @@ import ( "os/exec" "regexp" "runtime" + "path/filepath" ) func playerFindVdiskManager() (string, error) { @@ -28,16 +29,49 @@ func playerFindVmrun() (string, error) { return exec.LookPath("vmrun") } +func playerToolsIsoPath(flavor string) string { + return "/usr/lib/vmware/isoimages/" + flavor + ".iso" +} + +// return the base path to vmware's config on the host +func playerVMwareRoot() (s string, err error) { + return "/etc/vmware", nil +} + func playerDhcpLeasesPath(device string) string { - return "/etc/vmware/" + device + "/dhcpd/dhcpd.leases" + base, err := playerVMwareRoot() + if err != nil { + log.Printf("Error finding VMware root: %s", err) + return "" + } + return filepath.Join(base, device, "dhcpd/dhcpd.leases") } -func playerToolsIsoPath(flavor string) string { - return "/usr/lib/vmware/isoimages/" + flavor + ".iso" +func playerVmDhcpConfPath(device string) string { + base, err := playerVMwareRoot() + if err != nil { + log.Printf("Error finding VMware root: %s", err) + return "" + } + return filepath.Join(base, device, "dhcp/dhcp.conf") } -func playerVmnetnatConfPath() string { - return "" +func playerVmnetnatConfPath(device string) string { + base, err := playerVMwareRoot() + if err != nil { + log.Printf("Error finding VMware root: %s", err) + return "" + } + return filepath.Join(base, device, "nat/nat.conf") +} + +func playerNetmapConfPath() string { + base, err := playerVMwareRoot() + if err != nil { + log.Printf("Error finding VMware root: %s", err) + return "" + } + return filepath.Join(base, "netmap.conf") } func playerVerifyVersion(version string) error { diff --git a/builder/vmware/common/driver_workstation9.go b/builder/vmware/common/driver_workstation9.go index 0c463a249..8a6eb5556 100644 --- a/builder/vmware/common/driver_workstation9.go +++ b/builder/vmware/common/driver_workstation9.go @@ -149,18 +149,17 @@ func (d *Workstation9Driver) Verify() error { return workstationDhcpLeasesPath(device) } - d.VmwareDriver.VmnetnatConfPath = func() string { - return workstationVmnetnatConfPath() + d.VmwareDriver.DhcpConfPath = func(device string) string { + return workstationDhcpConfPath(device) } - d.VmwareDriver.DhcpConfPath = func() string { - return workstationDhcpConfPath() + d.VmwareDriver.VmnetnatConfPath = func(device string) string { + return workstationVmnetnatConfPath(device) } d.VmwareDriver.NetmapConfPath = func() string { return workstationNetmapConfPath() } - return nil } diff --git a/builder/vmware/common/driver_workstation9_windows.go b/builder/vmware/common/driver_workstation9_windows.go index e69d5069f..b8d6d2b61 100644 --- a/builder/vmware/common/driver_workstation9_windows.go +++ b/builder/vmware/common/driver_workstation9_windows.go @@ -59,7 +59,13 @@ func workstationDhcpLeasesPath(device string) string { return findFile("vmnetdhcp.leases", workstationDataFilePaths()) } -func workstationVmnetnatConfPath() string { +func workstationDhcpConfPath(device string) string { + // device isn't used on a windows host + return findFile("vmnetdhcp.conf", workstationDataFilePaths()) +} + +func workstationVmnetnatConfPath(device string) string { + // device isn't used on a windows host return findFile("vmnetnat.conf", workstationDataFilePaths()) } @@ -67,10 +73,6 @@ func workstationNetmapConfPath() string { return findFile("netmap.conf", workstationDataFilePaths()) } -func workstationDhcpConfPath() string { - return findFile("vmnetdhcp.conf", workstationDataFilePaths()) -} - // See http://blog.natefinch.com/2012/11/go-win-stuff.html // // This is used by workstationVMwareRoot in order to read some registry data. diff --git a/builder/vmware/common/driver_workstation_unix.go b/builder/vmware/common/driver_workstation_unix.go index 2ff94fd37..45e94d21e 100644 --- a/builder/vmware/common/driver_workstation_unix.go +++ b/builder/vmware/common/driver_workstation_unix.go @@ -39,24 +39,49 @@ func workstationFindVmrun() (string, error) { return exec.LookPath("vmrun") } +// return the base path to vmware's config on the host +func workstationVMwareRoot() (s string, err error) { + return "/etc/vmware", nil +} + func workstationDhcpLeasesPath(device string) string { - return "/etc/vmware/" + device + "/dhcpd/dhcpd.leases" + base, err := workstationVMwareRoot() + if err != nil { + log.Printf("Error finding VMware root: %s", err) + return "" + } + return filepath.Join(base, device, "dhcpd/dhcpd.leases") } -func workstationToolsIsoPath(flavor string) string { - return "/usr/lib/vmware/isoimages/" + flavor + ".iso" +func workstationDhcpConfPath(device string) string { + base, err := workstationVMwareRoot() + if err != nil { + log.Printf("Error finding VMware root: %s", err) + return "" + } + return filepath.Join(base, device, "dhcp/dhcpd.conf") } -func workstationVmnetnatConfPath() string { - return "" +func workstationVmnetnatConfPath(device string) string { + base, err := workstationVMwareRoot() + if err != nil { + log.Printf("Error finding VMware root: %s", err) + return "" + } + return filepath.Join(base, device, "nat/nat.conf") } -func workstationNetmapConfPath(device string) string { - return "" // FIXME +func workstationNetmapConfPath() string { + base, err := workstationVMwareRoot() + if err != nil { + log.Printf("Error finding VMware root: %s", err) + return "" + } + return filepath.Join(base, "netmap.conf") } -func workstationDhcpConfPath(device string) string { - return "/etc/vmware/" + device + "/dhcpd/dhcpd.conf" +func workstationToolsIsoPath(flavor string) string { + return "/usr/lib/vmware/isoimages/" + flavor + ".iso" } func workstationVerifyVersion(version string) error {