list

package
v1.8.5 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2020 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &command.Command{
	Cobra: &cobra.Command{
		Args:         cobra.NoArgs,
		Use:          "list",
		Short:        "list triton packages",
		Aliases:      []string{"ls"},
		SilenceUsage: true,
		Example: `
$ triton package list
$ triton package ls
$ triton package list --disk=102400
$ triton package list --memory=8192
$ triton package list --vpcu=4
`,
		PreRunE: func(cmd *cobra.Command, args []string) error {
			return nil
		},
		RunE: func(cmd *cobra.Command, args []string) error {
			cons := conswriter.GetTerminal()

			c, err := cfg.NewTritonConfig()
			if err != nil {
				return err
			}

			a, err := compute.NewComputeClient(c)
			if err != nil {
				return err
			}

			packages, err := a.GetPackagesList()
			if err != nil {
				return err
			}

			table := tablewriter.NewWriter(cons)
			table.SetHeaderAlignment(tablewriter.ALIGN_CENTER)
			table.SetHeaderLine(false)
			table.SetAutoFormatHeaders(true)

			table.SetColumnAlignment([]int{tablewriter.ALIGN_LEFT, tablewriter.ALIGN_LEFT, tablewriter.ALIGN_LEFT, tablewriter.ALIGN_LEFT, tablewriter.ALIGN_LEFT, tablewriter.ALIGN_LEFT})
			table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
			table.SetCenterSeparator("")
			table.SetColumnSeparator("")
			table.SetRowSeparator("")

			table.SetHeader([]string{"SHORTID", "NAME", "MEMORY", "SWAP", "DISK", "VCPUS"})

			for _, pkg := range packages {
				table.Append([]string{string(pkg.ID[:8]), pkg.Name, humanize.Bytes(uint64(pkg.Memory * 1000 * 1000)), humanize.Bytes(uint64(pkg.Swap * 1000 * 1000)), humanize.Bytes(uint64(pkg.Disk * 1000 * 1000)), parseVPCs(pkg.VCPUs)})
			}

			table.Render()

			return nil
		},
	},
	Setup: func(parent *command.Command) error {
		{
			const (
				key          = config.KeyPackageMemory
				longName     = "memory"
				defaultValue = ""
				description  = "Package Memory (in MiB)"
			)

			flags := parent.Cobra.Flags()
			flags.String(longName, defaultValue, description)
			viper.BindPFlag(key, flags.Lookup(longName))
		}

		{
			const (
				key          = config.KeyPackageDisk
				longName     = "disk"
				defaultValue = ""
				description  = "Package Disk (in MiB)"
			)

			flags := parent.Cobra.Flags()
			flags.String(longName, defaultValue, description)
			viper.BindPFlag(key, flags.Lookup(longName))
		}

		{
			const (
				key          = config.KeyPackageSwap
				longName     = "swap"
				defaultValue = ""
				description  = "Package Swap(in MiB)"
			)

			flags := parent.Cobra.Flags()
			flags.String(longName, defaultValue, description)
			viper.BindPFlag(key, flags.Lookup(longName))
		}

		{
			const (
				key          = config.KeyPackageVPCUs
				longName     = "vcpu"
				defaultValue = ""
				description  = "Package VCPUs"
			)

			flags := parent.Cobra.Flags()
			flags.String(longName, defaultValue, description)
			viper.BindPFlag(key, flags.Lookup(longName))
		}

		return nil
	},
}

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