Reduce the VNC port step to just obtaining the correct port number. Use the port forward step to simplify the code.
Signed-off-by: Rob Dobson <rob.dobson@citrix.com>
This commit is contained in:
parent
b61adffc01
commit
16a8be4fb0
52
builder/xenserver/step_get_vnc_port.go
Normal file
52
builder/xenserver/step_get_vnc_port.go
Normal file
@ -0,0 +1,52 @@
|
||||
package xenserver
|
||||
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/multistep"
|
||||
"github.com/mitchellh/packer/packer"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"log"
|
||||
)
|
||||
|
||||
type stepGetVNCPort struct {}
|
||||
|
||||
|
||||
func (self *stepGetVNCPort) Run(state multistep.StateBag) multistep.StepAction {
|
||||
|
||||
config := state.Get("config").(config)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
|
||||
ui.Say("Step: forward the instances VNC port over SSH")
|
||||
|
||||
domid := state.Get("domid").(string)
|
||||
cmd := fmt.Sprintf("xenstore-read /local/domain/%s/console/vnc-port", domid)
|
||||
|
||||
remote_vncport, _ := execute_ssh_cmd(cmd, config.HostIp, "22", config.Username, config.Password)
|
||||
|
||||
remote_port, err := strconv.ParseUint(remote_vncport, 10, 16)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
log.Fatal(fmt.Sprintf("Unable to convert '%s' to an int", remote_vncport))
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
state.Put("instance_vnc_port", uint(remote_port))
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
|
||||
func (self *stepGetVNCPort) Cleanup(state multistep.StateBag) {
|
||||
}
|
||||
|
||||
func instanceVNCPort (state multistep.StateBag) (uint, error) {
|
||||
vncPort := state.Get("instance_vnc_port").(uint)
|
||||
return vncPort, nil
|
||||
}
|
||||
|
||||
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
|
||||
}
|
Loading…
Reference in New Issue
Block a user