packer-cn/builder/scaleway/step_server_info.go

46 lines
1.1 KiB
Go
Raw Normal View History

2017-04-06 05:19:17 -04:00
package scaleway
import (
2018-02-05 19:50:32 -05:00
"context"
2017-04-06 05:19:17 -04:00
"fmt"
2018-02-05 19:50:32 -05:00
"github.com/hashicorp/packer/helper/multistep"
2017-04-06 05:19:17 -04:00
"github.com/hashicorp/packer/packer"
"github.com/scaleway/scaleway-cli/pkg/api"
)
type stepServerInfo struct{}
2018-02-05 19:50:32 -05:00
func (s *stepServerInfo) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
2017-04-06 05:19:17 -04:00
client := state.Get("client").(*api.ScalewayAPI)
ui := state.Get("ui").(packer.Ui)
serverID := state.Get("server_id").(string)
ui.Say("Waiting for server to become active...")
_, err := api.WaitForServerState(client, serverID, "running")
if err != nil {
err := fmt.Errorf("Error waiting for server to become booted: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
server, err := client.GetServer(serverID)
if err != nil {
err := fmt.Errorf("Error retrieving server: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
state.Put("server_ip", server.PublicAddress.IP)
state.Put("root_volume_id", server.Volumes["0"].Identifier)
return multistep.ActionContinue
}
func (s *stepServerInfo) Cleanup(state multistep.StateBag) {
// no cleanup
}