hypvsr

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTemplate

func GetTemplate(name string) (string, error)

func GetTemplateList

func GetTemplateList() []string

GetTemplateList gets the list of available templates

Types

type Cluster

type Cluster struct {
	Kind      string            `yaml:"kind"`     // Kind of the resource, should be 'Cluster'
	Name      string            `yaml:"name"`     // Name of the cluster. Must be unique in the system
	Params    map[string]string `yaml:"params"`   // Parameters for the cluster
	Instances []Machine         `yaml:"machines"` // List of machines in the cluster
	Results   []string          `yaml:"results"`
}

Cluster holds the configuration details for a cluster of machines

func (*Cluster) Prepare

func (c *Cluster) Prepare() error

type Credentials

type Credentials struct {
	Username string   `yaml:"username,omitempty"` // Username for the machine
	Password string   `yaml:"password,omitempty"` // Password for the machine
	Groups   []string `yaml:"groups,omitempty"`   // User groups for the machine
}

Credentials holds the username, password, and user groups

type Hypervisor

type Hypervisor interface {
	Create(machine *Machine) error
	Start(machine *Machine) error
	Stop(machine *Machine) error
	ForceStop(machine *Machine) error
	Status(machine *Machine) (string, error)
	Delete(machine *Machine) error
}

Hypervisor is an interface for interacting with the hypervisor

type Image

type Image struct {
	URL      string `yaml:"url,omitempty"`      // URL of the machine image
	Checksum string `yaml:"checksum,omitempty"` // Checksum for the image in the format 'algorithm:hash'
}

Image holds the URL and checksum of the machine image

type Instance

type Instance struct {
	Kind       string
	Machines   []Machine
	Config     config.Config
	Hypervisor Hypervisor
}

func NewInstance

func NewInstance(template Templater) (*Instance, error)

NewInstance is a factory function that returns an instance of KindManager.

type Libvirt

type Libvirt struct{}

Libvirt is a struct that represents the libvirt hypervisor

func (*Libvirt) Create

func (h *Libvirt) Create(machine *Machine) error

Create is a method for the libvirt hypervisor that creates an machine

func (*Libvirt) Delete

func (h *Libvirt) Delete(machine *Machine) error

Delete is a method for the libvirt hypervisor that deletes a created machine

func (*Libvirt) ForceStop

func (h *Libvirt) ForceStop(machine *Machine) error

ForceStop is a method for the libvirt hypervisor that force stops a running/stuck machine

func (*Libvirt) Start

func (h *Libvirt) Start(machine *Machine) error

Start is a method for the libvirt hypervisor that starts a stopped machine

func (*Libvirt) Status

func (h *Libvirt) Status(machine *Machine) (string, error)

Status is a method for the libvirt hypervisor that gets the status of an machine

func (*Libvirt) Stop

func (h *Libvirt) Stop(machine *Machine) error

Start is a method for the libvirt hypervisor that stops a running machine

type LocalTemplate

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

LocalTemplate represents a local file-based template

func (*LocalTemplate) Load

func (f *LocalTemplate) Load() (*Instance, error)

Load is a method on the LocalTemplate struct that implements the Templater interface. It reads the content of the template from the local file system, parses it, and returns a corresponding KindManager.

type Machine

type Machine struct {
	Kind        string        `yaml:"kind"`                  // Kind of the resource, should be 'Machine'
	Name        string        `yaml:"name,omitempty"`        // Name of the machine. Must be unique in the system
	Extends     string        `yaml:"extends,omitempty"`     // Name of the Machine to extend
	Replicas    int           `yaml:"replicas,omitempty"`    // Number of Replicas (used with kind Cluster)
	Image       Image         `yaml:"image,omitempty"`       // Image details for the machine
	Credentials Credentials   `yaml:"credentials,omitempty"` // Credentials for the machine
	Resources   Resources     `yaml:"resources,omitempty"`   // Hardware resources for the machine
	Scripts     Scripts       `yaml:"scripts,omitempty"`     // Scripts to run in the machine
	Mount       Mount         `yaml:"mount,omitempty"`       // Mount point details
	Network     Network       `yaml:"network,omitempty"`     // Network configuration
	Connection  string        `yaml:"connection,omitempty"`  // Connection to hypervisor
	Variant     string        `yaml:"variant,omitempty"`     // OS variant to use
	Hypervisor  Hypervisor    `yaml:"-"`
	Runner      osutil.Runner `yaml:"-"`
	// contains filtered or unexported fields
}

