Beispiel #1
0
func snapshots(e *ec2.EC2, args ...string) {
	isAll := false
	if len(args) > 0 {
		if args[0] == "-all" {
			isAll = true
			args = args[1:]
		}
	}

	filter := ec2.NewFilter()
	if !isAll {
		filter.Add("owner-id", "self")
	}
	for _, v := range args {
		sl := strings.SplitN(v, "=", 2)
		if len(sl) != 2 {
			fmt.Fprintf(os.Stderr, "snapshots: bad key=value pair \"%s\", skipping\n", v)
			continue
		}
		filter.Add(sl[0], sl[1])
	}

	resp, err := e.Snapshots(nil, filter)
	if err != nil {
		fmt.Fprintf(os.Stderr, "snapshots: %s\n", err)
		os.Exit(1)
	}

	for _, i := range resp.Snapshots {
		fmt.Printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
			i.Id,
			i.VolumeId,
			i.Status,
			i.StartTime,
			i.Progress,
			i.OwnerId,
			i.VolumeSize,
			i.Description,
			i.OwnerAlias,
		)
	}
}