Commit 5167c65f authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

Merge branch 'b-openstack-privage'

parents fc62afaa 2c683c50
...@@ -20,6 +20,13 @@ func CommHost( ...@@ -20,6 +20,13 @@ func CommHost(
return func(state multistep.StateBag) (string, error) { return func(state multistep.StateBag) (string, error) {
s := state.Get("server").(*servers.Server) s := state.Get("server").(*servers.Server)
// If we have a specific interface, try that
if sshinterface != "" {
if addr := sshAddrFromPool(s, sshinterface, port); addr != "" {
return addr, nil
}
}
// If we have a floating IP, use that // If we have a floating IP, use that
ip := state.Get("access_ip").(*floatingip.FloatingIP) ip := state.Get("access_ip").(*floatingip.FloatingIP)
if ip != nil && ip.IP != "" { if ip != nil && ip.IP != "" {
...@@ -30,31 +37,9 @@ func CommHost( ...@@ -30,31 +37,9 @@ func CommHost(
return s.AccessIPv4, nil return s.AccessIPv4, nil
} }
// Get all the addresses associated with this server. This // Try to get it from the requested interface
// was taken directly from Terraform. if addr := sshAddrFromPool(s, sshinterface, port); addr != "" {
for _, networkAddresses := range s.Addresses { return addr, nil
elements, ok := networkAddresses.([]interface{})
if !ok {
log.Printf(
"[ERROR] Unknown return type for address field: %#v",
networkAddresses)
continue
}
for _, element := range elements {
var addr string
address := element.(map[string]interface{})
if address["OS-EXT-IPS:type"] == "floating" {
addr = address["addr"].(string)
} else {
if address["version"].(float64) == 4 {
addr = address["addr"].(string)
}
}
if addr != "" {
return addr, nil
}
}
} }
s, err := servers.Get(client, s.ID).Extract() s, err := servers.Get(client, s.ID).Extract()
...@@ -89,3 +74,42 @@ func SSHConfig(username string) func(multistep.StateBag) (*ssh.ClientConfig, err ...@@ -89,3 +74,42 @@ func SSHConfig(username string) func(multistep.StateBag) (*ssh.ClientConfig, err
}, nil }, nil
} }
} }
func sshAddrFromPool(s *servers.Server, desired string, port int) string {
// Get all the addresses associated with this server. This
// was taken directly from Terraform.
for pool, networkAddresses := range s.Addresses {
// If we have an SSH interface specified, skip it if no match
if desired != "" && pool != desired {
log.Printf(
"[INFO] Skipping pool %s, doesn't match requested %s",
pool, desired)
continue
}
elements, ok := networkAddresses.([]interface{})
if !ok {
log.Printf(
"[ERROR] Unknown return type for address field: %#v",
networkAddresses)
continue
}
for _, element := range elements {
var addr string
address := element.(map[string]interface{})
if address["OS-EXT-IPS:type"] == "floating" {
addr = address["addr"].(string)
} else {
if address["version"].(float64) == 4 {
addr = address["addr"].(string)
}
}
if addr != "" {
return fmt.Sprintf("%s:%d", addr, port)
}
}
}
return ""
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment