Exemple #1
0
func images(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("is-public", "false")
	}
	for _, v := range args {
		s := strings.SplitN(v, "=", 2)
		if len(s) != 2 {
			fmt.Fprintf(os.Stderr, "images: bad key=value pair \"%s\", skipping\n", v)
			continue
		}
		filter.Add(s[0], s[1])
	}

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

	for _, i := range resp.Images {
		fmt.Printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
			i.Id,
			i.Name,
			i.State,
			i.Architecture,
			i.Type,
			i.OwnerAlias,
			i.Description,
			i.Platform)
	}
}