2013-05-21 03:55:32 -04:00
|
|
|
package amazonebs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/mitchellh/goamz/ec2"
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2013-06-04 14:29:59 -04:00
|
|
|
func waitForState(ec2conn *ec2.EC2, originalInstance *ec2.Instance, pending []string, target string) (i *ec2.Instance, err error) {
|
2013-05-21 03:55:32 -04:00
|
|
|
log.Printf("Waiting for instance state to become: %s", target)
|
|
|
|
|
|
|
|
i = originalInstance
|
2013-06-04 14:29:59 -04:00
|
|
|
for i.State.Name != target {
|
|
|
|
found := false
|
|
|
|
for _, allowed := range pending {
|
|
|
|
if i.State.Name == allowed {
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !found {
|
|
|
|
fmt.Errorf("unexpected state '%s', wanted target '%s'", i.State.Name, target)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2013-05-21 03:55:32 -04:00
|
|
|
var resp *ec2.InstancesResp
|
|
|
|
resp, err = ec2conn.Instances([]string{i.InstanceId}, ec2.NewFilter())
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
i = &resp.Reservations[0].Instances[0]
|
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|