Inspect Sandboxes

List sandbox instances in the current workspace, check each sandbox’s lifecycle phase, and fetch detailed properties such as network mode by sandbox ID.

Task flow

Initialize the workspace sandboxes client
                   │
                   ▼
List sandbox IDs, names, and lifecycle phases
                   │
                   ▼
Fetch phase and network_mode details by ID

Prerequisites

  1. Complete the endpoint, personal access token, and workspace setup in Use the SDK.

List sandboxes and inspect details

Use client.sandboxes(workspace_id) (client.Sandboxes(workspaceID) in Go) to call list for all sandboxes in the workspace, then pass a sandbox id to get to read its name, current phase, and network_mode.

import os

import moi_product_sdk as sdk

client = sdk.new_with_personal_access_token(
    os.environ["PRODUCT_API_BASE_URL"],
    os.environ["PRODUCT_API_KEY"],
)
service = client.sandboxes(os.environ["WORKSPACE_ID"])

sandboxes = service.list()
for item in sandboxes:
    print(item.id, item.name, item.phase)
if not sandboxes:
    raise SystemExit("No sandboxes found in the current workspace")

sandbox = service.get(sandboxes[0].id)
print("Detail:", sandbox.id, sandbox.name, sandbox.phase, sandbox.network_mode)
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	sdk "github.com/matrixorigin/matrixflow/sdk/go-sdk"
)

func main() {
	ctx := context.Background()
	client, err := sdk.NewWithPersonalAccessToken(
		os.Getenv("PRODUCT_API_BASE_URL"),
		os.Getenv("PRODUCT_API_KEY"),
	)
	if err != nil {
		log.Fatal(err)
	}
	defer client.Close()

	service := client.Sandboxes(os.Getenv("WORKSPACE_ID"))
	sandboxes, err := service.List(ctx)
	if err != nil {
		log.Fatal(err)
	}
	for _, item := range sandboxes {
		fmt.Println(item.GetId(), item.GetName(), item.GetPhase())
	}
	if len(sandboxes) == 0 {
		fmt.Println("No sandboxes found in the current workspace")
		return
	}

	sandbox, err := service.Get(ctx, sandboxes[0].GetId())
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Detail:", sandbox.GetId(), sandbox.GetName(), sandbox.GetPhase(), sandbox.GetNetworkMode())
}

Next steps

Last updated on