pods

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: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CreatePodsCmd = &cobra.Command{
	Use:   "pods",
	Args:  cobra.ExactArgs(0),
	Short: "create a group of pods",
	Long:  "create a group of pods on runpod.io",
	Run: func(cmd *cobra.Command, args []string) {
		gpus := strings.Split(gpuTypeId, ",")
		gpusIndex := 0
		input := &api.CreatePodInput{
			ContainerDiskInGb: containerDiskInGb,
			DeployCost:        deployCost,
			DockerArgs:        dockerArgs,
			GpuCount:          gpuCount,
			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"
		}

		for x := 0; x < podCount; x++ {
			input.GpuTypeId = gpus[gpusIndex]
			pod, err := api.CreatePod(input)
			if err != nil && len(gpus) > gpusIndex+1 && strings.Contains(err.Error(), "no longer any instances available") {
				gpusIndex++
				x--
				continue
			}
			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 RemovePodsCmd = &cobra.Command{
	Use:   "pods [name]",
	Args:  cobra.ExactArgs(1),
	Short: "remove all pods using name",
	Long:  "remove all pods using name from runpod.io",
	Run: func(cmd *cobra.Command, args []string) {
		mypods, err := api.GetPods()
		cobra.CheckErr(err)

		removed := 0
		for _, pod := range mypods {
			if pod.Name == args[0] && removed < podCount {
				_, err := api.RemovePod(pod.Id)
				if err == nil {
					removed++
				}
				cobra.CheckErr(err)
			}
		}

		fmt.Printf(`%d pods removed with name "%s"`, removed, args[0])
		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