virtualizers

package
v0.0.0-...-79a645e Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Ready    = "ready"
	Alive    = "alive"
	Broken   = "broken"
	Deleted  = "deleted"
	Changing = "changing"
)

Different states for the virtualizer

Variables

View Source
var ActiveVMs *syncmap.Map

ActiveVMs is a global sync map that contains current running vms

View Source
var IPRegex = regexp.MustCompile(`(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$`)

IPRegex is the regexp to capture an ip address from ip output of a vm

View Source
var Powershell string

Powershell is the path to exec from

Functions

func Backends

func Backends() ([]string, error)

Backends returns the currently available hypervisors the system running on.

func BindPort

func BindPort(netType, protocol, port string) (string, string, error)

BindPort attempts to bind ports and if not available will assign a different port.

func BridgedDevices

func BridgedDevices() ([]string, error)

BridgedDevices is a virtualbox only function which returns an array of available bridged devices

func CheckNameExistsHyperV

func CheckNameExistsHyperV(name string) (bool, error)

CheckNameExistsHyperV checks the hyperv driver to see if a vm with the same name already exists

func CheckNameExistsVirtualBox

func CheckNameExistsVirtualBox(name string) (bool, error)

CheckNameExistsVirtualBox checks the virtualbox list to see if a vm with the same name has already been created

func GetExecutable

func GetExecutable(virtualizer string) (string, error)

GetExecutable returns the name of the executable for the virtualizer.

func HostDevices

func HostDevices() ([]string, error)

HostDevices is a virtualbox only function which returns a list of available host devices

func Register

func Register(vtype string, allocator VirtualizerAllocator)

Register Adds a allocator to the map depending on what virtualizer was created

func RegisteredVirtualizers

func RegisteredVirtualizers() map[string]VirtualizerAllocator

RegisteredVirtualizers returns the map purely for testing the register function

func VSwitches

func VSwitches() ([]string, error)

VSwitches is a windows only function which returns the virtual switches hyper-v responds with

Types

type ListTuple

type ListTuple struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

ListTuple is an object stored in the database easier to reference through a struct

type LogChunk

type LogChunk struct {
	Cursor string `json:"cursor"`
	More   bool   `json:"more"`
	Data   string `json:"data"`
}

LogChunk is struct to control the Serial Logger output

func (*LogChunk) Bytes

func (l *LogChunk) Bytes() ([]byte, error)

Bytes decodes the data of a LogChunk

type Manager

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

Manager is main object which the daemon will interact with

func New

func New(args *ManagerArgs) (*Manager, error)

New creates a new manager the daemon can communicate with.

func (*Manager) Close

func (mgr *Manager) Close() error

Close loops through the current active vms to close them as the manager is closing.

func (*Manager) CreateVirtualizer

func (mgr *Manager) CreateVirtualizer(name, ptype string, data []byte) error

CreateVirtualizer creates a virtualizer from the name, type and data required

func (*Manager) DeleteVirtualizer

func (mgr *Manager) DeleteVirtualizer(name string) error

DeleteVirtualizer removes a virtualizer from the database with the appropriate name

func (*Manager) DiskAlignment

func (mgr *Manager) DiskAlignment(name string) (vcfg.Bytes, error)

DiskAlignment returns the alignment the disk needs to be for the virtualizer

func (*Manager) DiskFormat

func (mgr *Manager) DiskFormat(name string) (vdisk.Format, error)

DiskFormat returns the imageformat required for this virtualizer.

func (*Manager) List

func (mgr *Manager) List() ([]ListTuple, error)

List returns an array of ListTuples from the Database

func (*Manager) Prepare

func (mgr *Manager) Prepare(name string, args *PrepareArgs) (*VirtualizeOperation, error)

Prepare calls the prepare function of a virtualizer which sets up the ability to spawn a VM.

func (*Manager) ReturnData

func (mgr *Manager) ReturnData(name string) ([]byte, error)

ReturnData returns data related to the virtualizer to show a user.

func (*Manager) ValidateArgs

func (mgr *Manager) ValidateArgs(name string) error

ValidateArgs validates the arguments provided to see if the virtualizer is

type ManagerArgs

type ManagerArgs struct {
	Logger          func(format string, v ...interface{})
	DatabaseAddress string
	FirecrackerPath string // path to folder for vmlinux binaries
	Passphrase      string
	VMDrive         string // path to store vms will be /tmp if not provided

}

ManagerArgs are the arguments required to create Virtualizer Manager

type NIC

type NIC struct {
	Protocol map[NetworkProtocol]*NetworkProtocolPorts
}

NIC contains information pertaining to a specific network card for the virtual machine.

type NetworkInterface

type NetworkInterface struct {
	Name    string     `json:"name"`
	IP      string     `json:"ip"`
	Mask    string     `json:"mask"`
	Gateway string     `json:"gateway"`
	UDP     []RouteMap `json:"udp"`
	TCP     []RouteMap `json:"tcp"`
	HTTP    []RouteMap `json:"http"`
	HTTPS   []RouteMap `json:"https"`
}

NetworkInterface is the routes for the machine

type NetworkProtocol

type NetworkProtocol string

NetworkProtocol is related to the API returning state

type NetworkProtocolPorts

