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