driverhyperv

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 15 Imported by: 0

README

driver-hyperv

kutti driver for Microsoft Hyper-V

Go Report Card PkgGoDev GitHub release (latest by date)

Images

This driver depends on Hyper-V VM images published via the kuttiproject/driver-hyperv-images repository. The details of the driver-to-VM interface are documented there.

The releases of that repository are the default source for this driver. The list of available/deprecated images and the images themselves are published there. The releases of that repository follow the major and minor versions of this repository, but sometimes may lag by one version. The ImagesVersion constant specifies the version of the images repository that is used by a particular version of this driver.

Windows-only

This driver only works on Windows operating systems, from Windows 10 onwards.

Documentation

Overview

Package driverhyperv implements a kutti driver for Microsoft Hyper-V. It uses the Hyper-V PowerShell module to talk to Hyper-V. It invokes Cmdlets from the module via an interface script.

For cluster networking, it uses the Hyper-V default switch.

For nodes, it creates virtual machines with pre-set settings, and attaches copies of VHDX disks, maintained by the companion driver-hyperv-images project.

For images, it uses the aforesaid VHDX files, downloading the list from the URL pointed to by the ImagesSourceURL variable.

The details of individual operations can be found in the online documentation. Details about the interface between the driver and a running VM can be found at the driver-hyperv-images project: https://github.com/kuttiproject/driver-hyperv-images

Index

Constants

View Source
const (
	MachineStatusStarting = drivercore.MachineStatus("Starting")
	MachineStatusStopping = drivercore.MachineStatus("Stopping")
	MachineStatusCreating = drivercore.MachineStatus("Creating")
)

The MachineStatus* constants add some Hyper-V specific statuses.

View Source
const ImagesVersion = "0.1"

ImagesVersion defines the image repository version for the current version of the driver.

Variables

View Source
var ImagesSourceURL = "https://github.com/kuttiproject/driver-hyperv-images/releases/download/v" + ImagesVersion + "/" + imagesConfigFile

ImagesSourceURL is the location where the master list of images can be found

Functions

This section is empty.

Types

type Driver

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

Driver implements the drivercore.Driver interface for Hyper-V.

func (*Driver) DeleteMachine

func (vd *Driver) DeleteMachine(machinename string, clustername string) error

DeleteMachine completely deletes a Machine. It does this by running the Cmdlet:

Remove-VM -Name <machinename> -Force

through an interface script. It also deletes the VM disk files and the directory containing the VM files.

func (*Driver) DeleteNetwork

func (vd *Driver) DeleteNetwork(clustername string) error

DeleteNetwork is not implemented in the Hyper-V driver.

func (*Driver) Description

func (vd *Driver) Description() string

Description returns "Kutti driver for Hyper-V".

func (*Driver) Error

func (vd *Driver) Error() string

Error returns the last error returned in the driver.

func (*Driver) GetImage

func (vd *Driver) GetImage(k8sversion string) (drivercore.Image, error)

GetImage returns an image corresponding to a Kubernetes version, or an error.

func (*Driver) GetMachine

func (vd *Driver) GetMachine(machinename string, clustername string) (drivercore.Machine, error)

GetMachine returns the named machine, or an error. It does this by running the Cmdlet:

Get-VM -Name <machinename>

through an interface script.

func (*Driver) K8sVersions

func (vd *Driver) K8sVersions() []string

K8sVersions returns all Kubernetes versions currently supported.

func (*Driver) ListImages

func (vd *Driver) ListImages() ([]drivercore.Image, error)

ListImages lists the currently available Images.

func (*Driver) Name

func (vd *Driver) Name() string

Name returns "hyperv".

func (*Driver) NewMachine

func (vd *Driver) NewMachine(machinename string, clustername string, k8sversion string) (drivercore.Machine, error)

NewMachine creates a VM. It also starts the VM, changes the hostname, saves the IP address, and stops it again. It starts by copying the VHDX file appropriate for the specified k8sversion to the driver cache location for VM disks. It then runs the following Cmdlets, in order:

$newvm = New-VM -Name $machineName -Generation 1 -Path $machinePath -VHDPath $vhdpath -SwitchName "Default Switch"
Set-VM $newvm -StaticMemory -MemoryStartupBytes 2147483648 -ProcessorCount 2 -CheckpointType Disabled

through an interface script. The first creates a Hyper-V "Generation 1" VM which uses the VHDX file mentioned above, and connects it to the Hyper-V default network switch. The second turns off dynamic memory and checkpoints on the VM, and sets memory to 2GB and core count to 2 (hardcoded for now).

func (*Driver) NewNetwork

func (vd *Driver) NewNetwork(clustername string) (drivercore.Network, error)

NewNetwork is not implemented in the Hyper-V driver.

func (*Driver) QualifiedMachineName

func (vd *Driver) QualifiedMachineName(machinename string, clustername string) string

QualifiedMachineName returns a name in the form <username>-<clustername>-<machinename>. The <username> part is needed for this driver because Hyper-V VM names are machine-wide. It separates nodes created by different users.

func (*Driver) QualifiedNetworkName

func (vd *Driver) QualifiedNetworkName(clustername string) string

QualifiedNetworkName is not implemented in the Hyper-V driver.

func (*Driver) Status

func (vd *Driver) Status() string

Status returns current driver status.

func (*Driver) UpdateImageList

func (vd *Driver) UpdateImageList() error

UpdateImageList fetches the latest list of VM images from the driver source URL.

func (*Driver) UsesNATNetworking

