pod

package
v0.0.0-...-83a6fd2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllFields bool
View Source
var CreatePodCmd = &cobra.Command{
	Use:   "pod",
	Args:  cobra.ExactArgs(0),
	Short: "start a pod",
	Long:  "start a pod from runpod.io",
	Run: func(cmd *cobra.Command, args []string) {
		input := &api.CreatePodInput{
			ContainerDiskInGb: containerDiskInGb,
			DeployCost:        deployCost,
			DockerArgs:        dockerArgs,
			GpuCount:          gpuCount,
			GpuTypeId:         gpuTypeId,
			ImageName:         imageName,
			MinMemoryInGb:     minMemoryInGb,
			MinVcpuCount:      minVcpuCount,
			Name:              name,
			TemplateId:        templateId,
			VolumeInGb:        volumeInGb,
			VolumeMountPath:   volumeMountPath,
		}
		if len(ports) > 0 {
			input.Ports = strings.Join(ports, ",")
		}
		input.Env = make([]*api.PodEnv, len(env))
		for i, v := range env {
			e := strings.Split(v, "=")
			if len(e) != 2 {
				cobra.CheckErr(fmt.Errorf("wrong env value: %s", e))
			}
			input.Env[i] = &api.PodEnv{Key: e[0], Value: e[1]}
		}
		if secureCloud {
			input.CloudType = "SECURE"
		} else {
			input.CloudType = "COMMUNITY"
		}
		pod, err := api.CreatePod(input)
		cobra.CheckErr(err)

		if pod["desiredStatus"] == "RUNNING" {
			fmt.Printf(`pod "%s" created for $%.3f / hr`, pod["id"], pod["costPerHr"])
			fmt.Println()
		} else {
			cobra.CheckErr(fmt.Errorf(`pod "%s" start failed; status is %s`, args[0], pod["desiredStatus"]))
		}
	},
}
View Source
var GetPodCmd = &cobra.Command{
	Use:   "pod [podId]",
	Args:  cobra.MaximumNArgs(1),
	Short: "get all pods",
	Long:  "get all pods or specify pod id",
	Run: func(cmd *cobra.Command, args []string) {
		pods, err := api.GetPods()
		cobra.CheckErr(err)

		data := make([][]string, len(pods))
		for i, p := range pods {
			if len(args) == 1 && p.Id != strings.ToLower(args[0]) {
				continue
			}
			row := []string{p.Id, p.Name, fmt.Sprintf("%d %s", p.GpuCount, p.Machine.GpuDisplayName), p.ImageName, p.DesiredStatus}
			if AllFields {
				row = append(
					row,
					p.PodType,
					fmt.Sprintf("%d", p.VcpuCount),
					fmt.Sprintf("%d", p.MemoryInGb),
					fmt.Sprintf("%d", p.ContainerDiskInGb),
					fmt.Sprintf("%d", p.VolumeInGb),
					fmt.Sprintf("%.3f", p.CostPerHr),
				)
			}
			data[i] = row
		}

		header := []string{"ID", "Name", "GPU", "Image Name", "Status"}
		if AllFields {
			header = append(header, "Pod Type", "vCPU", "Mem", "Container Disk", "Volume Disk", "$/hr")
		}

		tb := tablewriter.NewWriter(os.Stdout)
		tb.SetHeader(header)
		tb.AppendBulk(data)
		format.TableDefaults(tb)
		tb.Render()
	},
}
View Source
var RemovePodCmd = &cobra.Command{
	Use:   "pod [podId]",
	Args:  cobra.ExactArgs(1),
	Short: "remove a pod",
	Long:  "remove a pod from runpod.io",
	Run: func(cmd *cobra.Command, args []string) {
		_, err := api.RemovePod(args[0])
		cobra.CheckErr(err)

		fmt.Printf(`pod "%s" removed`, args[0])
		fmt.Println()
	},
}
View Source
var StartPodCmd = &cobra.Command{
	Use:   "pod [podId]",
	Args:  cobra.ExactArgs(1),
	Short: "start a pod",
	Long:  "start a pod from runpod.io",
	Run: func(cmd *cobra.Command, args []string) {
		var err error
		var pod map[string]interface{}
		if bidPerGpu > 0 {
			pod, err = api.StartSpotPod(args[0], bidPerGpu)
		} else {
			pod, err = api.StartOnDemandPod(args[0])
		}
		cobra.CheckErr(err)

		if pod["desiredStatus"] == "RUNNING" {
			fmt.Printf(`pod "%s" started with $%.3f / hr`, args[0], pod["costPerHr"])
			fmt.Println()
		} else {
			cobra.CheckErr(fmt.Errorf(`pod "%s" start failed; status is %s`, args[0], pod["desiredStatus"]))
		}
	},
}
View Source
var StopPodCmd = &cobra.Command{
	Use:   "pod [podId]",
	Args:  cobra.ExactArgs(1),
	Short: "stop a pod",
	Long:  "stop a pod from runpod.io",
	Run: func(cmd *cobra.Command, args []string) {
		pod, err := api.StopPod(args[0])
		cobra.CheckErr(err)

		if pod["desiredStatus"] == "EXITED" {
			fmt.Printf(`pod "%s" stopped`, args[0])
		} else {
			fmt.Printf(`pod "%s" stop failed; status is %s`, args[0], pod["desiredStatus"])
		}
		fmt.Println()
	},
}

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