cloud

package
v1.14.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GetCloudCmd = &cobra.Command{
	Use:   "cloud [gpuCount]",
	Args:  cobra.MaximumNArgs(1),
	Short: "get all cloud gpus",
	Long:  "get all cloud gpus available on runpod.io",
	Run: func(cmd *cobra.Command, args []string) {
		var err error
		gpuCount := 1
		if len(args) > 0 {
			gpuCount, err = strconv.Atoi(args[0])
			cobra.CheckErr(err)
			if gpuCount <= 0 {
				cobra.CheckErr(fmt.Errorf("gpu count must be > 0: %d", gpuCount))
			}
		}
		var secureCloud *bool
		if secure != community {
			secureCloud = &secure
		}
		input := &api.GetCloudInput{
			GpuCount:      gpuCount,
			MinMemoryInGb: memory,
			MinVcpuCount:  vcpu,
			SecureCloud:   secureCloud,
			TotalDisk:     disk,
		}
		gpuTypes, err := api.GetCloud(input)
		cobra.CheckErr(err)

		data := [][]string{}
		for _, gpu := range gpuTypes {
			gpuType, ok := gpu.(map[string]interface{})
			if !ok {
				continue
			}
			kv, ok := gpuType["lowestPrice"].(map[string]interface{})
			if !ok || kv["minMemory"] == nil {
				continue
			}
			spotPrice, ok := kv["minimumBidPrice"].(float64)
			spotPriceString := "Reserved"
			if ok && spotPrice > 0 {
				spotPriceString = fmt.Sprintf("%.3f", spotPrice)
			}
			onDemandPrice, ok := kv["uninterruptablePrice"].(float64)
			onDemandPriceString := "Reserved"
			if ok && spotPrice > 0 {
				onDemandPriceString = fmt.Sprintf("%.3f", onDemandPrice)
			}
			row := []string{
				fmt.Sprintf("%dx %s", gpuCount, kv["gpuTypeId"].(string)),
				fmt.Sprintf("%.f", kv["minMemory"]),
				fmt.Sprintf("%.f", kv["minVcpu"]),
				spotPriceString,
				onDemandPriceString,
			}
			data = append(data, row)
		}

		header := []string{"GPU Type", "Mem GB", "vCPU", "Spot $/HR", "OnDemand $/HR"}
		tb := tablewriter.NewWriter(os.Stdout)
		tb.SetHeader(header)
		tb.AppendBulk(data)
		format.TableDefaults(tb)
		tb.Render()
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL