Documentation ¶
Index ¶
- Constants
- type BootOrderType
- type DriveType
- type GenerationType
- type Manager
- type PowerState
- type SCSIController
- func (s *SCSIController) AttachDrive(path string, driveType DriveType) (string, error)
- func (s *SCSIController) AttachDriveToAddress(path string, driveType DriveType, address int) (string, error)
- func (s *SCSIController) AttachedDevices() (map[int]string, error)
- func (s *SCSIController) EmptySlots() ([]int, error)
- func (s *SCSIController) Path() string
- type VirtualMachine
- func (v *VirtualMachine) AddVnic(name, mac string) (*Vnic, error)
- func (v *VirtualMachine) AttachDisks(disks []string) error
- func (v *VirtualMachine) CreateNewSCSIController() (string, error)
- func (v *VirtualMachine) GetSCSIControllers() ([]SCSIController, error)
- func (v *VirtualMachine) GetVnic(name string) (Vnic, error)
- func (v *VirtualMachine) ID() (string, error)
- func (v *VirtualMachine) ListVnics() ([]Vnic, error)
- func (v *VirtualMachine) Name() (string, error)
- func (v *VirtualMachine) RemoveVnic(name string) error
- func (v *VirtualMachine) SetBootOrder(bootOrder []int32) error
- func (v *VirtualMachine) SetCPUs(cpus int, limitCPUFeatures bool) error
- func (v *VirtualMachine) SetMemory(memoryMB int64) error
- func (v *VirtualMachine) SetPowerState(state PowerState) error
- type Vnic
Constants ¶
const ( VMManagementService = "Msvm_VirtualSystemManagementService" SettingsDefineStateClass = "Msvm_SettingsDefineState" // _SETTINGS_DEFINE_STATE_CLASS VirtualSystemSettingDataClass = "Msvm_VirtualSystemSettingData" // _VIRTUAL_SYSTEM_SETTING_DATA_CLASS ResourceAllocSettingDataClass = "Msvm_ResourceAllocationSettingData" // _RESOURCE_ALLOC_SETTING_DATA_CLASS ProcessorSettingDataClass = "Msvm_ProcessorSettingData" // _PROCESSOR_SETTING_DATA_CLASS MemorySettingDataClass = "Msvm_MemorySettingData" // _MEMORY_SETTING_DATA_CLASS SyntheticEthernetPortSettingDataClass = "Msvm_SyntheticEthernetPortSettingData" // _SYNTHETIC_ETHERNET_PORT_SETTING_DATA_CLASS EmulatedEthernetPortSettingDataClass = "Msvm_EmulatedEthernetPortSettingData" // _EMULATED_ETHERNET_PORT_SETTING_DATA_CLASS AffectedJobElementClass = "Msvm_AffectedJobElement" // _AFFECTED_JOB_ELEMENT_CLASS ShutdownComponentClass = "Msvm_ShutdownComponent" // _SHUTDOWN_COMPONENT StorageAllocSettingDataClass = "Msvm_StorageAllocationSettingData" // _STORAGE_ALLOC_SETTING_DATA_CLASS EthernetPortAllocationSettingDataClass = "Msvm_EthernetPortAllocationSettingData" // _ETHERNET_PORT_ALLOCATION_SETTING_DATA_CLASS SerialPortSettingDataClass = "Msvm_SerialPortSettingData" // _TH_SERIAL_PORT_SETTING_DATA_CLASS ComputerSystemClass = "Msvm_ComputerSystem" )
Hyper-V virtual machine specific constants
const ( PhysDiskResSubType = "Microsoft:Hyper-V:Physical Disk Drive" // _PHYS_DISK_RES_SUB_TYPE DiskResSubtype = "Microsoft:Hyper-V:Synthetic Disk Drive" // _DISK_RES_SUB_TYPE DVDResSubType = "Microsoft:Hyper-V:Synthetic DVD Drive" // _DVD_RES_SUB_TYPE SCSIResSubType = "Microsoft:Hyper-V:Synthetic SCSI Controller" // _SCSI_RES_SUBTYPE IDEDiskResSubType = "Microsoft:Hyper-V:Virtual Hard Disk" // _IDE_DISK_RES_SUB_TYPE IDEDVDResSubType = "Microsoft:Hyper-V:Virtual CD/DVD Disk" // _IDE_DVD_RES_SUB_TYPE IDEControllerResSubType = "Microsoft:Hyper-V:Emulated IDE Controller" // _IDE_CTRL_RES_SUB_TYPE SCSIControllerResSubType = "Microsoft:Hyper-V:Synthetic SCSI Controller" // _SCSI_CTRL_RES_SUB_TYPE VFDDriveResSubType = "Microsoft:Hyper-V:Synthetic Diskette Drive" // _VFD_DRIVE_RES_SUB_TYPE VFDDiskResSubType = "Microsoft:Hyper-V:Virtual Floppy Disk" // _VFD_DISK_RES_SUB_TYPE SerialPortResSubType = "Microsoft:Hyper-V:Serial Port" // _SERIAL_PORT_RES_SUB_TYPE VirtualSystemTypeRealized = "Microsoft:Hyper-V:System:Realized" // _VIRTUAL_SYSTEM_TYPE_REALIZED )
Device resource and subtypes
const ( StartupNone = 2 // _AUTO_STARTUP_NONE StartupRestartActive = 3 // _AUTO_STARTUP_RESTART_ACTIVE )
VM auto startup constants
const ( MetricAggregateCPUAverage = "Aggregated Average CPU Utilization" // _METRIC_AGGR_CPU_AVG MetricEnabled = 2 // _METRIC_ENABLED )
VM Metrics collection constants
const ( VirtualSystemCurrentSettings = 3 // _VIRTUAL_SYSTEM_CURRENT_SETTINGS MaxSCSIControllerSlots = 64 // SCSI_CONTROLLER_SLOTS_NUMBER )
Misc
const (
SnapshotFull = 2 // _SNAPSHOT_FULL
)
Snapshot constant
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BootOrderType ¶
type BootOrderType int32
BootOrderType represents the boot order type
var ( BootFloppy BootOrderType = 0 BootCDROM BootOrderType = 1 BootHDD BootOrderType = 2 BootPXE BootOrderType = 3 )
Boot order entries
type DriveType ¶
type DriveType string
DriveType represents the type of drive that can get attached to an IDE or SCSI controller
var ( DiskDrive DriveType = DiskResSubtype DVDDrive DriveType = DVDResSubType )
Disk drive types
type GenerationType ¶
type GenerationType string
GenerationType defines the VM generation type
var ( Generation1 GenerationType = "Microsoft:Hyper-V:SubType:1" Generation2 GenerationType = "Microsoft:Hyper-V:SubType:2" )
VM generation constants
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager offers a root\virtualization\v2 instance connection and an instance of Msvm_VirtualSystemManagementService
func (*Manager) CreateVM ¶
func (m *Manager) CreateVM(name string, memoryMB int64, cpus int, limitCPUFeatures bool, notes []string, generation GenerationType, secureBoot bool) (*VirtualMachine, error)
CreateVM creates a new virtual machine
func (*Manager) GetVM ¶
func (m *Manager) GetVM(instanceID string) (*VirtualMachine, error)
GetVM returns the virtual machine identified by instanceID
func (*Manager) ListVM ¶
func (m *Manager) ListVM() ([]*VirtualMachine, error)
ListVM returns a list of virtual machines
type PowerState ¶
type PowerState uint16
PowerState is the power state type.
var ( Enabled PowerState = 2 Disabled PowerState = 3 ShuttingDown PowerState = 4 Offline PowerState = 6 Reboot PowerState = 10 Reset PowerState = 11 Quiesce PowerState = 9 Suspended PowerState = 6 )
VM power state constants See: https://docs.microsoft.com/en-us/windows/win32/hyperv_v2/msvm-computersystem
type SCSIController ¶
type SCSIController struct {
// contains filtered or unexported fields
}
SCSIController represents a SCSI controller attached to a VM
func (*SCSIController) AttachDrive ¶
func (s *SCSIController) AttachDrive(path string, driveType DriveType) (string, error)
AttachDrive attaches a new drive to this SCSI controller. The slot is the first free slot available. If no slot is available, an error is returned.
func (*SCSIController) AttachDriveToAddress ¶
func (s *SCSIController) AttachDriveToAddress(path string, driveType DriveType, address int) (string, error)
AttachDriveToAddress attaches a new drive to this SCSI controller, on the specified slot
func (*SCSIController) AttachedDevices ¶
func (s *SCSIController) AttachedDevices() (map[int]string, error)
AttachedDevices returns a list of attached devices to the supplied controller
func (*SCSIController) EmptySlots ¶
func (s *SCSIController) EmptySlots() ([]int, error)
EmptySlots returns a list of empty slot addresses that can be used to attach devices
func (*SCSIController) Path ¶
func (s *SCSIController) Path() string
Path returns the WMI path of this controller
type VirtualMachine ¶
type VirtualMachine struct {
// contains filtered or unexported fields
}
VirtualMachine represents a single virtual machine
func (*VirtualMachine) AddVnic ¶
func (v *VirtualMachine) AddVnic(name, mac string) (*Vnic, error)
AddVnic creates a new virtual NIC on this machine
func (*VirtualMachine) AttachDisks ¶
func (v *VirtualMachine) AttachDisks(disks []string) error
AttachDisks attaches the supplied disks, to this virtual machine
func (*VirtualMachine) CreateNewSCSIController ¶
func (v *VirtualMachine) CreateNewSCSIController() (string, error)
CreateNewSCSIController will create a new ISCSI controller on this VM
func (*VirtualMachine) GetSCSIControllers ¶
func (v *VirtualMachine) GetSCSIControllers() ([]SCSIController, error)
GetSCSIControllers will return a list of SCSI controller paths
func (*VirtualMachine) GetVnic ¶
func (v *VirtualMachine) GetVnic(name string) (Vnic, error)
GetVnic will return the specified VNIC
func (*VirtualMachine) ID ¶
func (v *VirtualMachine) ID() (string, error)
ID returns the instance ID of this Virtual machine
func (*VirtualMachine) ListVnics ¶
func (v *VirtualMachine) ListVnics() ([]Vnic, error)
ListVnics will return a list of all VNICs attached to this VM
func (*VirtualMachine) Name ¶
func (v *VirtualMachine) Name() (string, error)
Name returns the current name of this virtual machine
func (*VirtualMachine) RemoveVnic ¶
func (v *VirtualMachine) RemoveVnic(name string) error
RemoveVnic removed the VNIC from this machine
func (*VirtualMachine) SetBootOrder ¶
func (v *VirtualMachine) SetBootOrder(bootOrder []int32) error
SetBootOrder sets the VM boot order
func (*VirtualMachine) SetCPUs ¶
func (v *VirtualMachine) SetCPUs(cpus int, limitCPUFeatures bool) error
SetCPUs sets the number of CPU cores on the VM
func (*VirtualMachine) SetMemory ¶
func (v *VirtualMachine) SetMemory(memoryMB int64) error
SetMemory sets the virtual machine memory allocation
func (*VirtualMachine) SetPowerState ¶
func (v *VirtualMachine) SetPowerState(state PowerState) error
SetPowerState sets the desired power state on a virtual machine.
type Vnic ¶
type Vnic struct {
// contains filtered or unexported fields
}
Vnic represents a virtual NIC attached to a VM
func (*Vnic) SetAccessVLAN ¶
SetAccessVLAN will set the NIC in mode ACCESS with the specified VLAN ID on the switchport this NIC is connected to.
func (*Vnic) SetModetrunk ¶
SetModetrunk will set this NIC in mode trunk, with the specified native VLAN ID and allowed trunk VLAN IDs