vmmanager

package
v0.15.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Rendered for windows/amd64

Overview

Package vmmanager manages host-side VM configuration and lifecycle for utility VMs (UVMs).

It provides a concrete UtilityVM struct and a set of granular manager interfaces, each scoped to an individual resource concern:

  • LifetimeManager – start, terminate, close, pause, resume, save, and wait.
  • NetworkManager – add, remove, and update NICs.
  • [SCSIManager] – hot-add and remove SCSI disks.
  • PCIManager – assign and remove PCI devices.
  • PipeManager – add and remove named pipes.
  • Plan9Manager – add and remove Plan 9 shares.
  • VMSocketManager – update and remove HvSocket services.
  • [VPMemManager] – add and remove virtual persistent memory devices.
  • VSMBManager – add and remove virtual SMB shares.
  • ResourceManager – CPU group, CPU limits, and memory updates.

All interfaces are implemented by UtilityVM.

Presently this package is tightly coupled with the HCS backend and only runs HCS-backed UVMs. It does not store host or guest side state; that is the responsibility of the orchestration layer above it.

Creating a UVM

Build an hcsschema.ComputeSystem configuration, then call Create:

config := &hcsschema.ComputeSystem{ ... }
uvm, err := vmmanager.Create(ctx, "uvm-id", config)
if err != nil { // handle error }
if err := uvm.Start(ctx); err != nil { // handle error }

After the VM is running, use the manager interfaces for host-side changes:

_ = uvm.AddNIC(ctx, nicID, settings)

Layer Boundaries

This package covers host-side changes and lifecycle operations on an existing UVM. Guest-side actions (for example, mounting a disk) belong in the sibling guestmanager package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcceptConnection

func AcceptConnection(ctx context.Context, uvm LifetimeManager, l net.Listener, closeConnection bool) (net.Conn, error)

AcceptConnection accepts a connection and then closes a listener. It monitors ctx.Done() and uvm.Wait() for early termination.

Types

type LifetimeManager

type LifetimeManager interface {
	// ID will return a string identifier for the Utility VM.
	ID() string

	// RuntimeID will return the Hyper-V VM GUID for the Utility VM.
	//
	// Only valid after the utility VM has been created.
	RuntimeID() guid.GUID

	// Start will power on the Utility VM and put it into a running state. This will boot the guest OS and start all of the
	// devices configured on the machine.
	Start(ctx context.Context) error

	// Terminate will forcefully power off the Utility VM.
	// It waits for the UVM to exit and returns any encountered errors.
	Terminate(ctx context.Context) error

	// Close terminates and releases resources associated with the utility VM.
	Close(ctx context.Context) error

	// Pause will place the Utility VM into a paused state. The guest OS will be halted and any devices will have be in a
	// a suspended state. Save can be used to snapshot the current state of the virtual machine, and Resume can be used to
	// place the virtual machine back into a running state.
	Pause(ctx context.Context) error

	// Resume will put a previously paused Utility VM back into a running state. The guest OS will resume operation from the point
	// in time it was paused and all devices should be un-suspended.
	Resume(ctx context.Context) error

	// Save will snapshot the state of the Utility VM at the point in time when the VM was paused.
	Save(ctx context.Context, options hcsschema.SaveOptions) error

	// Wait synchronously waits for the Utility VM to terminate.
	Wait(ctx context.Context) error

	// PropertiesV2 returns the properties of the Utility VM.
	PropertiesV2(ctx context.Context, types ...hcsschema.PropertyType) (*hcsschema.Properties, error)

	// StartedTime returns the time when the Utility VM entered the running state.
	StartedTime() time.Time

	// StoppedTime returns the time when the Utility VM entered the stopped state.
	StoppedTime() time.Time

	// ExitError will return any error if the Utility VM exited unexpectedly, or if the Utility VM experienced an
	// error after Wait returned, it will return the wait error.
	ExitError() error
}

type NetworkManager

type NetworkManager interface {
	// AddNIC adds a network adapter to the Utility VM. `nicID` should be a string representation of a
	// Windows GUID.
	AddNIC(ctx context.Context, nicID string, settings *hcsschema.NetworkAdapter) error

	// RemoveNIC removes a network adapter from the Utility VM. `nicID` should be a string representation of a
	// Windows GUID.
	RemoveNIC(ctx context.Context, nicID string, settings *hcsschema.NetworkAdapter) error

	// UpdateNIC updates the configuration of a network adapter on the Utility VM.
	UpdateNIC(ctx context.Context, nicID string, settings *hcsschema.NetworkAdapter) error
}

NetworkManager manages adding and removing network adapters for a Utility VM.

type PCIManager

type PCIManager interface {
	// AddDevice adds a pci device identified by `vmbusGUID` to the Utility VM with the provided settings.
	AddDevice(ctx context.Context, vmbusGUID string, settings hcsschema.VirtualPciDevice) error

	// RemoveDevice removes the pci device identified by `vmbusGUID` from the Utility VM.
	RemoveDevice(ctx context.Context, vmbusGUID string) error
}

PCIManager manages assiging pci devices to a Utility VM. This is Windows specific at the moment.

type PipeManager

type PipeManager interface {
	// AddPipe adds a named pipe to the Utility VM.
	AddPipe(ctx context.Context, hostPath string) error

	// RemovePipe removes a named pipe from the Utility VM.
	RemovePipe(ctx context.Context, hostPath string) error
}

PipeManager manages adding and removing named pipes for a Utility VM.

type Plan9Manager

type Plan9Manager interface {
	// AddPlan9 adds a plan 9 share to a running Utility VM.
	AddPlan9(ctx context.Context, settings hcsschema.Plan9Share) error

	// RemovePlan9 removes a plan 9 share from a running Utility VM.
	RemovePlan9(ctx context.Context, settings hcsschema.Plan9Share) error
}

Plan9Manager manages adding plan 9 shares to a Utility VM.

type ResourceManager

type ResourceManager interface {
	// SetCPUGroup assigns the Utility VM to a cpu group.
	SetCPUGroup(ctx context.Context, settings *hcsschema.CpuGroup) error

	// UpdateCPULimits updates the CPU limits for the Utility VM.
	// `limit` is the percentage of CPU cycles that the Utility VM is allowed to use.
	// `weight` is the relative weight of the Utility VM compared to other VMs when CPU cycles are contended.
	// `reservation` is the percentage of CPU cycles that are reserved for the Utility VM.
	// `maximumFrequencyMHz` is the maximum frequency in MHz that the Utility VM can use.
	UpdateCPULimits(ctx context.Context, settings *hcsschema.ProcessorLimits) error

	// UpdateMemory makes a call to the VM's orchestrator to update the VM's size in MB
	UpdateMemory(ctx context.Context, memory uint64) error
}

type UtilityVM

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

UtilityVM is an abstraction around a lightweight virtual machine. It houses core lifecycle methods such as Create, Start, and Stop and also several optional methods that can be used to determine what the virtual machine supports and to configure these resources.

func Create

func Create(ctx context.Context, id string, config *hcsschema.ComputeSystem) (*UtilityVM, error)

Create creates a new utility VM with the given ID and compute system configuration.

This method returns the concrete UtilityVM. Callers can use the manager interfaces (for example, LifetimeManager, NetworkManager) as needed.

func (*UtilityVM) AddDevice

func (uvm *UtilityVM) AddDevice(ctx context.Context, vmbusGUID string, settings hcsschema.VirtualPciDevice) error

func (*UtilityVM) AddNIC

func (uvm *UtilityVM) AddNIC(ctx context.Context, nicID string, settings *hcsschema.NetworkAdapter) error

func (*UtilityVM) AddPipe

func (uvm *UtilityVM) AddPipe(ctx context.Context, hostPath string) error

func (*UtilityVM) AddPlan9

func (uvm *UtilityVM) AddPlan9(ctx context.Context, settings hcsschema.Plan9Share) error

func (*UtilityVM) AddSCSIDisk

func (uvm *UtilityVM) AddSCSIDisk(ctx context.Context, disk hcsschema.Attachment, controller uint, lun uint) error

func (*UtilityVM) AddVPMemDevice

func (uvm *UtilityVM) AddVPMemDevice(ctx context.Context, id uint32, settings hcsschema.VirtualPMemDevice) error

func (*UtilityVM) AddVSMB

func (uvm *UtilityVM) AddVSMB(ctx context.Context, settings hcsschema.VirtualSmbShare) error

func (*UtilityVM) Close

func (uvm *UtilityVM) Close(ctx context.Context) error

Close closes the utility VM and releases all associated resources.

func (*UtilityVM) ExitError

func (uvm *UtilityVM) ExitError() error

ExitError returns the exit error of the utility VM, if it has exited.

func (*UtilityVM) ID

func (uvm *UtilityVM) ID() string

ID returns the ID of the utility VM.

func (*UtilityVM) Pause

func (uvm *UtilityVM) Pause(ctx context.Context) error

Pause pauses the utility VM.

func (*UtilityVM) PropertiesV2

func (uvm *UtilityVM) PropertiesV2(ctx context.Context, types ...hcsschema.PropertyType) (*hcsschema.Properties, error)

PropertiesV2 returns the properties of the utility VM from HCS.

func (*UtilityVM) RemoveDevice

func (uvm *UtilityVM) RemoveDevice(ctx context.Context, vmbusGUID string) error

func (*UtilityVM) RemoveHvSocketService

func (uvm *UtilityVM) RemoveHvSocketService(ctx context.Context, serviceID string) error

RemoveHvSocketService will remove an hvsocket service entry if it exists.

func (*UtilityVM) RemoveNIC

func (uvm *UtilityVM) RemoveNIC(ctx context.Context, nicID string, settings *hcsschema.NetworkAdapter) error

func (*UtilityVM) RemovePipe

func (uvm *UtilityVM) RemovePipe(ctx context.Context, hostPath string) error

func (*UtilityVM) RemovePlan9

func (uvm *UtilityVM) RemovePlan9(ctx context.Context, settings hcsschema.Plan9Share) error

func (*UtilityVM) RemoveSCSIDisk

func (uvm *UtilityVM) RemoveSCSIDisk(ctx context.Context, controller uint, lun uint) error

func (*UtilityVM) RemoveVPMemDevice

func (uvm *UtilityVM) RemoveVPMemDevice(ctx context.Context, id uint32) error

func (*UtilityVM) RemoveVSMB

func (uvm *UtilityVM) RemoveVSMB(ctx context.Context, settings hcsschema.VirtualSmbShare) error

func (*UtilityVM) Resume

func (uvm *UtilityVM) Resume(ctx context.Context) error

Resume resumes the utility VM.

func (*UtilityVM) RuntimeID

func (uvm *UtilityVM) RuntimeID() guid.GUID

RuntimeID returns the runtime ID of the utility VM.

func (*UtilityVM) Save

func (uvm *UtilityVM) Save(ctx context.Context, options hcsschema.SaveOptions) error

Save saves the state of the utility VM as a template.

func (*UtilityVM) SetCPUGroup

func (uvm *UtilityVM) SetCPUGroup(ctx context.Context, settings *hcsschema.CpuGroup) error

func (*UtilityVM) Start

func (uvm *UtilityVM) Start(ctx context.Context) (err error)

Start starts the utility VM.

func (*UtilityVM) StartedTime

func (uvm *UtilityVM) StartedTime() time.Time

StartedTime returns the time when the utility VM entered the running state.

func (*UtilityVM) StoppedTime

func (uvm *UtilityVM) StoppedTime() time.Time

StoppedTime returns the time when the utility VM entered the stopped state.

func (*UtilityVM) Terminate

func (uvm *UtilityVM) Terminate(ctx context.Context) error

Terminate terminates the utility VM and waits for it to exit.

func (*UtilityVM) UpdateCPULimits

func (uvm *UtilityVM) UpdateCPULimits(ctx context.Context, settings *hcsschema.ProcessorLimits) error

func (*UtilityVM) UpdateHvSocketService

func (uvm *UtilityVM) UpdateHvSocketService(ctx context.Context, serviceID string, config *hcsschema.HvSocketServiceConfig) error

UpdateHvSocketService calls HCS to update/create the hvsocket service for the UVM. Takes in a service ID and the hvsocket service configuration. If there is no entry for the service ID already it will be created. The same call on HvSockets side handles the Create/Update/Delete cases based on what is passed in. Here is the logic for the call.

1. If the service ID does not currently exist in the service table, it will be created with whatever descriptors and state was specified (disabled or not). 2. If the service already exists and empty descriptors and Disabled is passed in for the service config, the service will be removed. 3. Otherwise any combination that is not Disabled && Empty descriptors will just update the service.

If the request is crafted with Disabled = True and empty descriptors, then this function will behave identically to a call to RemoveHvSocketService. Prefer RemoveHvSocketService for this behavior as the relevant fields are set on HCS' side.

func (*UtilityVM) UpdateMemory

func (uvm *UtilityVM) UpdateMemory(ctx context.Context, memory uint64) error

func (*UtilityVM) UpdateNIC

func (uvm *UtilityVM) UpdateNIC(ctx context.Context, nicID string, settings *hcsschema.NetworkAdapter) error

func (*UtilityVM) Wait

func (uvm *UtilityVM) Wait(ctx context.Context) error

Wait waits for the utility VM to exit and returns any error that occurred during execution.

type VMSocketManager

type VMSocketManager interface {
	// UpdateHvSocketService will update the configuration for the HvSocket service with the specified `serviceID`.
	UpdateHvSocketService(ctx context.Context, serviceID string, config *hcsschema.HvSocketServiceConfig) error

	// RemoveHvSocketService will remove the HvSocket service with the specified `serviceID` from the Utility VM.
	RemoveHvSocketService(ctx context.Context, serviceID string) error
}

VMSocketManager manages configuration for a hypervisor socket transport. This includes sockets such as HvSocket and Vsock.

type VSMBManager

type VSMBManager interface {
	// AddVSMB adds a virtual smb share to a running Utility VM.
	AddVSMB(ctx context.Context, settings hcsschema.VirtualSmbShare) error

	// RemoveVSMB removes a virtual smb share from a running Utility VM.
	RemoveVSMB(ctx context.Context, settings hcsschema.VirtualSmbShare) error
}

VSMBManager manages adding virtual smb shares to a Utility VM.

Jump to

Keyboard shortcuts

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