Skip to content

Commit 5eb3f99

Browse files
lakebox: add stop command (#5291)
Wires up `databricks lakebox stop <id>` against the existing StopSandbox proto RPC (POST /api/2.0/lakebox/sandboxes/{id}/stop). Terminates the backing microVM, preserves the sandbox record and storage. The gateway auto-starts a stopped sandbox on the next `lakebox ssh`, so a paired `start` command isn't required today. Co-authored-by: Isaac ## Changes <!-- Brief summary of your changes that is easy to understand --> ## Why <!-- Why are these changes needed? Provide the context that the reviewer might be missing. For example, were there any decisions behind the change that are not reflected in the code itself? --> ## Tests <!-- How have you tested the changes? --> <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent 4714f92 commit 5eb3f99

3 files changed

Lines changed: 66 additions & 0 deletions

File tree

cmd/lakebox/api.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,20 @@ func (a *lakeboxAPI) delete(ctx context.Context, id string) error {
288288
return a.c.Do(ctx, http.MethodDelete, lakeboxAPIPath+"/"+id, a.headers(), nil, nil, nil)
289289
}
290290

291+
// stop calls POST /api/2.0/lakebox/sandboxes/{id}/stop and returns the
292+
// refreshed sandbox. The proto's `StopSandboxRequest` carries `sandbox_id`
293+
// (redundant with the URL path) under `body: "*"`, so we mirror it
294+
// explicitly even though the transcoder fills the field from the path.
295+
func (a *lakeboxAPI) stop(ctx context.Context, id string) (*sandboxEntry, error) {
296+
body := map[string]string{"sandbox_id": id}
297+
var resp sandboxEntry
298+
err := a.c.Do(ctx, http.MethodPost, lakeboxAPIPath+"/"+id+"/stop", a.headers(), nil, body, &resp)
299+
if err != nil {
300+
return nil, err
301+
}
302+
return &resp, nil
303+
}
304+
291305
// registerKey calls POST /api/2.0/lakebox/ssh-keys. An empty `name` is
292306
// omitted from the wire payload so the server records "unset" rather than
293307
// an explicit empty string.

cmd/lakebox/lakebox.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Common workflows:
3838
cmd.AddCommand(newListCommand())
3939
cmd.AddCommand(newCreateCommand())
4040
cmd.AddCommand(newDeleteCommand())
41+
cmd.AddCommand(newStopCommand())
4142
cmd.AddCommand(newStatusCommand())
4243
cmd.AddCommand(newConfigCommand())
4344

cmd/lakebox/stop.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package lakebox
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/databricks/cli/cmd/root"
7+
"github.com/databricks/cli/libs/cmdctx"
8+
"github.com/databricks/cli/libs/cmdio"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
func newStopCommand() *cobra.Command {
13+
cmd := &cobra.Command{
14+
Use: "stop <lakebox-id>",
15+
Short: "Stop a running Lakebox environment",
16+
Long: `Stop a running Lakebox environment.
17+
18+
Terminates the backing microVM but preserves the sandbox record and its
19+
persistent storage. To restart, run 'databricks lakebox ssh' — the
20+
gateway auto-starts a stopped sandbox on connection.
21+
22+
Stopping an already-stopped sandbox is a no-op.
23+
24+
Example:
25+
databricks lakebox stop happy-panda-1234`,
26+
Args: cobra.ExactArgs(1),
27+
PreRunE: root.MustWorkspaceClient,
28+
RunE: func(cmd *cobra.Command, args []string) error {
29+
ctx := cmd.Context()
30+
w := cmdctx.WorkspaceClient(ctx)
31+
api, err := newLakeboxAPI(w)
32+
if err != nil {
33+
return err
34+
}
35+
36+
lakeboxID := args[0]
37+
s := spin(ctx, "Stopping "+lakeboxID+"…")
38+
defer s.Close()
39+
40+
updated, err := api.stop(ctx, lakeboxID)
41+
if err != nil {
42+
s.fail("Failed to stop " + lakeboxID)
43+
return fmt.Errorf("failed to stop lakebox %s: %w", lakeboxID, err)
44+
}
45+
s.ok("Stopped " + cmdio.Bold(ctx, updated.SandboxID))
46+
return nil
47+
},
48+
}
49+
50+
return cmd
51+
}

0 commit comments

Comments
 (0)