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
- Variables
- type Driver
- func (vd *Driver) DeleteMachine(machinename string, clustername string) error
- func (vd *Driver) DeleteNetwork(clustername string) error
- func (vd *Driver) Description() string
- func (vd *Driver) Error() string
- func (vd *Driver) GetImage(k8sversion string) (drivercore.Image, error)
- func (vd *Driver) GetMachine(machinename string, clustername string) (drivercore.Machine, error)
- func (vd *Driver) K8sVersions() []string
- func (vd *Driver) ListImages() ([]drivercore.Image, error)
- func (vd *Driver) Name() string
- func (vd *Driver) NewMachine(machinename string, clustername string, k8sversion string) (drivercore.Machine, error)
- func (vd *Driver) NewNetwork(clustername string) (drivercore.Network, error)
- func (vd *Driver) QualifiedMachineName(machinename string, clustername string) string
- func (vd *Driver) QualifiedNetworkName(clustername string) string
- func (vd *Driver) Status() string
- func (vd *Driver) UpdateImageList() error
- func (vd *Driver) UsesNATNetworking() bool
- func (vd *Driver) UsesPerClusterNetworking() bool
- func (vd *Driver) ValidK8sVersion(k8sversion string) bool
- type Image
- func (i *Image) Deprecated() bool
- func (i *Image) Fetch() error
- func (i *Image) FetchWithProgress(progress func(current int64, total int64)) error
- func (i *Image) FromFile(localfilepath string) error
- func (i *Image) K8sVersion() string
- func (i *Image) MarshalJSON() ([]byte, error)
- func (i *Image) PurgeLocal() error
- func (i *Image) Status() drivercore.ImageStatus
- func (i *Image) UnmarshalJSON(b []byte) error
- type Machine
- func (vh *Machine) Error() string
- func (vh *Machine) ExecuteCommand(command drivercore.PredefinedCommand, params ...string) error
- func (vh *Machine) ForceStop() error
- func (vh *Machine) ForwardPort(hostport int, machineport int) error
- func (vh *Machine) ForwardSSHPort(hostport int) error
- func (vh *Machine) IPAddress() string
- func (vh *Machine) ImplementsCommand(command drivercore.PredefinedCommand) bool
- func (vh *Machine) Name() string
- func (vh *Machine) SSHAddress() string
- func (vh *Machine) Start() error
- func (vh *Machine) Status() drivercore.MachineStatus
- func (vh *Machine) Stop() error
- func (vh *Machine) UnforwardPort(machineport int) error
- func (vh *Machine) WaitForStateChange(timeoutinseconds int)
Constants ¶
const ( MachineStatusStarting = drivercore.MachineStatus("Starting") MachineStatusStopping = drivercore.MachineStatus("Stopping") MachineStatusCreating = drivercore.MachineStatus("Creating") )
The MachineStatus* constants add some Hyper-V specific statuses.
const ImagesVersion = "0.1"
ImagesVersion defines the image repository version for the current version of the driver.
Variables ¶
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 ¶
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 ¶
DeleteNetwork is not implemented in the Hyper-V driver.
func (*Driver) Description ¶
Description returns "Kutti driver for Hyper-V".
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 ¶
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 ¶
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) 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 ¶
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 ¶
QualifiedNetworkName is not implemented in the Hyper-V driver.
func (*Driver) UpdateImageList ¶
UpdateImageList fetches the latest list of VM images from the driver source URL.
func (*Driver) UsesNATNetworking ¶
UsesNATNetworking returns false.
func (*Driver) UsesPerClusterNetworking ¶
UsesPerClusterNetworking returns false.
func (*Driver) ValidK8sVersion ¶
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 ¶
Deprecated returns true if the image's version of Kubernetes is deprecated. New Machines should not be created from such an image.
func (*Image) FetchWithProgress ¶ added in v0.2.0
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 ¶
FromFile verifies an image file on a local path and copies it to the cache.
func (*Image) K8sVersion ¶
K8sVersion returns the version of Kubernetes present in the image.
func (*Image) MarshalJSON ¶
MarshalJSON returns the JSON encoding of the image.
func (*Image) PurgeLocal ¶
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 ¶
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 ¶
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 ¶
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 ¶
ForwardPort is not supported for the Hyper-V driver.
func (*Machine) ForwardSSHPort ¶
ForwardSSHPort is not supported for the Hyper-V driver.
func (*Machine) IPAddress ¶
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) SSHAddress ¶
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 ¶
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 ¶
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 ¶
UnforwardPort is not supported for the Hyper-V driver.
func (*Machine) WaitForStateChange ¶
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.