Commit 551e8077 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/openstack-new: fix some issues

parent c903579a
...@@ -3,6 +3,7 @@ package openstack ...@@ -3,6 +3,7 @@ package openstack
import ( import (
"errors" "errors"
"fmt" "fmt"
"log"
"time" "time"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
...@@ -21,7 +22,8 @@ func SSHAddress( ...@@ -21,7 +22,8 @@ func SSHAddress(
s := state.Get("server").(*servers.Server) s := state.Get("server").(*servers.Server)
// If we have a floating IP, use that // If we have a floating IP, use that
if ip := state.Get("access_ip").(*floatingip.FloatingIP); ip.FixedIP != "" { ip := state.Get("access_ip").(*floatingip.FloatingIP)
if ip != nil && ip.FixedIP != "" {
return fmt.Sprintf("%s:%d", ip.FixedIP, port), nil return fmt.Sprintf("%s:%d", ip.FixedIP, port), nil
} }
...@@ -29,33 +31,34 @@ func SSHAddress( ...@@ -29,33 +31,34 @@ func SSHAddress(
return fmt.Sprintf("%s:%d", s.AccessIPv4, port), nil return fmt.Sprintf("%s:%d", s.AccessIPv4, port), nil
} }
// Get all the addresses associated with this server // Get all the addresses associated with this server. This
/* // was taken directly from Terraform.
ip_pools, err := s.AllAddressPools() for _, networkAddresses := range s.Addresses {
if err != nil { elements, ok := networkAddresses.([]interface{})
return "", errors.New("Error parsing SSH addresses") if !ok {
log.Printf(
"[ERROR] Unknown return type for address field: %#v",
networkAddresses)
continue
} }
for pool, addresses := range ip_pools {
if sshinterface != "" { for _, element := range elements {
if pool != sshinterface { var addr string
continue 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 pool != "" { if addr != "" {
for _, address := range addresses { return fmt.Sprintf("%s:%d", addr, port), nil
if address.Addr != "" && address.Version == 4 {
return fmt.Sprintf("%s:%d", address.Addr, port), nil
}
}
} }
} }
*/
result := servers.Get(client, s.ID)
err := result.Err
if err == nil {
s, err = result.Extract()
} }
s, err := servers.Get(client, s.ID).Extract()
if err != nil { if err != nil {
return "", err return "", err
} }
......
...@@ -33,7 +33,7 @@ func (s *StepAllocateIp) Run(state multistep.StateBag) multistep.StepAction { ...@@ -33,7 +33,7 @@ func (s *StepAllocateIp) Run(state multistep.StateBag) multistep.StepAction {
state.Put("access_ip", instanceIp) state.Put("access_ip", instanceIp)
if s.FloatingIp != "" { if s.FloatingIp != "" {
instanceIp.FixedIP = s.FloatingIp *instanceIp = floatingip.FloatingIP{FixedIP: s.FloatingIp}
} else if s.FloatingIpPool != "" { } else if s.FloatingIpPool != "" {
newIp, err := floatingip.Create(client, floatingip.CreateOpts{ newIp, err := floatingip.Create(client, floatingip.CreateOpts{
Pool: s.FloatingIpPool, Pool: s.FloatingIpPool,
...@@ -45,11 +45,11 @@ func (s *StepAllocateIp) Run(state multistep.StateBag) multistep.StepAction { ...@@ -45,11 +45,11 @@ func (s *StepAllocateIp) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt return multistep.ActionHalt
} }
instanceIp = newIp *instanceIp = *newIp
ui.Say(fmt.Sprintf("Created temporary floating IP %s...", instanceIp.FixedIP)) ui.Say(fmt.Sprintf("Created temporary floating IP %s...", instanceIp.FixedIP))
} }
if instanceIp.FixedIP != "" { if instanceIp != nil && instanceIp.FixedIP != "" {
err := floatingip.Associate(client, server.ID, instanceIp.FixedIP).ExtractErr() err := floatingip.Associate(client, server.ID, instanceIp.FixedIP).ExtractErr()
if err != nil { if err != nil {
err := fmt.Errorf( err := fmt.Errorf(
...@@ -65,7 +65,6 @@ func (s *StepAllocateIp) Run(state multistep.StateBag) multistep.StepAction { ...@@ -65,7 +65,6 @@ func (s *StepAllocateIp) Run(state multistep.StateBag) multistep.StepAction {
} }
state.Put("access_ip", instanceIp) state.Put("access_ip", instanceIp)
return multistep.ActionContinue return multistep.ActionContinue
} }
......
...@@ -42,7 +42,7 @@ func (s *StepRunSourceServer) Run(state multistep.StateBag) multistep.StepAction ...@@ -42,7 +42,7 @@ func (s *StepRunSourceServer) Run(state multistep.StateBag) multistep.StepAction
CreateOptsBuilder: servers.CreateOpts{ CreateOptsBuilder: servers.CreateOpts{
Name: s.Name, Name: s.Name,
ImageRef: s.SourceImage, ImageRef: s.SourceImage,
FlavorRef: s.Flavor, FlavorName: s.Flavor,
SecurityGroups: s.SecurityGroups, SecurityGroups: s.SecurityGroups,
Networks: networks, Networks: networks,
}, },
......
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