當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ec2.EC2類代碼示例

本文整理匯總了Golang中github.com/crowdmob/goamz/ec2.EC2的典型用法代碼示例。如果您正苦於以下問題:Golang EC2類的具體用法?Golang EC2怎麽用?Golang EC2使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了EC2類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: getPrivateIPs

func getPrivateIPs(ec2region *ec2.EC2) []string {
	filter := ec2.NewFilter()

	for _, tag := range *tags {
		parts := strings.SplitN(tag, ":", 2)
		if len(parts) != 2 {
			log.Println("expected TAG:VALUE got", tag)
			break
		}
		filter.Add(fmt.Sprintf("tag:%v", parts[0]), parts[1])
	}

	taggedInstances := []string{}

	resp, err := ec2region.DescribeInstances(nil, filter)
	if err != nil {
		log.Println(err)
		return taggedInstances
	}

	for _, rsv := range resp.Reservations {
		for _, inst := range rsv.Instances {
			taggedInstances = append(taggedInstances, inst.PrivateIPAddress)
		}
	}
	return taggedInstances
}
開發者ID:madedotcom,項目名稱:varnish-purge-proxy,代碼行數:27,代碼來源:varnish-purge-proxy.go

示例2: tagSnapshot

func tagSnapshot(instId, snapId string, tags []ec2.Tag, c *ec2.EC2) {
	defer wg.Done()
	_, err := c.CreateTags([]string{snapId}, tags)
	if err != nil {
		log.Printf("failed to tag snaptshot %s for instance %s, error: %s", snapId, instId, err)
	}
	trimSnapshots(instId, c)
}
開發者ID:reedobrien,項目名稱:aws-go-utils,代碼行數:8,代碼來源:main.go

示例3: terminateInstances

func terminateInstances(c *gocheck.C, e *ec2.EC2, insts []*ec2.Instance) {
	var ids []string
	for _, inst := range insts {
		if inst != nil {
			ids = append(ids, inst.InstanceId)
		}
	}
	_, err := e.TerminateInstances(ids)
	c.Check(err, gocheck.IsNil, gocheck.Commentf("%d INSTANCES LEFT RUNNING!!!", len(ids)))
}
開發者ID:nkts,項目名稱:golang-devops-stuff,代碼行數:10,代碼來源:ec2t_test.go

示例4: trimSnapshots

func trimSnapshots(instId string, c *ec2.EC2) {
	filter := ec2.NewFilter()
	val := fmt.Sprintf("%s/%s", instId, *period)
	filter.Add("status", "completed")
	filter.Add("tag:inst_snap", val)
	resp, err := c.Snapshots(nil, filter)
	if err != nil {
		log.Printf("Error getting existing snapshots: ", err)
	}
	if len(resp.Snapshots) > *copies {
		excess := len(resp.Snapshots) - *copies
		extras := resp.Snapshots[:excess]
		log.Printf("Need %d have %d completed snapshots\n", *copies, len(resp.Snapshots))
		for _, extra := range extras {
			log.Printf("Trimming %s for %sn", extra.Id, instId)
			_, err := c.DeleteSnapshots([]string{extra.Id})
			if err != nil {
				log.Println("Failed trimming snapshot:", extra.Id, " Error: ", err)
			}
		}

	}
}
開發者ID:reedobrien,項目名稱:aws-go-utils,代碼行數:23,代碼來源:main.go


注:本文中的github.com/crowdmob/goamz/ec2.EC2類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。