2014-11-10 12:16:02 -06:00
|
|
|
package xenserver
|
|
|
|
|
|
|
|
import (
|
2014-12-09 05:47:07 -06:00
|
|
|
"fmt"
|
2014-12-08 09:34:48 -06:00
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
"time"
|
2014-11-10 12:16:02 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
type stepWait struct{}
|
|
|
|
|
|
|
|
func (self *stepWait) Run(state multistep.StateBag) multistep.StepAction {
|
2014-12-08 11:49:07 -06:00
|
|
|
config := state.Get("config").(config)
|
2014-12-08 09:34:48 -06:00
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
client := state.Get("client").(XenAPIClient)
|
|
|
|
|
|
|
|
ui.Say("Step: Wait for install to complete.")
|
|
|
|
|
|
|
|
instance_id := state.Get("instance_uuid").(string)
|
2014-12-09 05:47:07 -06:00
|
|
|
instance, err := client.GetVMByUuid(instance_id)
|
|
|
|
if err != nil {
|
|
|
|
ui.Error(fmt.Sprintf("Could not get VM from UUID %s", instance_id))
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2014-12-08 09:34:48 -06:00
|
|
|
|
2014-12-08 11:49:07 -06:00
|
|
|
//Expect install to be configured to shutdown on completion
|
2014-12-09 05:47:07 -06:00
|
|
|
err = InterruptibleWait{
|
2014-12-09 05:17:35 -06:00
|
|
|
Predicate: func() (bool, error) {
|
2014-12-09 05:47:07 -06:00
|
|
|
ui.Say("Waiting for install to complete.")
|
2014-12-08 11:49:07 -06:00
|
|
|
power_state, err := instance.GetPowerState()
|
|
|
|
return power_state == "Halted", err
|
|
|
|
},
|
|
|
|
PredicateInterval: 30 * time.Second,
|
2014-12-09 05:17:35 -06:00
|
|
|
Timeout: config.InstallTimeout,
|
2014-12-08 11:49:07 -06:00
|
|
|
}.Wait(state)
|
2014-12-08 09:34:48 -06:00
|
|
|
|
2014-12-08 11:49:07 -06:00
|
|
|
if err != nil {
|
|
|
|
ui.Error(err.Error())
|
|
|
|
ui.Error("Giving up waiting for installation to complete.")
|
|
|
|
return multistep.ActionHalt
|
2014-12-08 09:34:48 -06:00
|
|
|
}
|
|
|
|
|
2014-12-08 11:49:07 -06:00
|
|
|
ui.Say("Install has completed. Moving on.")
|
|
|
|
|
2014-12-08 09:34:48 -06:00
|
|
|
return multistep.ActionContinue
|
2014-11-10 12:16:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self *stepWait) Cleanup(state multistep.StateBag) {}
|