2013-07-25 01:56:37 -04:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mitchellh/goamz/ec2"
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// WaitForAMI waits for the given AMI ID to become ready.
|
|
|
|
func WaitForAMI(c *ec2.EC2, imageId string) error {
|
|
|
|
for {
|
|
|
|
imageResp, err := c.Images([]string{imageId}, ec2.NewFilter())
|
|
|
|
if err != nil {
|
2013-07-26 12:38:16 -04:00
|
|
|
if ec2err, ok := err.(*ec2.Error); ok && ec2err.Code == "InvalidAMIID.NotFound" {
|
|
|
|
log.Println("AMI not found, probably state issues on AWS side. Trying again.")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2013-07-25 01:56:37 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if imageResp.Images[0].State == "available" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("Image in state %s, sleeping 2s before checking again",
|
|
|
|
imageResp.Images[0].State)
|
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
}
|
|
|
|
}
|