func (vd *Driver) UsesNATNetworking() bool

UsesNATNetworking returns false.

func (*Driver) UsesPerClusterNetworking

func (vd *Driver) UsesPerClusterNetworking() bool

UsesPerClusterNetworking returns false.

func (*Driver) ValidK8sVersion

func (vd *Driver) ValidK8sVersion(k8sversion string) bool

ValidK8sVersion returns true if the specified Kubernetes version is currently supported.

type Image

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

Image implements the drivercore.Image interface for Hyper-V.

func (*Image) Deprecated

func (i *Image) Deprecated() bool

Deprecated returns true if the image's version of Kubernetes is deprecated. New Machines should not be created from such an image.

func (*Image) Fetch

func (i *Image) Fetch() error

Fetch downloads the image from its source URL.

func (*Image) FetchWithProgress added in v0.2.0

func (i *Image) FetchWithProgress(progress func(current int64, total int64)) error

FetchWithProgress downloads the image from the driver repository into the local cache, and reports progress via the supplied callback. The callback reports current and total in bytes.

func (*Image) FromFile

func (i *Image) FromFile(localfilepath string) error

FromFile verifies an image file on a local path and copies it to the cache.

func (*Image) K8sVersion

func (i *Image) K8sVersion() string

K8sVersion returns the version of Kubernetes present in the image.

func (*Image) MarshalJSON

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

MarshalJSON returns the JSON encoding of the image.

func (*Image) PurgeLocal

func (i *Image) PurgeLocal() error

PurgeLocal removes the local cached copy of an image.

func (*Image) Status

func (i *Image) Status() drivercore.ImageStatus

Status returns the status of the image. Status can be Downloaded, meaning the image exists in the local cache and can be used to create Machines, or Notdownloaded, meaning it has to be downloaded using Fetch.

func (*Image) UnmarshalJSON

func (i *Image) UnmarshalJSON(b []byte) error

UnmarshalJSON parses and restores a JSON-encoded image.

type Machine

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

Machine implements the drivercore.Machine interface for VirtualBox

func (*Machine) Error

func (vh *Machine) Error() string

Error returns the last error caused when manipulating this machine. A valid value can be expected only when Status() returns drivercore.MachineStatusError.

func (*Machine) ExecuteCommand

func (vh *Machine) ExecuteCommand(command drivercore.PredefinedCommand, params ...string) error

ExecuteCommand executes the specified predefined command.

func (*Machine) ForceStop

func (vh *Machine) ForceStop() error

ForceStop stops a Machine forcibly. It does this by running the command:

Stop-VM -Name <machinename> -TurnOff

through an interface script. This operation will set the status to drivercore.MachineStatusStopped.

func (*Machine) ForwardPort

func (vh *Machine) ForwardPort(hostport int, machineport int) error

ForwardPort is not supported for the Hyper-V driver.

func (*Machine) ForwardSSHPort

func (vh *Machine) ForwardSSHPort(hostport int) error

ForwardSSHPort is not supported for the Hyper-V driver.

func (*Machine) IPAddress

func (vh *Machine) IPAddress() string

IPAddress returns the current IP Address of this Machine. The Machine status has to be Running. If not, returns an empty string.

func (*Machine) ImplementsCommand

func (vh *Machine) ImplementsCommand(command drivercore.PredefinedCommand) bool

ImplementsCommand returns true if the driver implements the specified predefined command. The Hyper-V driver implements drivercore.RenameMachine

func (*Machine) Name

func (vh *Machine) Name() string

Name is the name of the machine.

func (*Machine) SSHAddress

func (vh *Machine) SSHAddress() string

SSHAddress returns the address to SSH into this Machine. The Machine status has to be Running. If not, returns an empty string. In the Hyper-V driver, this is the same as the IP address, followed by ":22" if not blank.

func (*Machine) Start

func (vh *Machine) Start() error

Start starts a Machine. It does this by running the command:

Start-VM -Name <machinename>

through an interface script. Note that a Machine may not be ready for further operations at the end of this, and therefore its status will Starting, not Started. See WaitForStateChange().

func (*Machine) Status

func (vh *Machine) Status() drivercore.MachineStatus

Status can be drivercore.MachineStatusRunning, drivercore.MachineStatusStopped drivercore.MachineStatusUnknown, drivercore.MachineStatusError, driverhyperv.MachineStatusStarting or driverhyperv.MachineStatusStopping.

func (*Machine) Stop

func (vh *Machine) Stop() error

Stop stops a Machine. It does this by running the command:

Stop-VM -Name <machinename> -Force

Note that a Machine may not be ready for further operations at the end of this, and therefore its status will be Stopping, not Stopped. See WaitForStateChange().

func (*Machine) UnforwardPort

func (vh *Machine) UnforwardPort(machineport int) error

UnforwardPort is not supported for the Hyper-V driver.

func (*Machine) WaitForStateChange

func (vh *Machine) WaitForStateChange(timeoutinseconds int)

WaitForStateChange waits the specified number of seconds, or until the Machine status changes. It does this by running the command:

Wait-VM -ErrorAction Stop -VMName $machineName -Timeout $timeOutSeconds -For IPAddress

if the Machine is starting, or the command:

Wait-VM -ErrorAction Stop -VMName $machineName -Timeout $timeOutSeconds -For Reboot

if the Machine is stopping. WaitForStateChange should be called after a call to Start, before any other operation. From observation, it should not be called _before_ Stop.

Jump to

Keyboard shortcuts

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