packer-plugin-xenserver/builder/xenserver/step_get_vnc_port.go

50 lines
1.2 KiB
Go
Raw Normal View History

package xenserver
import (
2014-12-08 09:34:48 -06:00
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
"strconv"
)
2014-12-08 09:34:48 -06:00
type stepGetVNCPort struct{}
func (self *stepGetVNCPort) Run(state multistep.StateBag) multistep.StepAction {
2014-12-08 09:34:48 -06:00
config := state.Get("config").(config)
ui := state.Get("ui").(packer.Ui)
2014-12-08 09:34:48 -06:00
ui.Say("Step: forward the instances VNC port over SSH")
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-12-08 09:34:48 -06:00
remote_vncport, _ := execute_ssh_cmd(cmd, config.HostIp, "22", config.Username, config.Password)
2014-12-08 09:34:48 -06:00
remote_port, err := strconv.ParseUint(remote_vncport, 10, 16)
2014-12-08 09:34:48 -06:00
if err != nil {
log.Fatal(err.Error())
log.Fatal(fmt.Sprintf("Unable to convert '%s' to an int", remote_vncport))
return multistep.ActionHalt
}
2014-12-08 09:34:48 -06:00
state.Put("instance_vnc_port", uint(remote_port))
2014-12-08 09:34:48 -06:00
return multistep.ActionContinue
}
func (self *stepGetVNCPort) Cleanup(state multistep.StateBag) {
}
2014-12-08 09:34:48 -06:00
func instanceVNCPort(state multistep.StateBag) (uint, error) {
vncPort := state.Get("instance_vnc_port").(uint)
return vncPort, nil
}
2014-12-08 09:34:48 -06:00
func instanceVNCIP(state multistep.StateBag) (string, error) {
// The port is in Dom0, so we want to forward from localhost
return "127.0.0.1", nil
}