本文整理汇总了Golang中launchpad/net/goamz/ec2.EC2.Instances方法的典型用法代码示例。如果您正苦于以下问题:Golang EC2.Instances方法的具体用法?Golang EC2.Instances怎么用?Golang EC2.Instances使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类launchpad/net/goamz/ec2.EC2
的用法示例。
在下文中一共展示了EC2.Instances方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: instances
func instances(c cmd, conn *ec2.EC2, args []string) {
resp, err := conn.Instances(nil, nil)
if err != nil {
fatalf("cannot get instances: %v", err)
}
var line []string
for _, r := range resp.Reservations {
for _, inst := range r.Instances {
if !instancesFlags.all && inst.State.Name == "terminated" {
continue
}
line = append(line[:0], inst.InstanceId)
if instancesFlags.state {
line = append(line, inst.State.Name)
}
if instancesFlags.addr {
if inst.DNSName == "" {
inst.DNSName = "none"
}
line = append(line, inst.DNSName)
}
fmt.Printf("%s\n", strings.Join(line, " "))
}
}
}
示例2: searchByFilter
func searchByFilter(e *ec2.EC2, key, value string) (*ec2.Instance, error) {
filter := ec2.NewFilter()
filter.Add(key, value)
resp, err := e.Instances(nil, filter)
if err != nil {
return nil, errors.New("EC2 API call failed. " +
"Check your AWS credentials and system clock")
}
if len(resp.Reservations) != 1 {
return nil, errors.New("no instance with " + key + "=" + value)
}
return &resp.Reservations[0].Instances[0], nil
}
示例3: getLocalIP
func getLocalIP(ec2conn *ec2.EC2) string {
f := ec2.NewFilter()
f.Add("tag:server-type", "image-proxy")
resp, err := ec2conn.Instances(nil, f)
if err != nil {
return ""
}
for _, reserv := range resp.Reservations {
for _, instance := range reserv.Instances {
if localAddress(instance.PrivateIPAddress) {
return instance.PrivateIPAddress
}
}
}
return ""
}
示例4: waitForDnsName
func waitForDnsName(ec2Inst *ec2.EC2, instance *ec2.Instance) (*ec2.Instance, error) {
t0 := time.Now()
for instance.DNSName == "" {
instId := instance.InstanceId
if time.Now().Sub(t0) > maxWaitTime {
return nil, fmt.Errorf("ec2: time out waiting for instance %s to start", instId)
}
log.Debugf("ec2: waiting for dnsname for instance %s", instId)
time.Sleep(500 * time.Millisecond)
resp, err := ec2Inst.Instances([]string{instance.InstanceId}, ec2.NewFilter())
if err != nil {
return nil, err
}
if len(resp.Reservations) == 0 || len(resp.Reservations[0].Instances) == 0 {
return nil, fmt.Errorf("No instances returned")
}
instance = &resp.Reservations[0].Instances[0]
}
return instance, nil
}
示例5: 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)
}