|
|
|
|
@ -21,15 +21,16 @@ import (
|
|
|
|
|
// Produces:
|
|
|
|
|
// vnc_port uint - The port that VNC is configured to listen on.
|
|
|
|
|
type StepConfigureVNC struct {
|
|
|
|
|
VNCPortMin uint
|
|
|
|
|
VNCPortMax uint
|
|
|
|
|
VNCBindAddress string
|
|
|
|
|
VNCPortMin uint
|
|
|
|
|
VNCPortMax uint
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type VNCAddressFinder interface {
|
|
|
|
|
VNCAddress(uint, uint) (string, uint, error)
|
|
|
|
|
VNCAddress(string, uint, uint) (string, uint, error)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (StepConfigureVNC) VNCAddress(portMin, portMax uint) (string, uint, error) {
|
|
|
|
|
func (StepConfigureVNC) VNCAddress(vncBindAddress string, 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.
|
|
|
|
|
@ -43,13 +44,13 @@ func (StepConfigureVNC) VNCAddress(portMin, portMax uint) (string, uint, error)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Printf("Trying port: %d", vncPort)
|
|
|
|
|
l, err := net.Listen("tcp", fmt.Sprintf(":%d", vncPort))
|
|
|
|
|
l, err := net.Listen("tcp", fmt.Sprintf("%s:%d", vncBindAddress, vncPort))
|
|
|
|
|
if err == nil {
|
|
|
|
|
defer l.Close()
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "127.0.0.1", vncPort, nil
|
|
|
|
|
return vncBindAddress, vncPort, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *StepConfigureVNC) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
|
@ -80,7 +81,7 @@ func (s *StepConfigureVNC) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
|
vncFinder = s
|
|
|
|
|
}
|
|
|
|
|
log.Printf("Looking for available port between %d and %d", s.VNCPortMin, s.VNCPortMax)
|
|
|
|
|
vncIp, vncPort, err := vncFinder.VNCAddress(s.VNCPortMin, s.VNCPortMax)
|
|
|
|
|
vncBindAddress, vncPort, err := vncFinder.VNCAddress(s.VNCBindAddress, s.VNCPortMin, s.VNCPortMax)
|
|
|
|
|
if err != nil {
|
|
|
|
|
state.Put("error", err)
|
|
|
|
|
ui.Error(err.Error())
|
|
|
|
|
@ -92,6 +93,7 @@ func (s *StepConfigureVNC) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
|
vmxData := ParseVMX(string(vmxBytes))
|
|
|
|
|
vmxData["remotedisplay.vnc.enabled"] = "TRUE"
|
|
|
|
|
vmxData["remotedisplay.vnc.port"] = fmt.Sprintf("%d", vncPort)
|
|
|
|
|
vmxData["remotedisplay.vnc.ip"] = fmt.Sprintf("%s", vncBindAddress)
|
|
|
|
|
|
|
|
|
|
if err := WriteVMX(vmxPath, vmxData); err != nil {
|
|
|
|
|
err := fmt.Errorf("Error writing VMX data: %s", err)
|
|
|
|
|
@ -101,7 +103,7 @@ func (s *StepConfigureVNC) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
state.Put("vnc_port", vncPort)
|
|
|
|
|
state.Put("vnc_ip", vncIp)
|
|
|
|
|
state.Put("vnc_ip", vncBindAddress)
|
|
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
|
}
|
|
|
|
|
|