本文整理匯總了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
}
示例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)
}
示例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)))
}
示例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)
}
}
}
}