instance

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder interface {
	BuildInstanceVM(ctx context.Context, instance *Instance) (VM, error)
	RecoverInstanceVM(ctx context.Context, instance *Instance) (VM, error)
	CleanupInstanceVM(ctx context.Context, instance *Instance) error
	CleanupInstance(ctx context.Context, instance *Instance) error
}

type ExitResult

type ExitResult struct {
	Success   bool      `json:"success"`
	ExitCode  int       `json:"exit_code,omitempty"`
	Requested bool      `json:"requested"`
	ExitedAt  time.Time `json:"exited_at"`
}

type Handle

type Handle struct {
	Console string
}

type Instance

type Instance struct {
	Id        string           `json:"id"`
	Metadata  InstanceMetadata `json:"metadata"`
	Config    InstanceConfig   `json:"config"`
	ImageRef  string           `json:"image_ref"`
	Network   NetworkingConfig `json:"network"`
	State     State            `json:"state"`
	CreatedAt time.Time        `json:"created_at"`
}

type InstanceConfig

type InstanceConfig struct {
	Image string              `json:"image"`
	Guest InstanceGuestConfig `json:"guest"`
	Init  api.InitConfig      `json:"init"`
	Stop  *api.StopConfig     `json:"stop,omitempty"`
	Env   []string            `json:"env"`
}

type InstanceGuestConfig

type InstanceGuestConfig struct {
	MemoryMB int `json:"memory_mb" minimum:"1"` // in MB
	VCpus    int `json:"vcpus" minimum:"1"`     // number of virtual CPUs (correspond to vm vcpus)
	CpusMHz  int `json:"cpus_mhz" minimum:"1"`  // in MHz
}

type InstanceMetadata

type InstanceMetadata struct {
	MachineId      string `json:"machine_id"`
	MachineVersion string `json:"machine_version"`
}

type InstanceNetwork

type InstanceNetwork struct {
	Network    networking.Network `json:"network"`
	InstanceIP net.IP             `json:"instance_ip"`
	HostIP     net.IP             `json:"host_ip"`
	Gateway    net.IP             `json:"gateway"`
	Broadcast  net.IP             `json:"broadcast"`
}

func GetLocalNetwork

func GetLocalNetwork(netw networking.Network) InstanceNetwork

func (*InstanceNetwork) HostIPNet

func (i *InstanceNetwork) HostIPNet() *net.IPNet

func (*InstanceNetwork) InstanceIPNet

func (i *InstanceNetwork) InstanceIPNet() *net.IPNet

func (*InstanceNetwork) MarshalJSON

func (i *InstanceNetwork) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*InstanceNetwork) UnmarshalJSON

func (i *InstanceNetwork) UnmarshalJSON(bytes []byte) error

UnmarshalJSON implements json.Unmarshaler.

type InstanceOptions

type InstanceOptions struct {
	Id       string           `json:"id"`
	Metadata InstanceMetadata `json:"metadata"`
	Config   InstanceConfig   `json:"config"`
}

type InstanceStatus

type InstanceStatus = string
const (
	InstanceStatusCreated    InstanceStatus = "created"
	InstanceStatusStopped    InstanceStatus = "stopped"
	InstanceStatusStarting   InstanceStatus = "starting"
	InstanceStatusRunning    InstanceStatus = "running"
	InstanceStatusDestroying InstanceStatus = "destroying"
	InstanceStatusDestroyed  InstanceStatus = "destroyed"
)

type InstanceStore

type InstanceStore interface {
	LoadInstances() ([]Instance, error)
	PutInstance(instance Instance) error
	DeleteInstance(id string) error
}

type NetworkingConfig

type NetworkingConfig struct {
	TapDevice      string          `json:"tap_device"`
	Local          InstanceNetwork `json:"local"`
	DefaultGateway net.IP          `json:"default_gateway"`
}

func (*NetworkingConfig) MarshalJSON

func (n *NetworkingConfig) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*NetworkingConfig) UnmarshalJSON

func (n *NetworkingConfig) UnmarshalJSON(bytes []byte) error

UnmarshalJSON implements json.Unmarshaler.

type NetworkingService

type NetworkingService interface {
	EnsureInstanceNetwork(id string, config NetworkingConfig) error
	CleanupInstanceNetwork(id string, config NetworkingConfig) error
}

type State

type State struct {
	Status     InstanceStatus `json:"status"`
	Stopping   bool           `json:"stopping"`
	ExitResult *ExitResult    `json:"exit_result,omitempty"`
}

type VM

type VM interface {
	Start(ctx context.Context) error
	Exec(ctx context.Context, cmd []string, timeout time.Duration) (*api.ExecResult, error)
	Run() ExitResult
	WaitExit(ctx context.Context) bool
	Signal(ctx context.Context, signal string) error
	Stop(ctx context.Context, signal string) error
	Shutdown(ctx context.Context) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL