Example #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,
		)
	}
}
Example #2
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)
	}
}
Example #3
0
func instances(e *ec2.EC2, args ...string) {
	filter := ec2.NewFilter()
	for _, v := range args {
		sl := strings.SplitN(v, "=", 2)
		if len(sl) != 2 {
			fmt.Fprintf(os.Stderr, "instances: bad key=value pair \"%s\", skipping\n", v)
			continue
		}
		filter.Add(sl[0], sl[1])
	}

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

	for _, r := range resp.Reservations {
		fmt.Println("reservation:", r.ReservationId)
		for _, i := range r.Instances {
			fmt.Printf("%s\t%s\t%s\t%s\n", i.InstanceId, i.State.Name, i.DNSName, i.ImageId)
		}
	}
}