当前位置: 首页>>代码示例>>Golang>>正文


Golang EC2.Instances方法代码示例

本文整理汇总了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, " "))
		}
	}
}
开发者ID:juanman2,项目名称:dot-emacs,代码行数:25,代码来源:ec2.go

示例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
}
开发者ID:RubanDeventhiran,项目名称:ansible-kick,代码行数:13,代码来源:ec2.go

示例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 ""
}
开发者ID:projectweekend,项目名称:vip,代码行数:19,代码来源:peer.go

示例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
}
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:20,代码来源:iaas.go

示例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)
}
开发者ID:BillTheBest,项目名称:libswarm,代码行数:38,代码来源:ec2t_test.go


注:本文中的launchpad/net/goamz/ec2.EC2.Instances方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。