type NetworkProtocolPorts struct {
	Port map[string]*NetworkRoute
}

NetworkProtocolPorts contains mappings from the internal ports in use by a Vorteil VM to the network address that can be used to reach them externally.

type NetworkRoute

type NetworkRoute struct {
	Address string
}

NetworkRoute contains information representing the valid and complete information needed to connected to a NetworkPort, regardless of NAT or proxying. Standard ports may be omitted, such as port 80 on HTTP, or 443 on HTTPS.

Examples:

NetworkRoute.Address = "192.168.1.1:80"
NetworkRoute.Address = "localhost:8080"
NetworkRoute.Address = "http://myapp.vorteil.io"

type PrepareArgs

type PrepareArgs struct {
	Name      string // name of the vm
	PName     string // name of virtualizer spawned from
	Logger    elog.View
	FCPath    string // used for firecracker to find vmlinux binaries
	Context   context.Context
	Start     bool       // to control whether its to start automatically
	Config    *vcfg.VCFG // the vcfg attached to the VM
	Source    interface{}
	ImagePath string
	VMDrive   string // path to store disks for vms
}

PrepareArgs is a struct that contains what the VM needs to be able to act accordingly.

type ProgramSummaries

type ProgramSummaries struct {
	Binary string   `json:"binary,omitempty"`
	Args   string   `json:"args,omitempty"`
	Env    []string `json:"env,omitempty"`
}

ProgramSummaries contains the programs that the machine will run

type RouteMap

type RouteMap struct {
	Port    string `json:"port"`
	Address string `json:"address"`
}

RouteMap contains a port and an address

type Routes

type Routes struct {
	NIC [4]NIC
}

Routes contains comprehensive information about the network interfaces on a live virtual machine, and how to connect to them. A common example of their use would be as follows.

addr := Routes.NIC[0].Protocol[NetworkProtocolHTTP].Port["80"].Address

type Source

type Source struct {
	Name       string   `json:"name"`
	Type       string   `json:"type"`
	Checksum   string   `json:"checksum"`
	Icon       string   `json:"icon"`
	FileSystem []string `json:"filesystem"`
	Job        string   `json:"job"`
}

Source is a struct that contains the contents of the virtual machine

type VState

type VState string

VState a type to call for the virtualizers. (ready, alive, broken, deleted, changing)

type VirtualMachine

type VirtualMachine struct {
	ID       string    `json:"id"`
	Instance string    `json:"instance"`
	LogFile  string    `json:"logFile"`
	StateLog string    `json:"stateLog"`
	Created  time.Time `json:"created"`
	Status   string    `json:"status"`
	State    string    `json:"state"`
	Platform string    `json:"platform"`
	Source   Source    `json:"source"`

	// build-determined fields
	Kernel string     `json:"kernel"`
	CPUs   int        `json:"cpus"`
	RAM    vcfg.Bytes `json:"ram"`
	Disk   vcfg.Bytes `json:"disk"`

	Programs []ProgramSummaries `json:"programs"`

	Name    string    `json:"name"`
	Author  string    `json:"author"`
	Summary string    `json:"summary"`
	URL     string    `json:"url"`
	Version string    `json:"version"`
	Date    time.Time `json:"date"`

	// dynamic or semi-dynamic fields
	Hostname string             `json:"hostname"`
	Networks []NetworkInterface `json:"networks"`

	// Logs
	Serial LogChunk `json:"serial"`
}

VirtualMachine is a struct that contains details about the virtual machine

type VirtualizeOperation

type VirtualizeOperation struct {
	Logs   <-chan string
	Status <-chan string
	Error  <-chan error
}

VirtualizeOperation is a struct that contains ways to log for the operation As it is normally go routined which can't return the error through normal means.

type Virtualizer

type Virtualizer interface {
	Type() string                                                                              // Returns what type of virtualizer it is as each virtualizer is actually a VM. I still need the type
	Initialize(data []byte) error                                                              // Initialize the virtualizer using the data provided from the alloc
	Prepare(args *PrepareArgs) *VirtualizeOperation                                            // Prepare the vm setup args etc
	State() string                                                                             // Return the state the vm is currently in
	Download() (vio.File, error)                                                               // Download the disk of the vm
	Details() (string, string, string, []NetworkInterface, time.Time, *vcfg.VCFG, interface{}) // fetch details relating to the machine
	Start() error                                                                              // Start the vm
	Stop() error                                                                               // Stop the vm
	Serial() *logger.Logger                                                                    // Return the serial output of the vm
	Close(bool) error                                                                          // Close the vm is deleting the vm and removing its contents as its not needed anymore.
}

Virtualizer is an interface which each virtualzier needs to implement

type VirtualizerAllocator

type VirtualizerAllocator interface {
	Alloc() Virtualizer             // Return the virtualizer
	ValidateArgs(data []byte) error // Validates the data provided to the virtualizer
	DiskAlignment() vcfg.Bytes      // Returns the appropriate disk alignment required for the virtualizer
	DiskFormat() vdisk.Format       // Returns the appropriate disk format required for the virtualizer
	IsAvailable() bool              // Check if the virtualizer is available on the host's system
}

VirtualizerAllocator is an interface which each virtualizer allocator needs to implement

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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