Merge 23769430bb
into 756f4d7e1a
This commit is contained in:
commit
88bdc65044
@ -157,8 +157,7 @@ func forward(local_conn net.Conn, config *gossh.ClientConfig, server string, ser
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ssh_port_forward(local_listener net.Listener, remote_port int, remote_dest, host string, host_ssh_port int, username, password string) error {
|
func ssh_port_forward(local_listener net.Listener, remote_port int, host string, host_ssh_port int, username, password string, remote_dest_func func() (string, error)) error {
|
||||||
|
|
||||||
config := &gossh.ClientConfig{
|
config := &gossh.ClientConfig{
|
||||||
User: username,
|
User: username,
|
||||||
Auth: []gossh.AuthMethod{
|
Auth: []gossh.AuthMethod{
|
||||||
@ -175,6 +174,12 @@ func ssh_port_forward(local_listener net.Listener, remote_port int, remote_dest,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remote_dest, err := remote_dest_func()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Forward to a remote port
|
// Forward to a remote port
|
||||||
go forward(local_connection, config, host, host_ssh_port, remote_dest, uint(remote_port))
|
go forward(local_connection, config, host, host_ssh_port, remote_dest, uint(remote_port))
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ func (self *StepForwardPortOverSSH) Run(ctx context.Context, state multistep.Sta
|
|||||||
remotePort, _ := self.RemotePort(state)
|
remotePort, _ := self.RemotePort(state)
|
||||||
remoteDest, _ := self.RemoteDest(state)
|
remoteDest, _ := self.RemoteDest(state)
|
||||||
|
|
||||||
go ssh_port_forward(l, remotePort, remoteDest, hostAddress, hostSshPort, config.Username, config.Password)
|
go ssh_port_forward(l, remotePort, hostAddress, hostSshPort, config.Username, config.Password, func() (string, error) { return self.RemoteDest(state) })
|
||||||
ui.Say(fmt.Sprintf("Port forward setup. %d ---> %s:%d on %s", sshHostPort, remoteDest, remotePort, hostAddress))
|
ui.Say(fmt.Sprintf("Port forward setup. %d ---> %s:%d on %s", sshHostPort, remoteDest, remotePort, hostAddress))
|
||||||
|
|
||||||
// Provide the local port to future steps.
|
// Provide the local port to future steps.
|
||||||
|
@ -29,47 +29,62 @@ func (self *StepWaitForIP) Run(ctx context.Context, state multistep.StateBag) mu
|
|||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
go func(c Connection, ui packer.Ui, config CommonConfig) {
|
||||||
|
state.Put("instance_ssh_address", "")
|
||||||
var ip string
|
var ip string
|
||||||
err = InterruptibleWait{
|
|
||||||
Timeout: self.Timeout,
|
|
||||||
PredicateInterval: 5 * time.Second,
|
|
||||||
Predicate: func() (result bool, err error) {
|
|
||||||
|
|
||||||
|
for true {
|
||||||
|
time.Sleep(500 * time.Millisecond)
|
||||||
if config.IPGetter == "auto" || config.IPGetter == "http" {
|
if config.IPGetter == "auto" || config.IPGetter == "http" {
|
||||||
|
|
||||||
// Snoop IP from HTTP fetch
|
// Snoop IP from HTTP fetch
|
||||||
select {
|
select {
|
||||||
case ip = <-self.Chan:
|
case temp_ip := <-self.Chan:
|
||||||
|
if ip != temp_ip {
|
||||||
|
ip = temp_ip
|
||||||
ui.Message(fmt.Sprintf("Got IP '%s' from HTTP request", ip))
|
ui.Message(fmt.Sprintf("Got IP '%s' from HTTP request", ip))
|
||||||
return true, nil
|
state.Put("instance_ssh_address", ip)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.IPGetter == "auto" || config.IPGetter == "tools" {
|
if config.IPGetter == "auto" || config.IPGetter == "tools" {
|
||||||
|
|
||||||
// Look for PV IP
|
// Look for PV IP
|
||||||
m, err := c.client.VM.GetGuestMetrics(c.session, instance)
|
m, err := c.client.VM.GetGuestMetrics(c.session, instance)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
continue
|
||||||
}
|
}
|
||||||
if m != "" {
|
if m != "" {
|
||||||
metrics, err := c.client.VMGuestMetrics.GetRecord(c.session, m)
|
metrics, err := c.client.VMGuestMetrics.GetRecord(c.session, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
continue
|
||||||
}
|
}
|
||||||
networks := metrics.Networks
|
networks := metrics.Networks
|
||||||
var ok bool
|
if temp_ip, ok := networks["0/ip"]; ok {
|
||||||
if ip, ok = networks["0/ip"]; ok {
|
if temp_ip != "" && ip != temp_ip {
|
||||||
if ip != "" {
|
ip = temp_ip
|
||||||
ui.Message(fmt.Sprintf("Got IP '%s' from XenServer tools", ip))
|
ui.Message(fmt.Sprintf("Got IP '%s' from XenServer tools", ip))
|
||||||
return true, nil
|
state.Put("instance_ssh_address", ip)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}(*c, ui, config)
|
||||||
|
|
||||||
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
|
||||||
|
var ip string
|
||||||
|
|
||||||
|
err = InterruptibleWait{
|
||||||
|
Timeout: self.Timeout,
|
||||||
|
PredicateInterval: 5 * time.Second,
|
||||||
|
Predicate: func() (result bool, err error) {
|
||||||
|
var ok bool
|
||||||
|
if ip, ok = state.Get("instance_ssh_address").(string); ok && ip != "" {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
return false, nil
|
return false, nil
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user