Documentation
¶
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 ¶
- func AcceptConnection(ctx context.Context, uvm LifetimeManager, l net.Listener, closeConnection bool) (net.Conn, error)
- type LifetimeManager
- type NetworkManager
- type PCIManager
- type PipeManager
- type Plan9Manager
- type ResourceManager
- type UtilityVM
- func (uvm *UtilityVM) AddDevice(ctx context.Context, vmbusGUID string, settings hcsschema.VirtualPciDevice) error
- func (uvm *UtilityVM) AddNIC(ctx context.Context, nicID string, settings *hcsschema.NetworkAdapter) error
- func (uvm *UtilityVM) AddPipe(ctx context.Context, hostPath string) error
- func (uvm *UtilityVM) AddPlan9(ctx context.Context, settings hcsschema.Plan9Share) error
- func (uvm *UtilityVM) AddSCSIDisk(ctx context.Context, disk hcsschema.Attachment, controller uint, lun uint) error
- func (uvm *UtilityVM) AddVPMemDevice(ctx context.Context, id uint32, settings hcsschema.VirtualPMemDevice) error
- func (uvm *UtilityVM) AddVSMB(ctx context.Context, settings hcsschema.VirtualSmbShare) error
- func (uvm *UtilityVM) Close(ctx context.Context) error
- func (uvm *UtilityVM) ExitError() error
- func (uvm *UtilityVM) ID() string
- func (uvm *UtilityVM) Pause(ctx context.Context) error
- func (uvm *UtilityVM) PropertiesV2(ctx context.Context, types ...hcsschema.PropertyType) (*hcsschema.Properties, error)
- func (uvm *UtilityVM) RemoveDevice(ctx context.Context, vmbusGUID string) error
- func (uvm *UtilityVM) RemoveHvSocketService(ctx context.Context, serviceID string) error
- func (uvm *UtilityVM) RemoveNIC(ctx context.Context, nicID string, settings *hcsschema.NetworkAdapter) error
- func (uvm *UtilityVM) RemovePipe(ctx context.Context, hostPath string) error
- func (uvm *UtilityVM) RemovePlan9(ctx context.Context, settings hcsschema.Plan9Share) error
- func (uvm *UtilityVM) RemoveSCSIDisk(ctx context.Context, controller uint, lun uint) error
- func (uvm *UtilityVM) RemoveVPMemDevice(ctx context.Context, id uint32) error
- func (uvm *UtilityVM) RemoveVSMB(ctx context.Context, settings hcsschema.VirtualSmbShare) error
- func (uvm *UtilityVM) Resume(ctx context.Context) error
- func (uvm *UtilityVM) RuntimeID() guid.GUID
- func (uvm *UtilityVM) Save(ctx context.Context, options hcsschema.SaveOptions) error
- func (uvm *UtilityVM) SetCPUGroup(ctx context.Context, settings *hcsschema.CpuGroup) error
- func (uvm *UtilityVM) Start(ctx context.Context) (err error)
- func (uvm *UtilityVM) StartedTime() time.Time
- func (uvm *UtilityVM) StoppedTime() time.Time
- func (uvm *UtilityVM) Terminate(ctx context.Context) error
- func (uvm *UtilityVM) UpdateCPULimits(ctx context.Context, settings *hcsschema.ProcessorLimits) error
- func (uvm *UtilityVM) UpdateHvSocketService(ctx context.Context, serviceID string, config *hcsschema.HvSocketServiceConfig) error
- func (uvm *UtilityVM) UpdateMemory(ctx context.Context, memory uint64) error
- func (uvm *UtilityVM) UpdateNIC(ctx context.Context, nicID string, settings *hcsschema.NetworkAdapter) error
- func (uvm *UtilityVM) Wait(ctx context.Context) error
- type VMSocketManager
- type VSMBManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
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) AddSCSIDisk ¶
func (*UtilityVM) AddVPMemDevice ¶
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 (*UtilityVM) RemoveHvSocketService ¶
RemoveHvSocketService will remove an hvsocket service entry if it exists.
func (*UtilityVM) RemovePipe ¶
func (*UtilityVM) RemovePlan9 ¶
func (*UtilityVM) RemoveSCSIDisk ¶
func (*UtilityVM) RemoveVPMemDevice ¶
func (*UtilityVM) RemoveVSMB ¶
func (*UtilityVM) SetCPUGroup ¶
func (*UtilityVM) StartedTime ¶
StartedTime returns the time when the utility VM entered the running state.
func (*UtilityVM) StoppedTime ¶
StoppedTime returns the time when the utility VM entered the stopped state.
func (*UtilityVM) UpdateCPULimits ¶
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 ¶
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.