2015-02-17 00:23:21 -05:00
|
|
|
package openstack
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2016-11-27 19:59:26 -05:00
|
|
|
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
|
2015-06-12 00:16:43 -04:00
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
"github.com/mitchellh/packer/packer"
|
2015-02-17 00:23:21 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type StepWaitForRackConnect struct {
|
|
|
|
Wait bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepWaitForRackConnect) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
if !s.Wait {
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2015-06-12 00:16:43 -04:00
|
|
|
config := state.Get("config").(Config)
|
|
|
|
server := state.Get("server").(*servers.Server)
|
2015-02-17 00:23:21 -05:00
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
|
2015-06-12 00:16:43 -04:00
|
|
|
// We need the v2 compute client
|
|
|
|
computeClient, err := config.computeV2Client()
|
|
|
|
if err != nil {
|
|
|
|
err = fmt.Errorf("Error initializing compute client: %s", err)
|
|
|
|
state.Put("error", err)
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2015-02-17 00:23:21 -05:00
|
|
|
|
2015-06-12 00:16:43 -04:00
|
|
|
ui.Say(fmt.Sprintf(
|
|
|
|
"Waiting for server (%s) to become RackConnect ready...", server.ID))
|
2015-02-17 00:23:21 -05:00
|
|
|
for {
|
2015-06-12 00:16:43 -04:00
|
|
|
server, err = servers.Get(computeClient, server.ID).Extract()
|
2015-02-17 00:23:21 -05:00
|
|
|
if err != nil {
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
if server.Metadata["rackconnect_automation_status"] == "DEPLOYED" {
|
2015-07-27 18:07:25 -04:00
|
|
|
state.Put("server", server)
|
2015-02-17 00:23:21 -05:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepWaitForRackConnect) Cleanup(state multistep.StateBag) {
|
|
|
|
}
|