Completely forgot to support the unix paths in each of the drivers for the VMware builder. Fixed.

This commit is contained in:
Ali Rizvi-Santiago 2016-04-05 20:45:58 -05:00
parent 4225b3568e
commit 9b95ce0bc6
8 changed files with 136 additions and 64 deletions

View File

@ -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 }
// parse dhcpd configuration
pathDhcpConfig := d.DhcpConfPath()
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 }
// parse dhcpd configuration
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 }
// 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 }

View File

@ -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

View File

@ -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
}

View File

@ -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())
}

View File

@ -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 playerDhcpLeasesPath(device string) string {
return "/etc/vmware/" + device + "/dhcpd/dhcpd.leases"
}
func playerToolsIsoPath(flavor string) string {
return "/usr/lib/vmware/isoimages/" + flavor + ".iso"
}
func playerVmnetnatConfPath() string {
return ""
// 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 {
base, err := playerVMwareRoot()
if err != nil {
log.Printf("Error finding VMware root: %s", err)
return ""
}
return filepath.Join(base, device, "dhcpd/dhcpd.leases")
}
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(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 {

View File

@ -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
}

View File

@ -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.

View File

@ -39,26 +39,51 @@ 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 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(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() string {
base, err := workstationVMwareRoot()
if err != nil {
log.Printf("Error finding VMware root: %s", err)
return ""
}
return filepath.Join(base, "netmap.conf")
}
func workstationToolsIsoPath(flavor string) string {
return "/usr/lib/vmware/isoimages/" + flavor + ".iso"
}
func workstationVmnetnatConfPath() string {
return ""
}
func workstationNetmapConfPath(device string) string {
return "" // FIXME
}
func workstationDhcpConfPath(device string) string {
return "/etc/vmware/" + device + "/dhcpd/dhcpd.conf"
}
func workstationVerifyVersion(version string) error {
if runtime.GOOS != "linux" {
return fmt.Errorf("The VMware WS version %s driver is only supported on Linux, and Windows, at the moment. Your OS: %s", version, runtime.GOOS)