command_pool

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DeleteCmd = &cli.Command{
	Name:        "delete",
	Usage:       "Delete a pool",
	Description: "Delete a stopped pool and all its member spaces.",
	Arguments: []cli.Argument{
		&cli.StringArg{
			Name:     "pool",
			Usage:    "The name or ID of the pool to delete",
			Required: true,
		},
	},
	Flags: []cli.Flag{
		&cli.BoolFlag{
			Name:    "yes",
			Aliases: []string{"y"},
			Usage:   "Skip confirmation prompt.",
		},
	},
	MaxArgs: cli.NoArgs,
	Run: func(ctx context.Context, cmd *cli.Command) error {
		poolName := cmd.GetStringArg("pool")

		if !cmd.GetBool("yes") {
			fmt.Printf("Delete pool %q and all its spaces? [y/N] ", poolName)
			var resp string
			fmt.Scanln(&resp)
			if resp != "y" && resp != "Y" && resp != "yes" {
				fmt.Println("Cancelled.")
				return nil
			}
		}

		client, err := cmdutil.GetClient(cmd)
		if err != nil {
			return fmt.Errorf("Failed to create API client: %w", err)
		}

		code, err := client.DeletePool(context.Background(), poolName)
		if err != nil {
			return fmt.Errorf("Error deleting pool: %w (code %d)", err, code)
		}

		fmt.Fprintln(os.Stderr, "Pool deleted:", poolName)
		return nil
	},
}
View Source
var ListCmd = &cli.Command{
	Name:        "list",
	Usage:       "List your pools",
	Description: "Lists all pools you own with their status and member count.",
	MaxArgs:     cli.NoArgs,
	Run: func(ctx context.Context, cmd *cli.Command) error {
		client, err := cmdutil.GetClient(cmd)
		if err != nil {
			fmt.Println("Failed to create API client:", err)
			os.Exit(1)
		}

		pools, code, err := client.GetPools(context.Background())
		if err != nil {
			if code == 404 {
				fmt.Println("No pools found.")
				return nil
			}
			return fmt.Errorf("Error listing pools: %w", err)
		}

		if len(pools.Pools) == 0 {
			fmt.Println("No pools found.")
			return nil
		}

		w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
		fmt.Fprintln(w, "NAME\tSTATE\tALIVE/DESIRED\tTEMPLATE")
		for _, p := range pools.Pools {
			state := "stopped"
			if p.Active {
				state = "active"
			}
			fmt.Fprintf(w, "%s\t%s\t%d/%d\t%s\n", p.Name, state, p.AliveMembers, p.DesiredCount, p.TemplateId)
		}
		w.Flush()
		return nil
	},
}
View Source
var PoolCmd = &cli.Command{
	Name:        "pool",
	Usage:       "Manage space pools",
	Description: "Manage your space pools from the command line.",
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:    "server",
			Aliases: []string{"s"},
			Usage:   "The address of the remote server to manage pools on.",
			EnvVars: []string{config.CONFIG_ENV_PREFIX + "_SERVER"},
			Global:  true,
		},
		&cli.StringFlag{
			Name:    "token",
			Aliases: []string{"t"},
			Usage:   "The token to use for authentication.",
			EnvVars: []string{config.CONFIG_ENV_PREFIX + "_TOKEN"},
			Global:  true,
		},
		&cli.BoolFlag{
			Name:         "tls-skip-verify",
			Usage:        "Skip TLS verification when talking to server.",
			ConfigPath:   []string{"tls.skip_verify"},
			EnvVars:      []string{config.CONFIG_ENV_PREFIX + "_TLS_SKIP_VERIFY"},
			DefaultValue: true,
			Global:       true,
		},
		&cli.StringFlag{
			Name:         "alias",
			Aliases:      []string{"a"},
			Usage:        "The server alias to use.",
			DefaultValue: "default",
			Global:       true,
		},
	},
	Commands: []*cli.Command{
		ListCmd,
		StartCmd,
		StopCmd,
		DeleteCmd,
		SetSizeCmd,
	},
}
View Source
var SetSizeCmd = &cli.Command{
	Name:        "set-size",
	Usage:       "Set the desired space count for a pool",
	Description: "Update the target number of spaces for a pool. The sweep loop handles creating or removing members.",
	Arguments: []cli.Argument{
		&cli.StringArg{
			Name:     "pool",
			Usage:    "The name or ID of the pool",
			Required: true,
		},
		&cli.IntArg{
			Name:     "count",
			Usage:    "The desired number of spaces (minimum 1)",
			Required: true,
		},
	},
	MaxArgs: cli.NoArgs,
	Run: func(ctx context.Context, cmd *cli.Command) error {
		poolName := cmd.GetStringArg("pool")
		desired := cmd.GetIntArg("count")

		if desired < 1 {
			return fmt.Errorf("count must be at least 1")
		}

		fmt.Printf("Setting pool %q size to %d...\n", poolName, desired)

		client, err := cmdutil.GetClient(cmd)
		if err != nil {
			return fmt.Errorf("Failed to create API client: %w", err)
		}

		code, err := client.SetPoolSize(context.Background(), poolName, desired)
		if err != nil {
			return fmt.Errorf("Error setting pool size: %w (code %d)", err, code)
		}

		fmt.Printf("Pool %q size set to %d.\n", poolName, desired)
		return nil
	},
}
View Source
var StartCmd = &cli.Command{
	Name:        "start",
	Usage:       "Start a pool",
	Description: "Start a stopped pool and all its member spaces.",
	Arguments: []cli.Argument{
		&cli.StringArg{
			Name:     "pool",
			Usage:    "The name or ID of the pool to start",
			Required: true,
		},
	},
	MaxArgs: cli.NoArgs,
	Run: func(ctx context.Context, cmd *cli.Command) error {
		poolName := cmd.GetStringArg("pool")
		fmt.Println("Starting pool:", poolName)

		client, err := cmdutil.GetClient(cmd)
		if err != nil {
			return fmt.Errorf("Failed to create API client: %w", err)
		}

		code, err := client.StartPool(context.Background(), poolName)
		if err != nil {
			return fmt.Errorf("Error starting pool: %w (code %d)", err, code)
		}

		fmt.Println("Pool started:", poolName)
		return nil
	},
}
View Source
var StopCmd = &cli.Command{
	Name:        "stop",
	Usage:       "Stop a pool",
	Description: "Stop a running pool and all its member spaces without deleting them.",
	Arguments: []cli.Argument{
		&cli.StringArg{
			Name:     "pool",
			Usage:    "The name or ID of the pool to stop",
			Required: true,
		},
	},
	MaxArgs: cli.NoArgs,
	Run: func(ctx context.Context, cmd *cli.Command) error {
		poolName := cmd.GetStringArg("pool")
		fmt.Println("Stopping pool:", poolName)

		client, err := cmdutil.GetClient(cmd)
		if err != nil {
			return fmt.Errorf("Failed to create API client: %w", err)
		}

		code, err := client.StopPool(context.Background(), poolName)
		if err != nil {
			return fmt.Errorf("Error stopping pool: %w (code %d)", err, code)
		}

		fmt.Println("Pool stopped:", poolName)
		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