Machine holds the configuration details for a single machine

func GetMachine

func GetMachine(name string) (*Machine, error)

GetMachine loads the YAML file content into the struct

func (*Machine) CopyContent

func (machine *Machine) CopyContent(origin string, dest string) error

Copies content from host to guest or vice-versa

func (*Machine) Create

func (machine *Machine) Create() error

Create creates the VM and starts it

func (*Machine) CreateDir

func (machine *Machine) CreateDir() error

CreateDir creates the directory for the machine

func (*Machine) CreateDisks

func (machine *Machine) CreateDisks() error

CreateDisks creates the disks for the machine

func (*Machine) Delete

func (machine *Machine) Delete() error

Deletes a VM

func (*Machine) DownloadImage

func (machine *Machine) DownloadImage() error

DownloadImage downloads the image for the machine

func (*Machine) ForceStop

func (machine *Machine) ForceStop() error

Force stops a running VM

func (*Machine) GetVMs

func (machine *Machine) GetVMs() []Machine

func (*Machine) Prepare

func (machine *Machine) Prepare() error

Prepare prepares the machine for use

func (*Machine) RunInitScripts

func (machine *Machine) RunInitScripts() error

Runs the initial scripts after the machine is created

func (*Machine) Shell

func (machine *Machine) Shell() error

func (*Machine) Start

func (machine *Machine) Start() error

Starts a stopped vm

func (*Machine) Status

func (machine *Machine) Status() (string, error)

Gets the status of a VM

func (*Machine) Stop

func (machine *Machine) Stop() error

Stops a running VM

func (*Machine) Wait

func (machine *Machine) Wait() error

Wait until the machine is running

type Mount

type Mount struct {
	Name      string `yaml:"name,omitempty"`      // Name of the mount point
	HostPath  string `yaml:"hostPath,omitempty"`  // Path in the host
	GuestPath string `yaml:"guestPath,omitempty"` // Path inside the VM
}

Mount holds the hostPath and guestPath for mounting host folders into the VM

type Network

type Network struct {
	NicName    string `yaml:"nicName,omitempty"`    // Name of the interface
	IPAddress  string `yaml:"ipAddress,omitempty"`  // IP Address of the machine
	Gateway    string `yaml:"gateway,omitempty"`    // Gateway of the network
	MacAddress string `yaml:"macAddress,omitempty"` // MacAddress of the NIC
}

Network holds the network configuration

type Qemu

type Qemu struct{}

func (*Qemu) Create

func (h *Qemu) Create(vm *Machine) error

func (*Qemu) Delete

func (h *Qemu) Delete(vm *Machine) error

func (*Qemu) ForceStop

func (h *Qemu) ForceStop(vm *Machine) error

func (*Qemu) Start

func (h *Qemu) Start(vm *Machine) error

func (*Qemu) Status

func (h *Qemu) Status(vm *Machine) (string, error)

func (*Qemu) Stop

func (h *Qemu) Stop(vm *Machine) error

type RemoteTemplate

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

RemoteTemplate represents a template that needs to be fetched from a remote source

func (*RemoteTemplate) Load

func (f *RemoteTemplate) Load() (*Instance, error)

Load is a method on the RemoteTemplate struct that implements the Templater interface. It reads the content of the template from the local file system, parses it, and returns a corresponding KindManager.

type Resources

type Resources struct {
	CPUs   string `yaml:"cpus,omitempty"`   // Number of CPUs for the machine
	Memory string `yaml:"memory,omitempty"` // Amount of RAM for the machine
	Disk   string `yaml:"disk,omitempty"`   // Disk space for the machine
}

Resources holds the hardware specifications of the machine

type Scripts

type Scripts struct {
	Install string `yaml:"install,omitempty"` // Installation script to run in the machine
	Init    string `yaml:"init,omitempty"`    // Initialisation script to run when machine starts
}

Scripts holds the installation and initialisation scripts

type Templater

type Templater interface {
	// Load method is responsible for loading the template
	// and returning an instance of KindManager and error if any occurs during the loading
	Load() (*Instance, error)
}

Templater is an interface for loading different types of templates

func NewTemplate

func NewTemplate(name string) Templater

NewTemplate is a factory function that returns an instance of Templater. It determines the type of Templater (LocalTemplate or RemoteTemplate) based on whether a file with the given name exists on the local file system.

Jump to

Keyboard shortcuts

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