Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cmd/lakebox/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,20 @@ func (a *lakeboxAPI) delete(ctx context.Context, id string) error {
return a.c.Do(ctx, http.MethodDelete, lakeboxAPIPath+"/"+id, a.headers(), nil, nil, nil)
}

// stop calls POST /api/2.0/lakebox/sandboxes/{id}/stop and returns the
// refreshed sandbox. The proto's `StopSandboxRequest` carries `sandbox_id`
// (redundant with the URL path) under `body: "*"`, so we mirror it
// explicitly even though the transcoder fills the field from the path.
func (a *lakeboxAPI) stop(ctx context.Context, id string) (*sandboxEntry, error) {
body := map[string]string{"sandbox_id": id}
var resp sandboxEntry
err := a.c.Do(ctx, http.MethodPost, lakeboxAPIPath+"/"+id+"/stop", a.headers(), nil, body, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}

// registerKey calls POST /api/2.0/lakebox/ssh-keys. An empty `name` is
// omitted from the wire payload so the server records "unset" rather than
// an explicit empty string.
Expand Down
1 change: 1 addition & 0 deletions cmd/lakebox/lakebox.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Common workflows:
cmd.AddCommand(newListCommand())
cmd.AddCommand(newCreateCommand())
cmd.AddCommand(newDeleteCommand())
cmd.AddCommand(newStopCommand())
cmd.AddCommand(newStatusCommand())
cmd.AddCommand(newConfigCommand())

Expand Down
51 changes: 51 additions & 0 deletions cmd/lakebox/stop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package lakebox

import (
"fmt"

"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/cmdctx"
"github.com/databricks/cli/libs/cmdio"
"github.com/spf13/cobra"
)

func newStopCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "stop <lakebox-id>",
Short: "Stop a running Lakebox environment",
Long: `Stop a running Lakebox environment.

Terminates the backing microVM but preserves the sandbox record and its
persistent storage. To restart, run 'databricks lakebox ssh' — the
gateway auto-starts a stopped sandbox on connection.

Stopping an already-stopped sandbox is a no-op.

Example:
databricks lakebox stop happy-panda-1234`,
Args: cobra.ExactArgs(1),
PreRunE: root.MustWorkspaceClient,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
w := cmdctx.WorkspaceClient(ctx)
api, err := newLakeboxAPI(w)
if err != nil {
return err
}

lakeboxID := args[0]
s := spin(ctx, "Stopping "+lakeboxID+"…")
defer s.Close()

updated, err := api.stop(ctx, lakeboxID)
if err != nil {
s.fail("Failed to stop " + lakeboxID)
return fmt.Errorf("failed to stop lakebox %s: %w", lakeboxID, err)
}
s.ok("Stopped " + cmdio.Bold(ctx, updated.SandboxID))
return nil
},
}

return cmd
}
Loading