webspace

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2021 License: GPL-3.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExecOptions added in v0.2.1

type ExecOptions struct {
	Command []string `json:"command"`

	User             uint32            `json:"user"`
	Group            uint32            `json:"group"`
	Environment      map[string]string `json:"environment"`
	Width            int               `json:"width"`
	Height           int               `json:"height"`
	WorkingDirectory string            `json:"workingDirectory"`
}

ExecOptions specifies options for executing a command in a webspace

type ExecSession added in v0.2.1

type ExecSession interface {
	IO() io.ReadWriteCloser
	Resize(int, int) error
	Signal(int) error
	Await() (int, error)
	ExitCode() int
}

ExecSession represents an interactive webspace exec session

type Image

type Image struct {
	Aliases     []lxdApi.ImageAlias `json:"aliases"`
	Fingerprint string              `json:"fingerprint"`
	Properties  map[string]string   `json:"properties"`
	Size        int64               `json:"size"`
}

Image represents an LXD image

type InterfaceAddress

type InterfaceAddress struct {
	Family  string `json:"family"`
	Address string `json:"address"`
	Netmask string `json:"netmask"`
	Scope   string `json:"scope"`
}

InterfaceAddress describes a network interface's address

type InterfaceCounters

type InterfaceCounters struct {
	BytesReceived int64 `json:"bytesReceived"`
	BytesSent     int64 `json:"bytesSent"`

	PacketsReceived int64 `json:"packetsReceived"`
	PacketsSent     int64 `json:"packetsSent"`
}

InterfaceCounters describes a network interface's statistics

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager manages webspace containers

func NewManager

func NewManager(cfg *config.Config, iam *iam.APIClient, l lxd.InstanceServer) (*Manager, error)

NewManager returns a new Manager instance

func (*Manager) Create

func (m *Manager) Create(uid int, image string, password string, sshKey string) (*Webspace, error)

Create creates a new webspace container via LXD

func (*Manager) Get

func (m *Manager) Get(uid int, userHint *iam.User) (*Webspace, error)

Get retrieves a Webspace instance from LXD

func (*Manager) GetAll

func (m *Manager) GetAll() ([]*Webspace, error)

GetAll retrieves all the webspaces

func (*Manager) Healthy added in v0.4.0

func (m *Manager) Healthy() bool

Healthy returns true if the manager is healthy

func (*Manager) Images

func (m *Manager) Images() ([]Image, error)

Images gets a list of available images to create webspaces from

func (*Manager) Lock added in v0.4.0

func (m *Manager) Lock(uid int)

Lock locks a webspace

func (*Manager) Shutdown

func (m *Manager) Shutdown(ctx context.Context)

Shutdown stops the webspace manager

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

Start starts the webspace manager

func (*Manager) Unlock added in v0.4.0

func (m *Manager) Unlock(uid int)

Unlock unlocks a webspace

type NetworkInterface

type NetworkInterface struct {
	MAC   string `json:"mac"`
	MTU   int    `json:"mtu"`
	State string `json:"state"`

	Counters  InterfaceCounters  `json:"counters"`
	Addresses []InterfaceAddress `json:"addresses"`
}

NetworkInterface describe's a webspace's network interface

type PortForward

type PortForward struct {
	// contains filtered or unexported fields
}

PortForward represents an active port forwarding

func NewPortForward

func NewPortForward(e uint16, backendAddr *net.TCPAddr, hook PortHook) (*PortForward, error)

NewPortForward creates and starts a port forward

func (*PortForward) Run

func (f *PortForward) Run()

Run starts the port forward

func (*PortForward) Stop

func (f *PortForward) Stop()

Stop shuts down the port forward

type PortHook

type PortHook func(f *PortForward) error

PortHook represents a function to run before connecting to the backend

type PortsManager

type PortsManager struct {
	// contains filtered or unexported fields
}

PortsManager manages TCP port forwarding

func NewPortsManager

func NewPortsManager(cfg *config.Config) (*PortsManager, error)

NewPortsManager creates a new TCP port forward manager

func (*PortsManager) Add

func (p *PortsManager) Add(ctx context.Context, e uint16, backendAddr *net.TCPAddr, hook PortHook) error

Add creates a new port forwarding

func (*PortsManager) AddAll

func (p *PortsManager) AddAll(ctx context.Context, w *Webspace, addr string) error

AddAll adds / updates port forwards for a given webspace

func (*PortsManager) Remove

func (p *PortsManager) Remove(ctx context.Context, e uint16, updateK8s bool) error

Remove stops and removes a port forwarding

func (*PortsManager) Shutdown

func (p *PortsManager) Shutdown(ctx context.Context)

Shutdown stops and removes all port forwards

func (*PortsManager) Trim

func (p *PortsManager) Trim(ctx context.Context, all []*Webspace) error

Trim removes port forwards that have been deleted

type State

type State struct {
	Running           bool                        `json:"running"`
	Uptime            float64                     `json:"uptime"`
	Usage             Usage                       `json:"usage"`
	NetworkInterfaces map[string]NetworkInterface `json:"networkInterfaces"`
}

State describes a webspace's state

type Traefik

type Traefik interface {
	// ClearAll cleans all configuration for all instances
	ClearAll(ctx context.Context) error
	// ClearConfig cleans out any configuration for an instance
	ClearConfig(ctx context.Context, n string) error
	// GenerateConfig generates configuration for an instance
	GenerateConfig(ctx context.Context, ws *Webspace, addr string) error
}

Traefik represents a method of programming Traefik router configuration

func NewTraefikKubernetes

func NewTraefikKubernetes(cfg *config.Config) (Traefik, error)

