virtual

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoVPN      = 0
	OnlyVPN    = 1
	VPNBrowser = 2
)
View Source
const (
	Running   = State(0)
	Stopped   = State(1)
	Suspended = State(2)
	Error     = State(3)
)
View Source
const (
	NOAVAILABLEFRONTEND = "No available frontends found on your setup, please add at least one ova file !"
)

Variables

View Source
var (
	DefaultClient     *docker.Client
	DefaultLinkBridge *defaultBridge

	TooLowMemErr              = errors.New("memory needs to be atleast 50mb")
	InvalidHostBindingErr     = errors.New("hostbing does not have correct format - (ip:)port")
	InvalidMountErr           = errors.New("incorrect mount format - src:dest")
	NoRegistriesToPullFromErr = errors.New("no registries to pull from")
	NoImageErr                = errors.New("unable to find image")
	EmptyDigestErr            = errors.New("empty digest")
	DigestFormatErr           = errors.New("unexpected digest format")
	NoRemoteDigestErr         = errors.New("unable to get digest from remote image")
	NoAvailableIPsErr         = errors.New("no available IPs")
	UnexpectedIPErr           = errors.New("unexpected IP range")
	ContNotCreatedErr         = errors.New("container is not created")

	Registries = map[string]docker.AuthConfiguration{
		"": {},
	}
)
View Source
var FileTransferRoot string

Functions

func CreateEventFolder

func CreateEventFolder(tag string) error

func CreateFileTransferRoot

func CreateFileTransferRoot(path string) error
func CreateFolderLink(vm string, envTag string, guacUsername string) error

func CreateUserFolder

func CreateUserFolder(teamId string, eventTag string) error

func GetAvailablePort

func GetAvailablePort() uint

func GetContainerCount

func GetContainerCount() (uint32, error)

Gets the count of all containers running

func GetRunningVmCount

func GetRunningVmCount() (uint32, error)

Gets the count of running Virtual machines

func RemoveEventFolder

func RemoveEventFolder(eventTag string) error

func VBoxCmdContext

func VBoxCmdContext(ctx context.Context, cmd string, cmds ...string) ([]byte, error)

Types

type Container

type Container struct {
	Id      string
	Conf    ContainerConfig
	Network *docker.Network
	Linked  []*Container
}

func NewContainer

func NewContainer(conf ContainerConfig) *Container

func (*Container) BridgeAlias

func (c *Container) BridgeAlias(alias string) (string, error)

func (*Container) Close

func (c *Container) Close() error

func (*Container) Create

func (c *Container) Create(ctx context.Context) error

func (*Container) Info

func (c *Container) Info() InstanceInfo

func (*Container) Run

func (c *Container) Run(ctx context.Context) error

func (*Container) Start

func (c *Container) Start(ctx context.Context) error

func (*Container) Stop

func (c *Container) Stop() error

func (*Container) Suspend

func (c *Container) Suspend(ctx context.Context) error

type ContainerConfig

type ContainerConfig struct {
	Name         string
	Image        string
	EnvVars      map[string]string
	PortBindings map[string]string
	Labels       map[string]string
	Mounts       []string
	User         string
	Resources    *Resources
	Cmd          []string
	DNS          []string
	UsedPorts    []string
	UseBridge    bool
}

type Host

type Host interface {
	GetDockerHostIP() (string, error)
}

func NewHost

func NewHost() Host

type IPPool

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

func (*IPPool) Get

func (ipp *IPPool) Get() (string, error)

type Image

type Image struct {
	Registry string
	Repo     string
	Tag      string
}

func (Image) IsPublic

func (i Image) IsPublic() bool

func (Image) NameWithReg

func (i Image) NameWithReg() string

func (Image) String

func (i Image) String() string

type Instance

type Instance interface {
	Create(context.Context) error
	Start(context.Context) error
	Run(context.Context) error
	Suspend(context.Context) error
	Stop() error
	Info() InstanceInfo
	io.Closer
}

type InstanceConfig

type InstanceConfig struct {
	Image    string  `yaml:"image"`
	MemoryMB uint    `yaml:"memoryMB"`
	CPU      float64 `yaml:"cpu"`
}

TODO comments and docs

type InstanceInfo

type InstanceInfo struct {
	Image string
	Type  string
	Id    string
	State State
}

type Network

type Network struct {
	Net       *docker.Network
	Subnet    string
	IsVPN     bool
	IpPool    map[uint]struct{}
	Connected []*Container
}

func NewNetwork

func NewNetwork(isVPN bool) (*Network, error)

func (*Network) Close

func (n *Network) Close() error

func (*Network) Connect

func (n *Network) Connect(c *Container, ip ...int) (int, error)

func (*Network) FormatIP

func (n *Network) FormatIP(num int) string

func (*Network) Interface

func (n *Network) Interface() string

func (*Network) SetIsVPN

func (n *Network) SetIsVPN(isVPN bool)

type NoCredentialsErr

type NoCredentialsErr struct {
	Registry string
}

func (NoCredentialsErr) Error

func (err NoCredentialsErr) Error() string

type NoLocalDigestErr

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

func (NoLocalDigestErr) Error

func (err NoLocalDigestErr) Error() string

type NoLocalImageAvailableErr

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

func (NoLocalImageAvailableErr) Error

func (err NoLocalImageAvailableErr) Error() string

type NoRemoteImageAvailableErr

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

func (NoRemoteImageAvailableErr) Error

func (err NoRemoteImageAvailableErr) Error() string

type ResourceResizer

type ResourceResizer interface {
	SetRAM(uint) error
	SetCPU(uint) error
}

type Resources

type Resources struct {
	MemoryMB uint
	CPU      float64
}

type State

type State int

func (State) String

func (s State) String() string

type VBoxErr

type VBoxErr struct {
	Action string
	Output []byte
}

func (*VBoxErr) Error

func (err *VBoxErr) Error() string

type VMOpt

type VMOpt func(context.Context, *Vm) error

func SetBridge

func SetBridge(nic string) VMOpt

func SetCPU

func SetCPU(cores uint) VMOpt

func SetLocalRDP

func SetLocalRDP(ip string, port uint) VMOpt

func SetRAM

func SetRAM(mb uint) VMOpt

type VboxLibrary

type VboxLibrary struct {
	M     sync.Mutex
	Pwd   string
	Known map[string]*Vm
	Locks map[string]*sync.Mutex
}

func NewLibrary

func NewLibrary(pwd string) *VboxLibrary

func (*VboxLibrary) GetCopy

func (lib *VboxLibrary) GetCopy(ctx context.Context, conf InstanceConfig, vmOpts ...VMOpt) (*Vm, error)

func (*VboxLibrary) GetImagePath

func (lib *VboxLibrary) GetImagePath(file string) string

func (*VboxLibrary) IsAvailable

func (lib *VboxLibrary) IsAvailable(file string) bool

type Vm

type Vm struct {
	Id    string
	Path  string
	Image string

	Running bool
	// contains filtered or unexported fields
}

VM information is stored in a struct

func NewVMWithSum

func NewVMWithSum(path, image string, checksum string, vmOpts ...VMOpt) *Vm

func VmExists

func VmExists(image string, checksum string) (*Vm, bool)

func (*Vm) Close

func (vm *Vm) Close() error

func (*Vm) Create

func (vm *Vm) Create(ctx context.Context) error

Creating VM

func (*Vm) Info

func (v *Vm) Info() InstanceInfo

func (*Vm) LinkedClone

func (v *Vm) LinkedClone(ctx context.Context, snapshot string, vmOpts ...VMOpt) (*Vm, error)

func (*Vm) Run

func (vm *Vm) Run(ctx context.Context) error

when Run is called, it calls Create function within it.

func (*Vm) Snapshot

func (vm *Vm) Snapshot(name string) error

func (*Vm) Start

func (vm *Vm) Start(ctx context.Context) error

func (*Vm) Stop

func (vm *Vm) Stop() error

func (*Vm) Suspend

func (vm *Vm) Suspend(ctx context.Context) error

Will call savestate on vm

Jump to

Keyboard shortcuts

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