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"
|
2020-12-17 16:29:25 -05:00
|
|
|
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
|
|
|
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
2015-02-17 00:23:21 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type StepWaitForRackConnect struct {
|
|
|
|
Wait bool
|
|
|
|
}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
func (s *StepWaitForRackConnect) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2015-02-17 00:23:21 -05:00
|
|
|
if !s.Wait {
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2018-09-18 10:05:49 -04:00
|
|
|
config := state.Get("config").(*Config)
|
2015-06-12 00:16:43 -04:00
|
|
|
server := state.Get("server").(*servers.Server)
|
2020-11-19 14:54:31 -05:00
|
|
|
ui := state.Get("ui").(packersdk.Ui)
|
2015-02-17 00:23:21 -05:00
|
|
|
|
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) {
|
|
|
|
}
|