pod

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 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,
			NetworkVolumeId:   networkVolumeId,
		}
		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 {

				var portEntries int = 0
				if p.Runtime != nil && p.Runtime.Ports != nil {
					portEntries = len(p.Runtime.Ports)
				}
				ports := make([]string, portEntries)
				for j := range ports {
					var privpub string = "prv"
					if p.Runtime.Ports[j].IsIpPublic {
						privpub = "pub"
					}
					ports[j] = fmt.Sprintf("%s:%d->%d\u00A0(%s,%s)", p.Runtime.Ports[j].Ip, p.Runtime.Ports[j].PublicPort, p.Runtime.Ports[j].PrivatePort, privpub, p.Runtime.Ports[j].PortType)
				}

				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),
					fmt.Sprintf("%s", strings.Join(ports[:], ",")),
				)
			}
			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", "Ports")
		}

		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