NewTraefikKubernetes manages webspace configuration for Traefik via Kubernetes resources

func NewTraefikRedis

func NewTraefikRedis(cfg *config.Config) Traefik

NewTraefikRedis creates a new Traefik config manager using Redis

type TraefikKubernetes

type TraefikKubernetes struct {
	// contains filtered or unexported fields
}

TraefikKubernetes manages webspace configuration for Traefik via Kubernetes resources

func (*TraefikKubernetes) ClearAll added in v0.5.0

func (t *TraefikKubernetes) ClearAll(ctx context.Context) error

func (*TraefikKubernetes) ClearConfig

func (t *TraefikKubernetes) ClearConfig(ctx context.Context, n string) error

ClearConfig cleans out any configuration for an instance

func (*TraefikKubernetes) GenerateConfig

func (t *TraefikKubernetes) GenerateConfig(ctx context.Context, ws *Webspace, addr string) error

GenerateConfig generates new Traefik configuration for a webspace

type TraefikRedis

type TraefikRedis struct {
	// contains filtered or unexported fields
}

TraefikRedis manages webspace configuration for Traefik via Redis

func (*TraefikRedis) ClearAll added in v0.5.0

func (t *TraefikRedis) ClearAll(ctx context.Context) error

func (*TraefikRedis) ClearConfig

func (t *TraefikRedis) ClearConfig(ctx context.Context, n string) error

ClearConfig cleans out any configuration for an instance

func (*TraefikRedis) GenerateConfig

func (t *TraefikRedis) GenerateConfig(ctx context.Context, ws *Webspace, addr string) error

GenerateConfig generates new Traefik configuration for a webspace

type Usage

type Usage struct {
	CPU       int64            `json:"cpu"`
	Disks     map[string]int64 `json:"disks"`
	Memory    int64            `json:"memory"`
	Processes int64            `json:"processes"`
}

Usage describes a webspace's resource usage

type Webspace

type Webspace struct {
	UserID  int                   `json:"user"`
	Config  config.WebspaceConfig `json:"config"`
	Domains []string              `json:"domains"`
	Ports   map[uint16]uint16     `json:"ports"`
	// contains filtered or unexported fields
}

Webspace represents a webspace with all of its configuration and state

func (*Webspace) AddDomain

func (w *Webspace) AddDomain(domain string) error

AddDomain verifies and adds a new domain

func (*Webspace) AddPort

func (w *Webspace) AddPort(external uint16, internal uint16) (uint16, error)

AddPort creates a port forwarding

func (*Webspace) AwaitIP

func (w *Webspace) AwaitIP() (string, error)

AwaitIP attempts to retrieve the webspace's IP with exponential backoff

func (*Webspace) Boot

func (w *Webspace) Boot() error

Boot starts the webspace

func (*Webspace) ClearLog added in v0.2.0

func (w *Webspace) ClearLog() error

ClearLog clears the webspace's `/dev/console` log

func (*Webspace) Console added in v0.2.0

func (w *Webspace) Console(width, height int) (io.ReadWriteCloser, func(int, int) error, error)

Console attaches to the webspace's `/dev/console`

func (*Webspace) DefaultDomain added in v0.3.1

func (w *Webspace) DefaultDomain(ctx context.Context) (string, error)

DefaultDomain returns the default domain for the webspace

func (*Webspace) Delete

func (w *Webspace) Delete() error

Delete deletes the webspace

func (*Webspace) EnsureStarted

func (w *Webspace) EnsureStarted() (string, error)

EnsureStarted starts a webspace if it isn't running (delaying by the startup delay) and returns its IP address after

func (*Webspace) Exec added in v0.2.1

func (w *Webspace) Exec(cmd string, ensureBooted bool) (int, string, string, error)

Exec runs a command in a webspace non-interactively

func (*Webspace) ExecInteractive added in v0.2.1

func (w *Webspace) ExecInteractive(opts ExecOptions) (ExecSession, error)

ExecInteractive runs a command in a webspace (with a PTY)

func (*Webspace) GetDomains

func (w *Webspace) GetDomains(ctx context.Context) ([]string, error)

GetDomains gets all domains (including the default one, which can change because of usernames!)

func (*Webspace) GetIP

func (w *Webspace) GetIP(state *lxdApi.InstanceState) (string, error)

GetIP retrieves the webspace's primary IP address

func (*Webspace) GetUser

func (w *Webspace) GetUser(ctx context.Context) (*iam.User, error)

GetUser gets the IAM user associated with this webspace

func (*Webspace) InstanceName

func (w *Webspace) InstanceName() string

InstanceName uses the suffix to calculate the name of the instance

func (*Webspace) Log

func (w *Webspace) Log() (io.ReadCloser, error)

Log returns the webspace's `/dev/console` log

func (*Webspace) Reboot

func (w *Webspace) Reboot() error

Reboot restarts the webspace

func (*Webspace) RemoveDomain

func (w *Webspace) RemoveDomain(ctx context.Context, domain string) error

RemoveDomain removes an existing domain

func (*Webspace) RemovePort

func (w *Webspace) RemovePort(external uint16) error

RemovePort removes a port forwarding

func (*Webspace) Save

func (w *Webspace) Save() error

Save updates the stored LXD configuration

func (*Webspace) Shutdown

func (w *Webspace) Shutdown() error

Shutdown stops the webspace

func (*Webspace) State

func (w *Webspace) State() (State, error)

State returns information about the webspace's state

func (*Webspace) Sync

func (w *Webspace) Sync(ctx context.Context) error

Sync forces configuration for a webspace to be re-generated

Jump to

Keyboard shortcuts

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