github.com/raghuse92/packer@v1.3.2/builder/openstack/step_wait_for_rackconnect.go (about)

     1  package openstack
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"time"
     7  
     8  	"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
     9  	"github.com/hashicorp/packer/helper/multistep"
    10  	"github.com/hashicorp/packer/packer"
    11  )
    12  
    13  type StepWaitForRackConnect struct {
    14  	Wait bool
    15  }
    16  
    17  func (s *StepWaitForRackConnect) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
    18  	if !s.Wait {
    19  		return multistep.ActionContinue
    20  	}
    21  
    22  	config := state.Get("config").(*Config)
    23  	server := state.Get("server").(*servers.Server)
    24  	ui := state.Get("ui").(packer.Ui)
    25  
    26  	// We need the v2 compute client
    27  	computeClient, err := config.computeV2Client()
    28  	if err != nil {
    29  		err = fmt.Errorf("Error initializing compute client: %s", err)
    30  		state.Put("error", err)
    31  		return multistep.ActionHalt
    32  	}
    33  
    34  	ui.Say(fmt.Sprintf(
    35  		"Waiting for server (%s) to become RackConnect ready...", server.ID))
    36  	for {
    37  		server, err = servers.Get(computeClient, server.ID).Extract()
    38  		if err != nil {
    39  			return multistep.ActionHalt
    40  		}
    41  
    42  		if server.Metadata["rackconnect_automation_status"] == "DEPLOYED" {
    43  			state.Put("server", server)
    44  			break
    45  		}
    46  
    47  		time.Sleep(2 * time.Second)
    48  	}
    49  
    50  	return multistep.ActionContinue
    51  }
    52  
    53  func (s *StepWaitForRackConnect) Cleanup(state multistep.StateBag) {
    54  }