Documentation
¶
Index ¶
- Variables
- type Event
- type EventBus
- type EventType
- type ExecRequest
- type ExecResult
- type FileChmodRequest
- type FileDeleteRequest
- type FileInfo
- type FileMoveRequest
- type FileWriteRequest
- type Manager
- func (m *Manager) ChmodFile(ctx context.Context, sandboxID string, req FileChmodRequest) error
- func (m *Manager) ConsoleLog(ctx context.Context, sandboxID string, lines int) ([]string, error)
- func (m *Manager) CountByProvider(_ context.Context, provider string) int
- func (m *Manager) DeleteFile(ctx context.Context, sandboxID string, req FileDeleteRequest) error
- func (m *Manager) Destroy(ctx context.Context, id string) error
- func (m *Manager) Exec(ctx context.Context, sandboxID string, req ExecRequest) (*ExecResult, error)
- func (m *Manager) ExecStream(ctx context.Context, sandboxID string, req ExecRequest) (<-chan providers.StreamChunk, error)
- func (m *Manager) ExtendTTL(ctx context.Context, id string, extra time.Duration) (*Sandbox, error)
- func (m *Manager) Get(ctx context.Context, id string) (*Sandbox, error)
- func (m *Manager) GlobFiles(ctx context.Context, sandboxID string, pattern string) ([]string, error)
- func (m *Manager) InitVMPool()
- func (m *Manager) List(ctx context.Context) ([]*Sandbox, error)
- func (m *Manager) ListFiles(ctx context.Context, sandboxID string, path string) ([]FileInfo, error)
- func (m *Manager) MoveFile(ctx context.Context, sandboxID string, req FileMoveRequest) error
- func (m *Manager) Prune(ctx context.Context) (int, error)
- func (m *Manager) ReadFile(ctx context.Context, sandboxID string, path string) ([]byte, error)
- func (m *Manager) Spawn(ctx context.Context, req SpawnRequest) (*Sandbox, error)
- func (m *Manager) Start()
- func (m *Manager) StatFile(ctx context.Context, sandboxID string, path string) (*FileInfo, error)
- func (m *Manager) Stop()
- func (m *Manager) VMPoolStatus() *VMPoolStatus
- func (m *Manager) WriteFile(ctx context.Context, sandboxID string, req FileWriteRequest) error
- type ManagerConfig
- type PoolManager
- type PoolStatus
- type Sandbox
- type SandboxInfo
- type SandboxState
- type SecretConfig
- type SpawnRequest
- type Template
- type TemplateRegistry
- func (r *TemplateRegistry) Create(ctx context.Context, t *Template) error
- func (r *TemplateRegistry) Delete(ctx context.Context, name string) error
- func (r *TemplateRegistry) Get(ctx context.Context, name string) (*Template, error)
- func (r *TemplateRegistry) List(ctx context.Context) ([]*Template, error)
- func (r *TemplateRegistry) ToSpawnRequest(t *Template) SpawnRequest
- func (r *TemplateRegistry) Update(ctx context.Context, t *Template) error
- type VMPoolManager
- type VMPoolStatus
- type VMSlot
Constants ¶
This section is empty.
Variables ¶
var ErrVMPoolFull = errors.New("vm pool at capacity")
ErrVMPoolFull is returned when the VM pool is at capacity and overflow is "reject".
Functions ¶
This section is empty.
Types ¶
type EventBus ¶
type EventBus struct {
// contains filtered or unexported fields
}
EventBus is an in-process pub/sub system with ring buffer history.
func NewEventBus ¶
func NewEventBus() *EventBus
func (*EventBus) Subscribe ¶
Subscribe creates a new subscription and returns a channel + unsubscribe key.
func (*EventBus) Unsubscribe ¶
Unsubscribe removes a subscription.
type EventType ¶
type EventType string
const ( EventSandboxCreated EventType = "sandbox.created" EventSandboxRunning EventType = "sandbox.running" EventSandboxDestroyed EventType = "sandbox.destroyed" EventSandboxError EventType = "sandbox.error" EventExecStarted EventType = "exec.started" EventExecCompleted EventType = "exec.completed" EventFileWritten EventType = "file.written" EventFileRead EventType = "file.read" )
type ExecRequest ¶
type ExecResult ¶
type FileChmodRequest ¶
type FileDeleteRequest ¶
type FileMoveRequest ¶
type FileWriteRequest ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func NewManager ¶
func (*Manager) ConsoleLog ¶
func (*Manager) CountByProvider ¶
func (*Manager) DeleteFile ¶
func (*Manager) Exec ¶
func (m *Manager) Exec(ctx context.Context, sandboxID string, req ExecRequest) (*ExecResult, error)
func (*Manager) ExecStream ¶
func (m *Manager) ExecStream(ctx context.Context, sandboxID string, req ExecRequest) (<-chan providers.StreamChunk, error)
func (*Manager) InitVMPool ¶
func (m *Manager) InitVMPool()
InitVMPool initializes the VM pool manager if pool mode is enabled.
func (*Manager) VMPoolStatus ¶
func (m *Manager) VMPoolStatus() *VMPoolStatus
VMPoolStatus returns the current VM pool status. Returns nil if pool is disabled.
type ManagerConfig ¶
type PoolManager ¶
type PoolManager struct {
// contains filtered or unexported fields
}
PoolManager maintains pre-warmed sandbox pools per template.
func NewPoolManager ¶
func NewPoolManager(mgr *Manager, registry *TemplateRegistry, logger zerolog.Logger) *PoolManager
func (*PoolManager) Acquire ¶
func (pm *PoolManager) Acquire(templateName string) string
Acquire takes a pre-warmed sandbox from the pool. Returns empty string if none available.
func (*PoolManager) Configure ¶
func (pm *PoolManager) Configure(templateName string, size int)
Configure sets the pool size for a template.
func (*PoolManager) Start ¶
func (pm *PoolManager) Start()
Start begins the background refill goroutine.
func (*PoolManager) Status ¶
func (pm *PoolManager) Status() map[string]PoolStatus
Status returns pool stats for all templates.
type PoolStatus ¶
type PoolStatus struct {
TemplateName string `json:"template_name"`
TargetSize int `json:"target_size"`
CurrentSize int `json:"current_size"`
}
PoolStatus represents the state of a template's pool.
type Sandbox ¶
type Sandbox struct {
ID string `json:"id"`
State SandboxState `json:"state"`
Provider string `json:"provider"`
Image string `json:"image"`
MemoryMB int `json:"memory_mb"`
VCPUs int `json:"vcpus"`
OwnerID string `json:"owner_id,omitempty"`
VMID string `json:"vm_id,omitempty"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt time.Time `json:"expires_at"`
Metadata map[string]string `json:"metadata,omitempty"`
}
type SandboxInfo ¶
type SandboxInfo struct {
ID string `json:"id"`
State SandboxState `json:"state"`
Provider string `json:"provider"`
Image string `json:"image"`
MemoryMB int `json:"memory_mb"`
VCPUs int `json:"vcpus"`
CreatedAt string `json:"created_at"`
ExpiresAt string `json:"expires_at"`
Metadata map[string]string `json:"metadata,omitempty"`
ExecCount int `json:"exec_count"`
FileCount int `json:"file_count"`
}
type SandboxState ¶
type SandboxState string
const ( StateCreating SandboxState = "creating" StateRunning SandboxState = "running" StateIdle SandboxState = "idle" StateDestroyed SandboxState = "destroyed" StateError SandboxState = "error" )
type SecretConfig ¶
type SecretConfig struct {
Name string `json:"name" yaml:"name"`
InjectAt string `json:"inject_at" yaml:"inject_at"`
}
SecretConfig defines a secret to inject into a sandbox.
type SpawnRequest ¶
type SpawnRequest struct {
Image string `json:"image"`
Provider string `json:"provider,omitempty"`
MemoryMB int `json:"memory_mb,omitempty"`
VCPUs int `json:"vcpus,omitempty"`
TTL string `json:"ttl,omitempty"`
Template string `json:"template,omitempty"`
OwnerID string `json:"owner_id,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
type Template ¶
type Template struct {
Name string `json:"name" yaml:"name"`
Version int `json:"version" yaml:"version"`
Image string `json:"image" yaml:"image"`
Description string `json:"description,omitempty" yaml:"description"`
Setup []string `json:"setup,omitempty" yaml:"setup"`
AllowedHosts []string `json:"allowed_hosts,omitempty" yaml:"allowed_hosts"`
MemoryMB int `json:"memory_mb" yaml:"memory_mb"`
CPUCores int `json:"cpu_cores" yaml:"cpu_cores"`
TTLSeconds int `json:"ttl_seconds" yaml:"ttl_seconds"`
Env map[string]string `json:"env,omitempty" yaml:"env"`
Secrets []SecretConfig `json:"secrets,omitempty" yaml:"secrets"`
PoolSize int `json:"pool_size" yaml:"pool_size"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Template represents a reusable sandbox configuration.
type TemplateRegistry ¶
type TemplateRegistry struct {
// contains filtered or unexported fields
}
TemplateRegistry manages sandbox templates via the store.
func NewTemplateRegistry ¶
func NewTemplateRegistry(st store.Store) *TemplateRegistry
func (*TemplateRegistry) Create ¶
func (r *TemplateRegistry) Create(ctx context.Context, t *Template) error
func (*TemplateRegistry) Delete ¶
func (r *TemplateRegistry) Delete(ctx context.Context, name string) error
func (*TemplateRegistry) List ¶
func (r *TemplateRegistry) List(ctx context.Context) ([]*Template, error)
func (*TemplateRegistry) ToSpawnRequest ¶
func (r *TemplateRegistry) ToSpawnRequest(t *Template) SpawnRequest
ToSpawnRequest converts a template into a SpawnRequest.
type VMPoolManager ¶
type VMPoolManager struct {
// contains filtered or unexported fields
}
VMPoolManager handles multi-user VM pool scheduling.
func NewVMPoolManager ¶
func NewVMPoolManager(cfg config.PoolConfig, spawnFn func(ctx context.Context, req SpawnRequest) (*Sandbox, error), logger zerolog.Logger) *VMPoolManager
NewVMPoolManager creates a VM pool manager. The spawnFn is called to create new VMs.
func (*VMPoolManager) Release ¶
func (p *VMPoolManager) Release(vmID, sandboxID string) bool
Release decrements the user count for a VM. Returns true if the VM is now empty and should be destroyed.
func (*VMPoolManager) Status ¶
func (p *VMPoolManager) Status() VMPoolStatus
Status returns the current pool status.