本文整理匯總了Golang中github.com/flynn/flynn/Godeps/_workspace/src/github.com/cupcake/goamz/aws.AttemptStrategy.Start方法的典型用法代碼示例。如果您正苦於以下問題:Golang AttemptStrategy.Start方法的具體用法?Golang AttemptStrategy.Start怎麽用?Golang AttemptStrategy.Start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/flynn/flynn/Godeps/_workspace/src/github.com/cupcake/goamz/aws.AttemptStrategy
的用法示例。
在下文中一共展示了AttemptStrategy.Start方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: deleteGroups
// deleteGroups ensures the given groups are deleted, by retrying
// until a timeout or all groups cannot be found anymore.
// This should be used to make sure tests leave no groups around.
func (s *ServerTests) deleteGroups(c *C, groups []ec2.SecurityGroup) {
testAttempt := aws.AttemptStrategy{
Total: 2 * time.Minute,
Delay: 5 * time.Second,
}
for a := testAttempt.Start(); a.Next(); {
deleted := 0
c.Logf("deleting groups %v", groups)
for _, group := range groups {
_, err := s.ec2.DeleteSecurityGroup(group)
if err == nil || errorCode(err) == "InvalidGroup.NotFound" {
c.Logf("group %v deleted", group)
deleted++
continue
}
if err != nil {
c.Logf("retrying; DeleteSecurityGroup returned: %v", err)
}
}
if deleted == len(groups) {
c.Logf("all groups deleted")
return
}
}
c.Fatalf("timeout while waiting %v groups to get deleted!", groups)
}
示例2: TestAttemptTiming
func (S) TestAttemptTiming(c *C) {
testAttempt := aws.AttemptStrategy{
Total: 0.25e9,
Delay: 0.1e9,
}
want := []time.Duration{0, 0.1e9, 0.2e9, 0.2e9}
got := make([]time.Duration, 0, len(want)) // avoid allocation when testing timing
t0 := time.Now()
for a := testAttempt.Start(); a.Next(); {
got = append(got, time.Now().Sub(t0))
}
got = append(got, time.Now().Sub(t0))
c.Assert(got, HasLen, len(want))
const margin = 0.01e9
for i, got := range want {
lo := want[i] - margin
hi := want[i] + margin
if got < lo || got > hi {
c.Errorf("attempt %d want %g got %g", i, want[i].Seconds(), got.Seconds())
}
}
}
示例3: terminateInstances
func terminateInstances(c *C, e *ec2.EC2, ids []string) {
_, err := e.TerminateInstances(ids)
c.Assert(err, IsNil, Commentf("%v INSTANCES LEFT RUNNING!!!", ids))
// We need to wait until the instances are really off, because
// entities that depend on them won't be deleted (i.e. groups,
// NICs, subnets, etc.)
testAttempt := aws.AttemptStrategy{
Total: 10 * time.Minute,
Delay: 5 * time.Second,
}
f := ec2.NewFilter()
f.Add("instance-state-name", "terminated")
idsLeft := make(map[string]bool)
for _, id := range ids {
idsLeft[id] = true
}
for a := testAttempt.Start(); a.Next(); {
c.Logf("waiting for %v to get terminated", ids)
resp, err := e.Instances(ids, f)
if err != nil {
c.Fatalf("not waiting for %v to terminate: %v", ids, err)
}
for _, r := range resp.Reservations {
for _, inst := range r.Instances {
delete(idsLeft, inst.InstanceId)
}
}
ids = []string{}
for id, _ := range idsLeft {
ids = append(ids, id)
}
if len(ids) == 0 {
c.Logf("all instances terminated.")
return
}
}
c.Fatalf("%v INSTANCES LEFT RUNNING!!!", ids)
}
示例4: TestRunInstancesVPC
func (s *AmazonServerSuite) TestRunInstancesVPC(c *C) {
vpcResp, err := s.ec2.CreateVPC("10.6.0.0/16", "")
c.Assert(err, IsNil)
vpcId := vpcResp.VPC.Id
defer s.deleteVPCs(c, []string{vpcId})
subResp := s.createSubnet(c, vpcId, "10.6.1.0/24", "")
subId := subResp.Subnet.Id
defer s.deleteSubnets(c, []string{subId})
groupResp, err := s.ec2.CreateSecurityGroupVPC(
vpcId,
sessionName("testgroup1 vpc"),
"testgroup description vpc",
)
c.Assert(err, IsNil)
group := groupResp.SecurityGroup
defer s.deleteGroups(c, []ec2.SecurityGroup{group})
// Run a single instance with a new network interface.
ips := []ec2.PrivateIP{
{Address: "10.6.1.10", IsPrimary: true},
{Address: "10.6.1.20", IsPrimary: false},
}
instResp, err := s.ec2.RunInstances(&ec2.RunInstances{
MinCount: 1,
ImageId: imageId,
InstanceType: "t1.micro",
NetworkInterfaces: []ec2.RunNetworkInterface{{
DeviceIndex: 0,
SubnetId: subId,
PrivateIPs: ips,
SecurityGroupIds: []string{group.Id},
DeleteOnTermination: true,
}},
})
c.Assert(err, IsNil)
inst := &instResp.Instances[0]
defer terminateInstances(c, s.ec2, []string{inst.InstanceId})
// Now list the network interfaces and find ours.
testAttempt := aws.AttemptStrategy{
Total: 5 * time.Minute,
Delay: 5 * time.Second,
}
f := ec2.NewFilter()
f.Add("subnet-id", subId)
var newNIC *ec2.NetworkInterface
for a := testAttempt.Start(); a.Next(); {
c.Logf("waiting for NIC to become available")
listNICs, err := s.ec2.NetworkInterfaces(nil, f)
if err != nil {
c.Logf("retrying; NetworkInterfaces returned: %v", err)
continue
}
for _, iface := range listNICs.Interfaces {
c.Logf("found NIC %v", iface)
if iface.Attachment.InstanceId == inst.InstanceId {
c.Logf("instance %v new NIC appeared", inst.InstanceId)
newNIC = &iface
break
}
}
if newNIC != nil {
break
}
}
if newNIC == nil {
c.Fatalf("timeout while waiting for NIC to appear.")
}
c.Check(newNIC.Id, Matches, `^eni-[0-9a-f]+$`)
c.Check(newNIC.SubnetId, Equals, subId)
c.Check(newNIC.VPCId, Equals, vpcId)
c.Check(newNIC.Status, Matches, `^(attaching|in-use)$`)
c.Check(newNIC.PrivateIPAddress, Equals, ips[0].Address)
c.Check(newNIC.PrivateIPs, DeepEquals, ips)
c.Check(newNIC.Groups, HasLen, 1)
c.Check(newNIC.Groups[0].Id, Equals, group.Id)
c.Check(newNIC.Attachment.Status, Matches, `^(attaching|attached)$`)
c.Check(newNIC.Attachment.DeviceIndex, Equals, 0)
c.Check(newNIC.Attachment.DeleteOnTermination, Equals, true)
}