driverhyperv

package module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

driver-hyperv

kutti driver for Microsoft Hyper-V

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 differencing VHDX disks backed by master images 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.2"

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 uses a differencing VHDX file backed by the cached master image for the specified k8sversion in the driver cache location for VM disks. It then runs the following Cmdlets, in order:

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

through an interface script.

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 = imagecore.Image

Image implements the drivercore.Image interface for Hyper-V. See the imagecore package.

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 up to the specified number of seconds, or until the Machine status changes. It does this through the waitmachine command of the interface script. If the Machine is starting, the script runs the command:

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

If the Machine is stopping, Wait-VM cannot be used, and the script looks at the state of the VM until it is Off. If the command works, the Machine is updated from its result. If it does not, for example because the time ran out, the Machine is left as it was. A timeout that is not positive is taken by the script as 25 seconds. WaitForStateChange should be called after a call to Start or Stop, before any other operation.

Jump to

Keyboard shortcuts

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