github.phpd.cn/hashicorp/packer@v1.3.2/builder/scaleway/step_server_info.go (about) 1 package scaleway 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/hashicorp/packer/helper/multistep" 8 "github.com/hashicorp/packer/packer" 9 "github.com/scaleway/scaleway-cli/pkg/api" 10 ) 11 12 type stepServerInfo struct{} 13 14 func (s *stepServerInfo) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { 15 client := state.Get("client").(*api.ScalewayAPI) 16 ui := state.Get("ui").(packer.Ui) 17 serverID := state.Get("server_id").(string) 18 19 ui.Say("Waiting for server to become active...") 20 21 _, err := api.WaitForServerState(client, serverID, "running") 22 if err != nil { 23 err := fmt.Errorf("Error waiting for server to become booted: %s", err) 24 state.Put("error", err) 25 ui.Error(err.Error()) 26 return multistep.ActionHalt 27 } 28 29 server, err := client.GetServer(serverID) 30 if err != nil { 31 err := fmt.Errorf("Error retrieving server: %s", err) 32 state.Put("error", err) 33 ui.Error(err.Error()) 34 return multistep.ActionHalt 35 } 36 37 state.Put("server_ip", server.PublicAddress.IP) 38 state.Put("root_volume_id", server.Volumes["0"].Identifier) 39 40 return multistep.ActionContinue 41 } 42 43 func (s *stepServerInfo) Cleanup(state multistep.StateBag) { 44 // no cleanup 45 }