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 /// files so that the address detection (ip and ethernet) machinery
/// works. /// works.
DhcpLeasesPath func(string) string DhcpLeasesPath func(string) string
VmnetnatConfPath func() string DhcpConfPath func(string) string
DhcpConfPath func() string VmnetnatConfPath func(string) string
NetmapConfPath func() string NetmapConfPath func() string
} }
@ -359,19 +359,20 @@ func (d *VmwareDriver) HostAddress(state multistep.StateBag) (string,error) {
netmap,err := readNetmapConfig(pathNetmap) netmap,err := readNetmapConfig(pathNetmap)
if err != nil { return "",err } 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 // convert network to name
network := state.Get("vmnetwork").(string) network := state.Get("vmnetwork").(string)
device,err := netmap.NameIntoDevice(network) device,err := netmap.NameIntoDevice(network)
if err != nil { return "", err } 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 // find the entry configured in the dhcpd
interfaceConfig,err := config.HostByName(device) interfaceConfig,err := config.HostByName(device)
if err != nil { return "", err } if err != nil { return "", err }
@ -404,19 +405,19 @@ func (d *VmwareDriver) HostIP(state multistep.StateBag) (string,error) {
netmap,err := readNetmapConfig(pathNetmap) netmap,err := readNetmapConfig(pathNetmap)
if err != nil { return "",err } 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 // parse dhcpd configuration
pathDhcpConfig := d.DhcpConfPath() pathDhcpConfig := d.DhcpConfPath(device)
if _, err := os.Stat(pathDhcpConfig); err != nil { if _, err := os.Stat(pathDhcpConfig); err != nil {
return "", fmt.Errorf("Could not find vmnetdhcp conf file: %s", pathDhcpConfig) return "", fmt.Errorf("Could not find vmnetdhcp conf file: %s", pathDhcpConfig)
} }
config,err := readDhcpConfig(pathDhcpConfig) config,err := readDhcpConfig(pathDhcpConfig)
if err != nil { return "",err } 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 // find the entry configured in the dhcpd
interfaceConfig,err := config.HostByName(device) interfaceConfig,err := config.HostByName(device)
if err != nil { return "", err } if err != nil { return "", err }

View File

@ -78,12 +78,15 @@ type DriverMock struct {
DhcpLeasesPathDevice string DhcpLeasesPathDevice string
DhcpLeasesPathResult string DhcpLeasesPathResult string
NetmapPathCalled bool
NetmapPathResult string
DhcpConfPathCalled bool DhcpConfPathCalled bool
DhcpConfPathResult string DhcpConfPathResult string
VmnetnatConfPathCalled bool
VmnetnatConfPathResult string
NetmapConfPathCalled bool
NetmapConfPathResult string
VerifyCalled bool VerifyCalled bool
VerifyErr error VerifyErr error
} }
@ -184,16 +187,21 @@ func (d *DriverMock) DhcpLeasesPath(device string) string {
return d.DhcpLeasesPathResult return d.DhcpLeasesPathResult
} }
func (d *DriverMock) NetmapPath(device string) string {
d.NetmapPathCalled = true
return d.NetmapPathResult
}
func (d *DriverMock) DhcpConfPath(device string) string { func (d *DriverMock) DhcpConfPath(device string) string {
d.DhcpConfPathCalled = true d.DhcpConfPathCalled = true
return d.DhcpConfPathResult 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 { func (d *DriverMock) Verify() error {
d.VerifyCalled = true d.VerifyCalled = true
return d.VerifyErr return d.VerifyErr

View File

@ -187,16 +187,18 @@ func (d *Player5Driver) Verify() error {
d.VmwareDriver.DhcpLeasesPath = func(device string) string { d.VmwareDriver.DhcpLeasesPath = func(device string) string {
return playerDhcpLeasesPath(device) 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 { d.VmwareDriver.NetmapConfPath = func() string {
return playerNetmapConfPath() return playerNetmapConfPath()
} }
return nil return nil
} }

View File

@ -57,15 +57,11 @@ func playerDhcpLeasesPath(device string) string {
} else if _, err := os.Stat(path); err == nil { } else if _, err := os.Stat(path); err == nil {
return path return path
} }
return findFile("vmnetdhcp.leases", playerDataFilePaths()) return findFile("vmnetdhcp.leases", playerDataFilePaths())
} }
func playerVmnetnatConfPath() string { func playerVmDhcpConfPath(device string) string {
return findFile("vmnetnat.conf", playerDataFilePaths()) // the device isn't actually used on windows hosts
}
func playerVmDhcpConfPath() string {
path, err := playerDhcpConfigPathRegistry() path, err := playerDhcpConfigPathRegistry()
if err != nil { if err != nil {
log.Printf("Error finding configuration in registry: %s", err) log.Printf("Error finding configuration in registry: %s", err)
@ -75,6 +71,11 @@ func playerVmDhcpConfPath() string {
return findFile("vmnetdhcp.conf", playerDataFilePaths()) 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 { func playerNetmapConfPath() string {
return findFile("netmap.conf", playerDataFilePaths()) return findFile("netmap.conf", playerDataFilePaths())
} }

View File

@ -10,6 +10,7 @@ import (
"os/exec" "os/exec"
"regexp" "regexp"
"runtime" "runtime"
"path/filepath"
) )
func playerFindVdiskManager() (string, error) { func playerFindVdiskManager() (string, error) {
@ -28,16 +29,49 @@ func playerFindVmrun() (string, error) {
return exec.LookPath("vmrun") return exec.LookPath("vmrun")
} }
func playerDhcpLeasesPath(device string) string {
return "/etc/vmware/" + device + "/dhcpd/dhcpd.leases"
}
func playerToolsIsoPath(flavor string) string { func playerToolsIsoPath(flavor string) string {
return "/usr/lib/vmware/isoimages/" + flavor + ".iso" return "/usr/lib/vmware/isoimages/" + flavor + ".iso"
} }
func playerVmnetnatConfPath() string { // return the base path to vmware's config on the host
return "" 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 { func playerVerifyVersion(version string) error {

View File

@ -149,18 +149,17 @@ func (d *Workstation9Driver) Verify() error {
return workstationDhcpLeasesPath(device) return workstationDhcpLeasesPath(device)
} }
d.VmwareDriver.VmnetnatConfPath = func() string { d.VmwareDriver.DhcpConfPath = func(device string) string {
return workstationVmnetnatConfPath() return workstationDhcpConfPath(device)
} }
d.VmwareDriver.DhcpConfPath = func() string { d.VmwareDriver.VmnetnatConfPath = func(device string) string {
return workstationDhcpConfPath() return workstationVmnetnatConfPath(device)
} }
d.VmwareDriver.NetmapConfPath = func() string { d.VmwareDriver.NetmapConfPath = func() string {
return workstationNetmapConfPath() return workstationNetmapConfPath()
} }
return nil return nil
} }

View File

@ -59,7 +59,13 @@ func workstationDhcpLeasesPath(device string) string {
return findFile("vmnetdhcp.leases", workstationDataFilePaths()) 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()) return findFile("vmnetnat.conf", workstationDataFilePaths())
} }
@ -67,10 +73,6 @@ func workstationNetmapConfPath() string {
return findFile("netmap.conf", workstationDataFilePaths()) return findFile("netmap.conf", workstationDataFilePaths())
} }
func workstationDhcpConfPath() string {
return findFile("vmnetdhcp.conf", workstationDataFilePaths())
}
// See http://blog.natefinch.com/2012/11/go-win-stuff.html // See http://blog.natefinch.com/2012/11/go-win-stuff.html
// //
// This is used by workstationVMwareRoot in order to read some registry data. // 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 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 { 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 { func workstationToolsIsoPath(flavor string) string {
return "/usr/lib/vmware/isoimages/" + flavor + ".iso" 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 { func workstationVerifyVersion(version string) error {
if runtime.GOOS != "linux" { 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) 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)