Example #1
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
}
Example #2
0
func (a *Prices) Run() error {
	configs, e := pricing.AllInstanceTypeConfigs()
	if e != nil {
		return e
	}
	sort.Sort(configs)
	var pr *pricing.Pricing
	regionName := a.Region
	typ := "od"
	if a.Heavy {
		regionName = normalizeRegion(regionName)
		typ = "ri-heavy"
		pr, e = pricing.LinuxReservedHeavy()
	} else {
		regionName = normalizeRegionForOd(regionName)
		pr, e = pricing.LinuxOnDemand()
	}
	if e != nil {
		return e
	}
	priceMapping := map[string]pricing.PriceList{}
	region := pr.FindRegion(regionName)
	if region == nil {
		return fmt.Errorf("could not find prices for reagion %q. Known regions are %v", regionName, pr.RegionNames())
	}
	for _, t := range region.InstanceTypes {
		for _, size := range t.Sizes {
			priceMapping[size.Size] = size.ValueColumns.Prices()
		}
	}
	if a.Detailed {
		printConfigsDetailed(regionName, typ, priceMapping, configs)
	} else {
		printConfigs(regionName, typ, priceMapping, configs)
	}
	return nil
}