2014-12-29 06:46:54 -06:00
|
|
|
package common
|
2014-11-18 12:47:50 -06:00
|
|
|
|
|
|
|
import (
|
2014-12-08 09:34:48 -06:00
|
|
|
"fmt"
|
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
"strconv"
|
2014-11-18 12:47:50 -06:00
|
|
|
)
|
|
|
|
|
2014-12-29 06:46:54 -06:00
|
|
|
type StepGetVNCPort struct{}
|
2014-11-18 12:47:50 -06:00
|
|
|
|
2014-12-29 06:46:54 -06:00
|
|
|
func (self *StepGetVNCPort) Run(state multistep.StateBag) multistep.StepAction {
|
2014-12-08 09:34:48 -06:00
|
|
|
ui := state.Get("ui").(packer.Ui)
|
2014-11-18 12:47:50 -06:00
|
|
|
|
2014-12-08 09:34:48 -06:00
|
|
|
ui.Say("Step: forward the instances VNC port over SSH")
|
2014-11-18 12:47:50 -06:00
|
|
|
|
2014-12-08 09:34:48 -06:00
|
|
|
domid := state.Get("domid").(string)
|
|
|
|
cmd := fmt.Sprintf("xenstore-read /local/domain/%s/console/vnc-port", domid)
|
2014-11-18 12:47:50 -06:00
|
|
|
|
2015-01-02 10:22:36 -06:00
|
|
|
remote_vncport, err := ExecuteHostSSHCmd(state, cmd)
|
2014-12-09 08:02:48 -06:00
|
|
|
if err != nil {
|
|
|
|
ui.Error(fmt.Sprintf("Unable to get VNC port (is the VM running?): %s", err.Error()))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2014-11-18 12:47:50 -06:00
|
|
|
|
2014-12-08 09:34:48 -06:00
|
|
|
remote_port, err := strconv.ParseUint(remote_vncport, 10, 16)
|
2014-11-18 12:47:50 -06:00
|
|
|
|
2014-12-08 09:34:48 -06:00
|
|
|
if err != nil {
|
2014-12-09 05:27:31 -06:00
|
|
|
ui.Error(fmt.Sprintf("Unable to convert '%s' to an int", remote_vncport))
|
|
|
|
ui.Error(err.Error())
|
2014-12-08 09:34:48 -06:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2014-11-18 12:47:50 -06:00
|
|
|
|
2014-12-08 09:34:48 -06:00
|
|
|
state.Put("instance_vnc_port", uint(remote_port))
|
2014-11-18 12:47:50 -06:00
|
|
|
|
2014-12-08 09:34:48 -06:00
|
|
|
return multistep.ActionContinue
|
2014-11-18 12:47:50 -06:00
|
|
|
}
|
|
|
|
|
2014-12-29 06:46:54 -06:00
|
|
|
func (self *StepGetVNCPort) Cleanup(state multistep.StateBag) {
|
2014-11-18 12:47:50 -06:00
|
|
|
}
|
|
|
|
|
2014-12-29 06:46:54 -06:00
|
|
|
func InstanceVNCPort(state multistep.StateBag) (uint, error) {
|
2014-12-08 09:34:48 -06:00
|
|
|
vncPort := state.Get("instance_vnc_port").(uint)
|
|
|
|
return vncPort, nil
|
2014-11-18 12:47:50 -06:00
|
|
|
}
|
|
|
|
|
2014-12-29 06:46:54 -06:00
|
|
|
func InstanceVNCIP(state multistep.StateBag) (string, error) {
|
2014-12-08 09:34:48 -06:00
|
|
|
// The port is in Dom0, so we want to forward from localhost
|
|
|
|
return "127.0.0.1", nil
|
2014-11-18 12:47:50 -06:00
|
|
|
}
|