2015-02-17 00:23:21 -05:00
|
|
|
package openstack
|
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
2015-02-17 00:23:21 -05:00
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2016-11-27 19:59:26 -05:00
|
|
|
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2015-02-17 00:23:21 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type StepWaitForRackConnect struct {
|
|
|
|
Wait bool
|
|
|
|
}
|
|
|
|
|
2018-01-22 18:31:41 -05:00
|
|
|
func (s *StepWaitForRackConnect) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
2015-02-17 00:23:21 -05:00
|
|
|
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) {
|
|
|
|
}
|