vmware-iso: Update VNCAddressFinder interface to return errors from VNCAddress()

This commit is contained in:
Jason A. Beranek 2014-08-18 20:28:25 -05:00
parent 6acbc91ff7
commit 2c41d59e21
2 changed files with 13 additions and 9 deletions

View File

@ -148,7 +148,7 @@ func (d *ESX5Driver) HostIP() (string, error) {
return host, err
}
func (d *ESX5Driver) VNCAddress(portMin, portMax uint) (string, uint) {
func (d *ESX5Driver) VNCAddress(portMin, portMax uint) (string, uint, error) {
var vncPort uint
// TODO(dougm) use esxcli network ip connection list
for port := portMin; port <= portMax; port++ {
@ -170,7 +170,13 @@ func (d *ESX5Driver) VNCAddress(portMin, portMax uint) (string, uint) {
}
}
return d.Host, vncPort
if vncPort == 0 {
err := fmt.Errorf("Unable to find available VNC port between %d and %d",
portMin, portMax)
return d.Host, vncPort, err
}
return d.Host, vncPort, nil
}
func (d *ESX5Driver) SSHAddress(state multistep.StateBag) (string, error) {

View File

@ -24,10 +24,10 @@ import (
type stepConfigureVNC struct{}
type VNCAddressFinder interface {
VNCAddress(uint, uint) (string, uint)
VNCAddress(uint, uint) (string, uint, error)
}
func (stepConfigureVNC) VNCAddress(portMin, portMax uint) (string, uint) {
func (stepConfigureVNC) VNCAddress(portMin, portMax uint) (string, uint, error) {
// Find an open VNC port. Note that this can still fail later on
// because we have to release the port at some point. But this does its
// best.
@ -47,7 +47,7 @@ func (stepConfigureVNC) VNCAddress(portMin, portMax uint) (string, uint) {
break
}
}
return "127.0.0.1", vncPort
return "127.0.0.1", vncPort, nil
}
func (s *stepConfigureVNC) Run(state multistep.StateBag) multistep.StepAction {
@ -79,10 +79,8 @@ func (s *stepConfigureVNC) Run(state multistep.StateBag) multistep.StepAction {
vncFinder = s
}
log.Printf("Looking for available port between %d and %d", config.VNCPortMin, config.VNCPortMax)
vncIp, vncPort := vncFinder.VNCAddress(config.VNCPortMin, config.VNCPortMax)
if vncPort == 0 {
err := fmt.Errorf("Unable to find available VNC port between %d and %d",
config.VNCPortMin, config.VNCPortMax)
vncIp, vncPort, err := vncFinder.VNCAddress(config.VNCPortMin, config.VNCPortMax)
if err != nil {
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt