Commit 37b92dff authored by higebu's avatar higebu

Fix unknown command and syntax error of the ESX5Driver

parent da7dd7f8
...@@ -45,6 +45,9 @@ type Driver interface { ...@@ -45,6 +45,9 @@ type Driver interface {
// Get the path to the VMware ISO for the given flavor. // Get the path to the VMware ISO for the given flavor.
ToolsIsoPath(string) string ToolsIsoPath(string) string
// Attach the VMware tools ISO
ToolsInstall() error
// Get the path to the DHCP leases file for the given device. // Get the path to the DHCP leases file for the given device.
DhcpLeasesPath(string) string DhcpLeasesPath(string) string
......
...@@ -148,6 +148,10 @@ func (d *Fusion5Driver) ToolsIsoPath(k string) string { ...@@ -148,6 +148,10 @@ func (d *Fusion5Driver) ToolsIsoPath(k string) string {
return filepath.Join(d.AppPath, "Contents", "Library", "isoimages", k+".iso") return filepath.Join(d.AppPath, "Contents", "Library", "isoimages", k+".iso")
} }
func (d *Fusion5Driver) ToolsInstall() error {
return nil
}
func (d *Fusion5Driver) DhcpLeasesPath(device string) string { func (d *Fusion5Driver) DhcpLeasesPath(device string) string {
return "/var/db/vmware/vmnet-dhcpd-" + device + ".leases" return "/var/db/vmware/vmnet-dhcpd-" + device + ".leases"
} }
......
...@@ -51,6 +51,9 @@ type DriverMock struct { ...@@ -51,6 +51,9 @@ type DriverMock struct {
ToolsIsoPathFlavor string ToolsIsoPathFlavor string
ToolsIsoPathResult string ToolsIsoPathResult string
ToolsInstallCalled bool
ToolsInstallErr error
DhcpLeasesPathCalled bool DhcpLeasesPathCalled bool
DhcpLeasesPathDevice string DhcpLeasesPathDevice string
DhcpLeasesPathResult string DhcpLeasesPathResult string
...@@ -120,6 +123,11 @@ func (d *DriverMock) ToolsIsoPath(flavor string) string { ...@@ -120,6 +123,11 @@ func (d *DriverMock) ToolsIsoPath(flavor string) string {
return d.ToolsIsoPathResult return d.ToolsIsoPathResult
} }
func (d *DriverMock) ToolsInstall() error {
d.ToolsInstallCalled = true
return d.ToolsInstallErr
}
func (d *DriverMock) DhcpLeasesPath(device string) string { func (d *DriverMock) DhcpLeasesPath(device string) string {
d.DhcpLeasesPathCalled = true d.DhcpLeasesPathCalled = true
d.DhcpLeasesPathDevice = device d.DhcpLeasesPathDevice = device
......
...@@ -187,6 +187,10 @@ func (d *Player5LinuxDriver) ToolsIsoPath(flavor string) string { ...@@ -187,6 +187,10 @@ func (d *Player5LinuxDriver) ToolsIsoPath(flavor string) string {
return "/usr/lib/vmware/isoimages/" + flavor + ".iso" return "/usr/lib/vmware/isoimages/" + flavor + ".iso"
} }
func (d *Player5LinuxDriver) ToolsInstall() error {
return nil
}
func (d *Player5LinuxDriver) DhcpLeasesPath(device string) string { func (d *Player5LinuxDriver) DhcpLeasesPath(device string) string {
return "/etc/vmware/" + device + "/dhcpd/dhcpd.leases" return "/etc/vmware/" + device + "/dhcpd/dhcpd.leases"
} }
...@@ -149,6 +149,10 @@ func (d *Workstation9Driver) ToolsIsoPath(flavor string) string { ...@@ -149,6 +149,10 @@ func (d *Workstation9Driver) ToolsIsoPath(flavor string) string {
return workstationToolsIsoPath(flavor) return workstationToolsIsoPath(flavor)
} }
func (d *Workstation9Driver) ToolsInstall() error {
return nil
}
func (d *Workstation9Driver) DhcpLeasesPath(device string) string { func (d *Workstation9Driver) DhcpLeasesPath(device string) string {
return workstationDhcpLeasesPath(device) return workstationDhcpLeasesPath(device)
} }
......
...@@ -31,6 +31,7 @@ type ESX5Driver struct { ...@@ -31,6 +31,7 @@ type ESX5Driver struct {
comm packer.Communicator comm packer.Communicator
outputDir string outputDir string
vmId string
} }
func (d *ESX5Driver) Clone(dst, src string) error { func (d *ESX5Driver) Clone(dst, src string) error {
...@@ -46,9 +47,8 @@ func (d *ESX5Driver) CreateDisk(diskPathLocal string, size string, typeId string ...@@ -46,9 +47,8 @@ func (d *ESX5Driver) CreateDisk(diskPathLocal string, size string, typeId string
return d.sh("vmkfstools", "-c", size, "-d", typeId, "-a", "lsilogic", diskPath) return d.sh("vmkfstools", "-c", size, "-d", typeId, "-a", "lsilogic", diskPath)
} }
func (d *ESX5Driver) IsRunning(vmxPathLocal string) (bool, error) { func (d *ESX5Driver) IsRunning(string) (bool, error) {
vmxPath := filepath.Join(d.outputDir, filepath.Base(vmxPathLocal)) state, err := d.run(nil, "vim-cmd", "vmsvc/power.getstate", d.vmId)
state, err := d.run(nil, "vim-cmd", "vmsvc/power.getstate", vmxPath)
if err != nil { if err != nil {
return false, err return false, err
} }
...@@ -56,13 +56,11 @@ func (d *ESX5Driver) IsRunning(vmxPathLocal string) (bool, error) { ...@@ -56,13 +56,11 @@ func (d *ESX5Driver) IsRunning(vmxPathLocal string) (bool, error) {
} }
func (d *ESX5Driver) Start(vmxPathLocal string, headless bool) error { func (d *ESX5Driver) Start(vmxPathLocal string, headless bool) error {
vmxPath := filepath.Join(d.outputDir, filepath.Base(vmxPathLocal)) return d.sh("vim-cmd", "vmsvc/power.on", d.vmId)
return d.sh("vim-cmd", "vmsvc/power.on", vmxPath)
} }
func (d *ESX5Driver) Stop(vmxPathLocal string) error { func (d *ESX5Driver) Stop(vmxPathLocal string) error {
vmxPath := filepath.Join(d.outputDir, filepath.Base(vmxPathLocal)) return d.sh("vim-cmd", "vmsvc/power.off", d.vmId)
return d.sh("vim-cmd", "vmsvc/power.off", vmxPath)
} }
func (d *ESX5Driver) Register(vmxPathLocal string) error { func (d *ESX5Driver) Register(vmxPathLocal string) error {
...@@ -70,7 +68,12 @@ func (d *ESX5Driver) Register(vmxPathLocal string) error { ...@@ -70,7 +68,12 @@ func (d *ESX5Driver) Register(vmxPathLocal string) error {
if err := d.upload(vmxPath, vmxPathLocal); err != nil { if err := d.upload(vmxPath, vmxPathLocal); err != nil {
return err return err
} }
return d.sh("vim-cmd", "solo/registervm", vmxPath) r, err := d.run(nil, "vim-cmd", "solo/registervm", vmxPath)
if err != nil {
return err
}
d.vmId = strings.TrimRight(r, "\n")
return nil
} }
func (d *ESX5Driver) SuppressMessages(vmxPath string) error { func (d *ESX5Driver) SuppressMessages(vmxPath string) error {
...@@ -78,8 +81,7 @@ func (d *ESX5Driver) SuppressMessages(vmxPath string) error { ...@@ -78,8 +81,7 @@ func (d *ESX5Driver) SuppressMessages(vmxPath string) error {
} }
func (d *ESX5Driver) Unregister(vmxPathLocal string) error { func (d *ESX5Driver) Unregister(vmxPathLocal string) error {
vmxPath := filepath.Join(d.outputDir, filepath.Base(vmxPathLocal)) return d.sh("vim-cmd", "vmsvc/unregister", d.vmId)
return d.sh("vim-cmd", "vmsvc/unregister", vmxPath)
} }
func (d *ESX5Driver) UploadISO(localPath string) (string, error) { func (d *ESX5Driver) UploadISO(localPath string) (string, error) {
...@@ -105,6 +107,10 @@ func (d *ESX5Driver) ToolsIsoPath(string) string { ...@@ -105,6 +107,10 @@ func (d *ESX5Driver) ToolsIsoPath(string) string {
return "" return ""
} }
func (d *ESX5Driver) ToolsInstall() error {
return d.sh("vim-cmd", "vmsvc/tools.install", d.vmId)
}
func (d *ESX5Driver) DhcpLeasesPath(string) string { func (d *ESX5Driver) DhcpLeasesPath(string) string {
return "" return ""
} }
...@@ -168,35 +174,18 @@ func (d *ESX5Driver) SSHAddress(state multistep.StateBag) (string, error) { ...@@ -168,35 +174,18 @@ func (d *ESX5Driver) SSHAddress(state multistep.StateBag) (string, error) {
return address.(string), nil return address.(string), nil
} }
r, err := d.esxcli("network", "vm", "list") r, err := d.run(nil, "vim-cmd", "vmsvc/get.guest", d.vmId, " | grep -m 1 ipAddress | awk -F'\"' '{print $2}'")
if err != nil {
return "", err
}
record, err := r.find("Name", config.VMName)
if err != nil { if err != nil {
return "", err return "", err
} }
wid := record["WorldID"]
if wid == "" {
return "", errors.New("VM WorldID not found")
}
r, err = d.esxcli("network", "vm", "port", "list", "-w", wid) ipAddress := strings.TrimRight(r, "\n")
if err != nil {
return "", err
}
record, err = r.read()
if err != nil {
return "", err
}
if record["IPAddress"] == "0.0.0.0" { if ipAddress == "" {
return "", errors.New("VM network port found, but no IP address") return "", errors.New("VM network port found, but no IP address")
} }
address := fmt.Sprintf("%s:%d", record["IPAddress"], config.SSHPort) address := fmt.Sprintf("%s:%d", ipAddress, config.SSHPort)
state.Put("vm_address", address) state.Put("vm_address", address)
return address, nil return address, nil
} }
......
...@@ -13,6 +13,10 @@ func (*stepPrepareTools) Run(state multistep.StateBag) multistep.StepAction { ...@@ -13,6 +13,10 @@ func (*stepPrepareTools) Run(state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*config) config := state.Get("config").(*config)
driver := state.Get("driver").(vmwcommon.Driver) driver := state.Get("driver").(vmwcommon.Driver)
if config.RemoteType == "esx5" {
return multistep.ActionContinue
}
if config.ToolsUploadFlavor == "" { if config.ToolsUploadFlavor == "" {
return multistep.ActionContinue return multistep.ActionContinue
} }
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
vmwcommon "github.com/mitchellh/packer/builder/vmware/common"
"os" "os"
) )
...@@ -15,6 +16,15 @@ type stepUploadTools struct{} ...@@ -15,6 +16,15 @@ type stepUploadTools struct{}
func (*stepUploadTools) Run(state multistep.StateBag) multistep.StepAction { func (*stepUploadTools) Run(state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*config) config := state.Get("config").(*config)
driver := state.Get("driver").(vmwcommon.Driver)
if config.RemoteType == "esx5" {
if err := driver.ToolsInstall(); err != nil {
state.Put("error", fmt.Errorf("Couldn't mount VMware tools ISO."))
}
return multistep.ActionContinue
}
if config.ToolsUploadFlavor == "" { if config.ToolsUploadFlavor == "" {
return multistep.ActionContinue return multistep.ActionContinue
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment