Esempio n. 1
0
File: ec2.go Progetto: vito/gocloud
func (a *DescribeInstances) Run() error {
	log.Print("describing ec2 instances")
	instances, e := client().DescribeInstances()
	if e != nil {
		return e
	}
	if a.Detailed {
		for _, i := range instances {
			table := gocli.NewTable()
			table.Add(i.InstanceId, "Name", i.Name())
			table.Add(i.InstanceId, "ImageId", i.ImageId)
			table.Add(i.InstanceId, "InstanceType", i.InstanceType)
			table.Add(i.InstanceId, "InstanceStateName", i.InstanceStateName)
			table.Add(i.InstanceId, "Availability Zone", i.PlacementAvailabilityZone)
			table.Add(i.InstanceId, "KeyName", i.KeyName)
			table.Add(i.InstanceId, "IpAddress", i.IpAddress)
			table.Add(i.InstanceId, "PrivateIpAddress", i.PrivateIpAddress)
			table.Add(i.InstanceId, "LaunchTime", i.LaunchTime.Format("2006-01-02T15:04:05"))
			table.Add(i.InstanceId, "VpcId", i.VpcId)
			table.Add(i.InstanceId, "MonitoringState", i.MonitoringState)
			table.Add(i.InstanceId, "SubnetId", i.SubnetId)
			for _, group := range i.SecurityGroups {
				table.Add(i.InstanceId, "SecurityGroup", group.GroupId)
			}
			for _, tag := range i.Tags {
				table.Add(i.InstanceId, "Tag", tag.Key, tag.Value)
			}
			fmt.Println(table)
		}
		return nil
	}
	table := gocli.NewTable()
	table.Add("id", "image", "name", "state", "type", "private_ip", "ip", "az", "launched")
	for _, i := range instances {
		sgs := []string{}
		if i.InstanceStateName != "running" {
			continue
		}
		for _, g := range i.SecurityGroups {
			sgs = append(sgs, g.GroupId)
		}
		table.Add(
			i.InstanceId,
			i.ImageId,
			i.Name(),
			i.InstanceStateName,
			i.InstanceType,
			i.PrivateIpAddress,
			i.IpAddress,
			i.PlacementAvailabilityZone,
			i.LaunchTime.Format("2006-01-02T15:04"),
		)
	}
	fmt.Println(table)
	return nil
}
Esempio n. 2
0
File: ec2.go Progetto: vito/gocloud
func (a *DescribeImages) Run() error {
	log.Println("describing images")
	filter := &ec2.ImageFilter{}
	if a.Canonical {
		filter.Owner = ec2.CANONICAL_OWNER_ID
	} else if a.Self {
		filter.Owner = ec2.SELF_OWNER_ID
	}

	if a.Ubuntu {
		filter.Name = ec2.UBUNTU_PREFIX
	} else if a.Raring {
		filter.Name = ec2.UBUNTU_RARING_PREFIX
	} else if a.Saucy {
		filter.Name = ec2.UBUNTU_SAUCY_PREFIX
	}

	images, e := client().DescribeImagesWithFilter(filter)
	if e != nil {
		return e
	}
	sort.Sort(images)
	table := gocli.NewTable()
	for _, image := range images {
		table.Add(image.ImageId, image.Name, image.ImageState)
	}
	fmt.Println(table)
	return nil
}
Esempio n. 3
0
func printServer(server *jiffybox.Server) {
	table := gocli.NewTable()
	table.Add("Id", server.Id)
	table.Add("Name", server.Name)
	table.Add("Status", server.Status)
	table.Add("Created", server.CreatedAt().Format(TIME_FORMAT))
	table.Add("Host", server.Host)
	table.Add("Running", server.Running)
	table.Add("RecoverymodeActive", server.RecoverymodeActive)
	table.Add("Plan", server.Plan.Id)
	table.Add("Cpu", server.Plan.Cpus)
	table.Add("RAM", server.Plan.RamInMB)
	table.Add("IsBeingCopied", server.IsBeingCopied)
	table.Add("ManualBackupRunning", server.ManualBackupRunning)
	if server.ActiveProfile != nil {
		table.Add("Profile Name", server.ActiveProfile.Name)
		table.Add("Profile Kernel", server.ActiveProfile.Kernel)
	}
	i := 0
	for k, v := range server.Ips {
		key := ""
		if i == 0 {
			key = "Ips"
			i++
		}
		table.Add(key, k+": "+strings.Join(v, ", "))
	}
	fmt.Println(table)
}
Esempio n. 4
0
func (r *route53ListResourceRecordSet) Run() error {
	client := route53.NewFromEnv()
	rrsets, e := client.ListResourceRecordSets(r.HostedZone)
	if e != nil {
		return e
	}
	table := gocli.NewTable()
	table.Add("name", "type", "ttl", "weight", "id", "hc id", "value")
	maxLen := 64
	for _, rrs := range rrsets {
		weight := ""
		if rrs.Weight > 0 {
			weight = fmt.Sprintf("%d", rrs.Weight)
		}
		col := []string{
			rrs.Name, rrs.Type, fmt.Sprintf("%d", rrs.TTL), rrs.SetIdentifier, weight, rrs.HealthCheckId,
		}
		for i, record := range rrs.ResourceRecords {
			v := record.Value
			if len(v) > maxLen {
				v = v[0:maxLen]
			}
			if i == 0 {
				col = append(col, v)
				table.AddStrings(col)
			} else {
				table.Add("", "", "", "", "", "", v)
			}
		}
	}
	fmt.Println(table)
	return nil
}
Esempio n. 5
0
func Compare() error {
	table := gocli.NewTable()
	for _, plan := range digitalocean.Plans {
		table.Add(plan.Cores, fmt.Sprintf("%.1f GB", float64(plan.MemoryInMB)/1024.0))
	}

	pricing, e := aws.LinuxOnDemand()
	if e != nil {
		return e
	}
	counts := map[string]int{}
	for _, region := range pricing.Config.Regions {
		for _, typ := range region.InstanceTypes {
			for _, size := range typ.Sizes {
				for _, vc := range size.ValueColumns {
					counts[size.Size]++
					table.Add(region.Region, typ.Type, size.Size, vc.Name, vc.Prices["USD"])
				}
			}
		}
	}
	fmt.Println(table)
	fmt.Println(counts)
	return nil
}
Esempio n. 6
0
func ListDropletsAction() (e error) {
	logger.Debug("listing droplets")

	droplets, e := CurrentAccount().Droplets()
	if e != nil {
		return e
	}

	if _, e := CurrentAccount().CachedSizes(); e != nil {
		return e
	}

	table := gocli.NewTable()
	if len(droplets) == 0 {
		table.Add("no droplets found")
	} else {
		table.Add("Id", "Created", "Status", "Locked", "Name", "IPAddress", "Region", "Size", "Image")
		for _, droplet := range droplets {
			table.Add(
				strconv.Itoa(droplet.Id),
				droplet.CreatedAt.Format("2006-01-02T15:04"),
				droplet.Status,
				strconv.FormatBool(droplet.Locked),
				droplet.Name,
				droplet.IpAddress,
				fmt.Sprintf("%s (%d)", CurrentAccount().RegionName(droplet.RegionId), droplet.RegionId),
				fmt.Sprintf("%s (%d)", CurrentAccount().SizeName(droplet.SizeId), droplet.SizeId),
				fmt.Sprintf("%s (%d)", CurrentAccount().ImageName(droplet.ImageId), droplet.ImageId),
			)
		}
	}
	fmt.Fprintln(os.Stdout, table.String())
	return nil
}
Esempio n. 7
0
func (a *ParametersDescribe) Run() error {
	client := cloudformation.NewFromEnv()
	tpl := cloudformation.DescribeStacks{
		StackName: a.Name,
	}
	rsp, e := tpl.Execute(client)
	if e != nil {
		return e
	}
	stacks := rsp.DescribeStacksResult.Stacks
	if len(stacks) != 1 {
		return fmt.Errorf("expected 1 stack for %q, got %d", a.Name, len(stacks))
	}
	stack := stacks[0]
	t := gocli.NewTable()
	for _, p := range stack.Parameters {
		value := p.ParameterValue
		if len(value) > 64 && !a.Full {
			value = value[0:64] + "... (truncated)"
		}
		t.Add(p.ParameterKey, value)
	}
	fmt.Println(t)
	return nil
}
Esempio n. 8
0
func (l *ListGists) Run() error {
	rsp, e := authenticatedRequest("GET", urlRoot+"/gists", nil)
	if e != nil {
		return e
	}
	defer rsp.Body.Close()
	gists := []*Gist{}
	e = json.NewDecoder(rsp.Body).Decode(&gists)
	if e != nil {
		return e
	}
	t := gocli.NewTable()
	for _, g := range gists {
		name := ""
		if len(g.Files) > 0 {
			for n := range g.Files {
				name = n
				break
			}
		}
		if g.Public || !l.Public {
			t.Add(g.CreatedAt.Local().Format(time.RFC3339), g.Id, name, g.Description)
		}
	}
	io.WriteString(os.Stdout, t.String()+"\n")
	return nil
}
Esempio n. 9
0
func (act *list) Run() error {
	resp, err := newClient().DescribeDBSnapshots(&rds.DescribeDBSnapshotsInput{DBInstanceIdentifier: &act.InstanceId})
	if err != nil {
		return err
	}
	snapshots := resp.DBSnapshots
	logger.Printf("found %d snapshots", len(snapshots))

	table := gocli.NewTable()
	for i := range snapshots {
		t := ""
		if v := snapshots[i].SnapshotCreateTime; v != nil {
			t = v.UTC().Format("2006-01-02 15:04:05")
		}
		table.Add(
			p2s(snapshots[i].DBInstanceIdentifier),
			p2s(snapshots[i].DBSnapshotIdentifier),
			p2s(snapshots[i].Status),
			p2i64(snapshots[i].AllocatedStorage),
			p2s(snapshots[i].Engine),
			p2s(snapshots[i].EngineVersion),
			t,
		)
	}
	fmt.Println(table)
	return nil
}
Esempio n. 10
0
func (a *nodesLS) Run() error {
	h := a.Host
	if !strings.HasPrefix(h, "http") {
		h = "http://" + h
	}
	rsp, err := http.Get(h + "/_nodes/stats")
	if err != nil {
		return err
	}
	defer rsp.Body.Close()
	if rsp.Status[0] != '2' {
		b, _ := ioutil.ReadAll(rsp.Body)
		return fmt.Errorf("got status %s but expected 2x. body=%s", rsp.Status, string(b))
	}
	var r *nodeStatsResponse
	if err := json.NewDecoder(rsp.Body).Decode(&r); err != nil {
		return err
	}
	t := gocli.NewTable()
	list := NodeStats{}
	for _, n := range r.Nodes {
		list = append(list, n)
	}
	sort.Sort(list)
	t.Add("name", "host", "address", "load5", "cpu sys", "cpu user", "cpu idle", "mem used")
	for _, n := range list {
		load5 := ""
		if len(n.OS.LoadAverage) > 0 {
			load5 = fmt.Sprintf("%.2f", n.OS.LoadAverage[0])
		}
		t.Add(n.Name, n.Host, n.TransportAddress, load5, n.OS.CPU.Sys, n.OS.CPU.User, n.OS.CPU.Idle, n.OS.Mem.UsedPercent)
	}
	fmt.Println(t)
	return nil
}
Esempio n. 11
0
File: ec2.go Progetto: vito/gocloud
func DescribeSecurityGroups() error {
	groups, e := client().DescribeSecurityGroups(nil)
	if e != nil {
		return e
	}
	table := gocli.NewTable()
	for _, group := range groups {
		table.Add(group.GroupId, "", "", group.GroupName)
		for _, perm := range group.IpPermissions {
			ports := ""
			if perm.FromPort > 0 {
				if perm.FromPort == perm.ToPort {
					ports += fmt.Sprintf("%d", perm.FromPort)
				} else {
					ports += fmt.Sprintf("%d-%d", perm.FromPort, perm.ToPort)
				}
			}
			groups := []string{}
			for _, group := range perm.Groups {
				groups = append(groups, group.GroupId)
			}
			if len(groups) > 0 {
				table.Add("", perm.IpProtocol, ports, strings.Join(groups, ","))
			}

			if len(perm.IpRanges) > 0 {
				table.Add("", perm.IpProtocol, ports, strings.Join(perm.IpRanges, ","))
			}
		}
	}
	fmt.Print(table)
	return nil
}
Esempio n. 12
0
func (r *dropletsList) Run() error {
	cl, e := client()
	if e != nil {
		return e
	}
	rsp, e := cl.Droplets()
	if e != nil {
		return e
	}
	t := gocli.NewTable()
	t.Add("Id", "Status", "Ip", "Name", "Region", "Size", "ImageId:ImageName (ImageSlug)", "CreatedAt")
	for _, d := range rsp.Droplets {
		imageName := fmt.Sprintf("%d:%s", d.Image.Id, d.Image.Name)
		if d.Image.Slug != "" {
			imageName += " (" + d.Image.Slug + ")"
		}
		ip := ""
		if len(d.Networks.V4) > 0 {
			ip = d.Networks.V4[0].IpAddress
		}
		t.Add(d.Id, d.Status, ip, d.Name, d.Region.Slug, d.Size.Slug, imageName, d.CreatedAt.Format("2006-01-02T15:04:05"))
	}
	fmt.Println(t)
	return nil
}
Esempio n. 13
0
func VersionAction(args *gocli.Args) error {
	table := gocli.NewTable()
	table.Add("Version", digo.VERSION)
	if len(digo.GITCOMMIT) > 0 {
		table.Add("Revision", digo.GITCOMMIT)
	}
	fmt.Printf(table.String())
	return nil
}
Esempio n. 14
0
func printConfigsDetailed(regionName string, typ string, priceMapping map[string]pricing.PriceList, configs pricing.InstanceTypeConfigs) {
	table := gocli.NewTable()
	for _, config := range configs {
		table.Add("Type", config.Name)
		table.Add("CPUs", config.Cpus)
		table.Add("Storage", config.Storage)
		table.Add("-------", "")
	}
	fmt.Println(table)
}
Esempio n. 15
0
func (r *StackDescription) Run() error {
	client := cloudformation.NewFromEnv()
	rsp, e := client.DescribeStacks(&cloudformation.DescribeStacksParameters{
		StackName: r.Name,
	})
	if e != nil {
		return e
	}
	if rsp.DescribeStacksResult == nil || len(rsp.DescribeStacksResult.Stacks) == 0 {
		return nil
	}

	s := rsp.DescribeStacksResult.Stacks[0]

	t := gocli.NewTable()
	t.Add("name", s.StackName)
	t.Add("created", s.CreationTime)
	t.Add("state", s.StackStatus)
	if len(s.Parameters) > 0 {
		t := gocli.NewTable()
		fmt.Println("Parameters:")
		for _, p := range s.Parameters {
			t.Add(p.ParameterKey, p.ParameterValue)
		}
		fmt.Println(t)
	} else {
		fmt.Println("Parameters: none")
	}

	if len(s.Outputs) > 0 {
		t := gocli.NewTable()
		fmt.Println("Outputs:")
		for _, p := range s.Outputs {
			t.Add(p.OutputKey, p.OutputValue)
		}
		fmt.Println(t)
	} else {
		fmt.Println("Outputs: none")
	}
	fmt.Println(t)
	return nil
}
Esempio n. 16
0
File: ec2.go Progetto: vito/gocloud
func DescribeKeyPairs() error {
	pairs, e := client().DescribeKeyPairs()
	if e != nil {
		return e
	}
	table := gocli.NewTable()
	for _, pair := range pairs {
		table.Add(pair.KeyName, pair.KeyFingerprint)
	}
	fmt.Print(table)
	return nil
}
Esempio n. 17
0
File: ec2.go Progetto: vito/gocloud
func DescribeAddresses() error {
	addresses, e := client().DescribeAddresses()
	if e != nil {
		return e
	}
	table := gocli.NewTable()
	for _, address := range addresses {
		table.Add(address.PublicIp, address.PrivateIpAddress, address.Domain, address.InstanceId)
	}
	fmt.Print(table)
	return nil
}
Esempio n. 18
0
func (list *ListTemplates) Run() error {
	templates, e := vmware.AllTemplates()
	if e != nil {
		return e
	}
	table := gocli.NewTable()
	table.Add("Name", "Path")
	for _, t := range templates {
		table.Add(t.Id(), t.Path)
	}
	logger.Println(table)
	return nil
}
Esempio n. 19
0
File: ec2.go Progetto: vito/gocloud
func DescribeTags() error {
	tags, e := client().DescribeTags()
	if e != nil {
		return e
	}
	sort.Sort(tags)
	table := gocli.NewTable()
	for _, tag := range tags {
		table.Add(tag.ResourceType, tag.ResourceId, tag.Key, tag.Value)
	}
	fmt.Println(table)
	return nil
}
Esempio n. 20
0
func ListAllDataCentersHandler() error {
	dcs, e := profitbricks.NewFromEnv().GetAllDataCenters()
	if e != nil {
		return e
	}
	table := gocli.NewTable()
	table.Add("Id", "Name", "Version")
	for _, dc := range dcs {
		table.Add(dc.DataCenterId, dc.DataCenterName, dc.DataCenterVersion)
	}
	fmt.Println(table)
	return nil
}
Esempio n. 21
0
func (a *DescribeDataCenterHandler) Run() error {
	client := profitbricks.NewFromEnv()
	dc, e := client.GetDataCenter(a.DataCenterId)
	if e != nil {
		return e
	}

	table := gocli.NewTable()
	table.Add("Id", dc.DataCenterId)
	table.Add("Name", dc.DataCenterName)
	table.Add("Region", dc.Region)
	table.Add("State", dc.ProvisioningState)
	table.Add("Version", dc.DataCenterVersion)
	fmt.Println(table)
	fmt.Println("\nServers:")
	if len(dc.Servers) > 0 {
		table = gocli.NewTable()
		table.Add("Id", "Created", "Name", "Lans", "Ip", "AZ", "ProvState", "VMState", "Ram", "Cores", "Internet")
		for _, server := range dc.Servers {
			table.Add(server.ServerId, server.CreationTime.Format("2006-01-02T15:04"), server.ServerName, server.Lans(), strings.Join(server.Ips, ","), server.AvailabilityZone, server.ProvisioningState, server.VirtualMachineState, server.Ram, server.Cores, server.InternetAccess)
		}
		fmt.Println(table)
	} else {
		fmt.Println("* None *")
	}

	fmt.Println("\nStorages:")
	if len(dc.Storages) > 0 {
		table = gocli.NewTable()
		table.Add("Id", "Name", "Size")
		for _, storage := range dc.Storages {
			table.Add(storage.StorageId, storage.StorageName, storage.Size)
		}
		fmt.Println(table)
	} else {
		fmt.Println("* None *")
	}
	return nil
}
Esempio n. 22
0
func ListKeysAction() error {
	table := gocli.NewTable()
	table.Add("Id", "Name")
	keys, e := CurrentAccount().SshKeys()
	if e != nil {
		return e
	}
	for _, key := range keys {
		table.Add(strconv.Itoa(key.Id), key.Name)
	}
	fmt.Fprintln(os.Stdout, table.String())
	return nil
}
Esempio n. 23
0
func (d *DescribeDroplet) Run() error {
	droplet, e := CurrentAccount().GetDroplet(d.Id)
	if e != nil {
		return e
	}
	table := gocli.NewTable()
	table.Add("Id", fmt.Sprintf("%d", droplet.Id))
	table.Add("Name", droplet.Name)
	table.Add("Status", droplet.Status)
	table.Add("Locked", strconv.FormatBool(droplet.Locked))
	fmt.Println(table)
	return nil
}
Esempio n. 24
0
func listServers(args *gocli.Args) error {
	servers, e := account.Servers()
	if e != nil {
		return e
	}
	table := gocli.NewTable()
	table.Add("Number", "Name", "Product", "DC", "Ip", "Status")
	for _, server := range servers {
		table.Add(server.ServerNumber, server.ServerName, server.Product, server.Dc, server.ServerIp, server.Status)
	}
	fmt.Println(table)
	return nil
}
Esempio n. 25
0
func iamGetAccountSummary() error {
	client := iam.NewFromEnv()
	summary, e := client.GetAccountSummary()
	if e != nil {
		return e
	}
	table := gocli.NewTable()
	for _, entry := range summary.Entries {
		table.Add(entry.Key, entry.Value)
	}
	fmt.Println(table)
	return nil
}
Esempio n. 26
0
func iamListUsers() error {
	client := iam.NewFromEnv()
	rsp, e := client.ListUsers()
	if e != nil {
		return e
	}
	table := gocli.NewTable()
	for _, user := range rsp.Users {
		table.Add(user.UserId, user.UserName, strings.TrimSpace(user.Arn))
	}
	fmt.Println(table)
	return nil
}
Esempio n. 27
0
func JiffyBoxListDistributionsAction() error {
	distributions, e := client().Distributions()
	if e != nil {
		return e
	}
	table := gocli.NewTable()
	table.Add("Key", "Name", "Min Disk Size", "Default Kernel")
	for _, distribution := range distributions {
		table.Add(distribution.Key, distribution.Name, distribution.MinDiskSizeMB, distribution.DefaultKernel)
	}
	fmt.Println(table)
	return nil
}
Esempio n. 28
0
func JiffyBoxListBackups() error {
	backups, e := client().Backups()
	if e != nil {
		return e
	}

	table := gocli.NewTable()
	for _, backup := range backups {
		table.Add(backup.Id, backup.ServerId, backup.Key, backup.CreatedAt().Format(TIME_FORMAT))
	}
	fmt.Println(table)
	return nil
}
Esempio n. 29
0
func (r *dropletsList) Run() error {
	cl, e := client()
	if e != nil {
		return e
	}
	rsp, e := cl.Droplets()
	if e != nil {
		return e
	}
	t := gocli.NewTable()
	t.Add("Id", "Status", "IP", "Private IP", "Name", "Region", "Size", "ImageId:ImageName (ImageSlug)", "CreatedAt")
	for _, d := range rsp.Droplets {
		imageName := fmt.Sprintf("%d:%s", d.Image.Id, d.Image.Name)
		if d.Image.Slug != "" {
			imageName += " (" + d.Image.Slug + ")"
		}
		var public, private string
		if d.Networks != nil {
			for _, i := range d.Networks.V4 {
				switch i.Type {
				case "public":
					public = i.IpAddress
				case "private":
					private = i.IpAddress

				}
			}
		}
		reg := func() string {
			if d.Region != nil {
				return d.Region.Slug
			}
			return ""
		}()
		created := func() string {
			if !d.CreatedAt.IsZero() {
				return d.CreatedAt.Format("2006-01-02 15:04:05")
			}
			return ""
		}()
		size := func() string {
			if d.Size != nil {
				return d.Size.Slug
			}
			return d.SizeSlug
		}()
		t.Add(d.Id, d.Status, public, private, d.Name, reg, size, imageName, created)
	}
	fmt.Println(t)
	return nil
}
Esempio n. 30
0
func ListAllStorages() error {
	client := profitbricks.NewFromEnv()
	storages, e := client.GetAllStorages()
	if e != nil {
		return e
	}
	table := gocli.NewTable()
	table.Add("Id", "Name", "ProvisioningState", "Servers", "Image Name", "Image ID")
	for _, storage := range storages {
		table.Add(storage.StorageId, storage.StorageName, storage.ProvisioningState, strings.Join(storage.ServerIds, ","), storage.ImageName, storage.ImageId)
	}
	fmt.Println(table)
	return nil
}