packer-cn/builder/scaleway/step_server_info.go

45 lines
1.1 KiB
Go
Raw Normal View History

2017-04-06 05:19:17 -04:00
package scaleway
import (
"fmt"
"github.com/hashicorp/packer/packer"
"github.com/mitchellh/multistep"
"github.com/scaleway/scaleway-cli/pkg/api"
)
type stepServerInfo struct{}
func (s *stepServerInfo) Run(state multistep.StateBag) multistep.StepAction {
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
}