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


Golang EC2.DeleteSnapshot方法代码示例

本文整理汇总了Golang中github.com/aws/aws-sdk-go/service/ec2.EC2.DeleteSnapshot方法的典型用法代码示例。如果您正苦于以下问题:Golang EC2.DeleteSnapshot方法的具体用法?Golang EC2.DeleteSnapshot怎么用?Golang EC2.DeleteSnapshot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/aws/aws-sdk-go/service/ec2.EC2的用法示例。


在下文中一共展示了EC2.DeleteSnapshot方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: PurgeSnapshots

func PurgeSnapshots(svc *ec2.EC2) error {

	dsi := ec2.DescribeSnapshotsInput{}

	filter := &ec2.Filter{}
	filterName := "tag:" + PurgeAllowKey
	filter.Name = &filterName
	value := "true"
	filter.Values = []*string{&value}
	dsi.Filters = append(dsi.Filters, filter)

	dso, err := svc.DescribeSnapshots(&dsi)
	if err != nil {
		return fmt.Errorf("describeSnapshots error, %s", err)
	}

	purgeCount := 0
	for _, snapshot := range dso.Snapshots {
		var paVal string
		var found bool

		if paVal, found = getTagValue(PurgeAfterKey, snapshot.Tags); !found {
			log.Printf("snapshot ID %s has tag '%s' but does not have a '%s' tag. Skipping purge...", *snapshot.SnapshotId, PurgeAllowKey, PurgeAfterKey)
			continue
		}

		pa, err := time.Parse(PurgeAfterFormat, paVal)
		if err != nil {
			return err
		}

		if pa.Before(time.Now()) {
			deli := ec2.DeleteSnapshotInput{}
			deli.SnapshotId = snapshot.SnapshotId

			_, err := svc.DeleteSnapshot(&deli)
			if err != nil {
				return fmt.Errorf("error purging Snapshot ID %s, err %s", *snapshot.SnapshotId, err)
			}
			log.Printf("snapshot ID '%s' purged, size %d GiB\n", *snapshot.SnapshotId, *snapshot.VolumeSize)
			purgeCount++
		}
	}

	log.Printf("%d snapshots purged\n", purgeCount)

	return nil
}
开发者ID:porjo,项目名称:auto-snapshot,代码行数:48,代码来源:main.go

示例2: deleteOldSnapshots

func deleteOldSnapshots(svc *ec2.EC2, days int) {
	output, err := svc.DescribeSnapshots(&ec2.DescribeSnapshotsInput{Filters: []*ec2.Filter{
		{
			Name: aws.String("description"),
			Values: []*string{
				aws.String(descriptionPrefix + "-*"),
			},
		},
	}})
	if err != nil {
		fmt.Printf("%T(%v)", err, err)
		os.Exit(-1)
	}
	time := time.Now().AddDate(0, 0, -1*days)
	for _, snapshot := range output.Snapshots {
		if snapshot.StartTime.Before(time) {
			svc.DeleteSnapshot(&ec2.DeleteSnapshotInput{SnapshotId: snapshot.SnapshotId})
		}
	}
}
开发者ID:csimsek,项目名称:aws-autosnapshots-go,代码行数:20,代码来源:aws-autosnapshots.go


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