Documentation ¶
Index ¶
- Constants
- type Manager
- func (m *Manager) CreateVMSwitch(name string) (VirtualSwitch, error)
- func (m *Manager) GetVMSwitch(switchID string) (VirtualSwitch, error)
- func (m *Manager) GetVMSwitchByName(name string) ([]VirtualSwitch, error)
- func (m *Manager) ListVMSwitches() ([]VirtualSwitch, error)
- func (m *Manager) Release()
- func (m *Manager) RemoveVMSwitch(switchID string) error
- type NetAdapter
- type NetAdapterState
- type NetIPAddress
- type PowerManagementCapability
- type VirtualSwitch
- func (v VirtualSwitch) ClearExternalPort() (bool, error)
- func (v VirtualSwitch) ClearInternalPort() (bool, error)
- func (v VirtualSwitch) ID() (string, error)
- func (v VirtualSwitch) Name() (string, error)
- func (v VirtualSwitch) Path() (string, error)
- func (v VirtualSwitch) SetExternalPort(interfaceID string) error
- func (v VirtualSwitch) SetInternalPort() error
- func (v VirtualSwitch) SetNAT(cird string) error
- func (v VirtualSwitch) SetName(newName string) error
Constants ¶
const ( ExternalPort = "Msvm_ExternalEthernetPort" ComputerSystem = "Msvm_ComputerSystem" VMSwitchClass = "Msvm_VirtualEthernetSwitch" VMSwitchSettings = "Msvm_VirtualEthernetSwitchSettingData" VMSwitchManagementService = "Msvm_VirtualEthernetSwitchManagementService" WIFIPort = "Msvm_WiFiPort" EthernetSwitchPort = "Msvm_EthernetSwitchPort" PortAllocSetData = "Msvm_EthernetPortAllocationSettingData" PortVLANSetData = "Msvm_EthernetSwitchPortVlanSettingData" PortSecuritySetData = "Msvm_EthernetSwitchPortSecuritySettingData" PortAllocACLSetData = "Msvm_EthernetSwitchPortAclSettingData" PortExtACLSetData = PortAllocACLSetData LANEndpoint = "Msvm_LANEndpoint" CIMResAllocSettingDataClass = "CIM_ResourceAllocationSettingData" StateDisabled = 3 OperationModeAccess = 1 OperationModeTrunk = 2 ETHConnResSubType = "Microsoft:Hyper-V:Ethernet Connection" NetAdapterClass = "MSFT_NetAdapter" )
Hyper-V networking constants
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager offers a root\virtualization\v2 instance connection and an instance of Msvm_VirtualEthernetSwitchManagementService
func NewVMSwitchManager ¶
NewVMSwitchManager returns a new Manager type
func (*Manager) CreateVMSwitch ¶
func (m *Manager) CreateVMSwitch(name string) (VirtualSwitch, error)
CreateVMSwitch will create a new private VM Switch. To convert it into an internal or external VMSwitch, call the SetInternalPort() and SetExternalPort() functions. Calling SetInternalPort() on a private switch will turn it into an "internal" switch. An internal switch will only facilitate traffic between VMs attached to it and the Host operating system. Attaching an internal port means the OS can manage the IP settings of the switch. Calling SetExternalPort() will attach an physical or virtual net adapter to the VM switch. This will allow trafic to flow through that interface, making it an external VM switch. If both SetInternalPort() and SetExternalPort() are called, the switch becomes an external VM switch with management OS, inheriting the IP settings of the external net adapter attached to the switch.
func (*Manager) GetVMSwitch ¶
func (m *Manager) GetVMSwitch(switchID string) (VirtualSwitch, error)
GetVMSwitch returns a *VirtualSwitch given the ID of the switch
func (*Manager) GetVMSwitchByName ¶
func (m *Manager) GetVMSwitchByName(name string) ([]VirtualSwitch, error)
GetVMSwitchByName will return a list of VM switches that have the specified name. VM switch names are non unique, so we return a list.
func (*Manager) ListVMSwitches ¶
func (m *Manager) ListVMSwitches() ([]VirtualSwitch, error)
ListVMSwitches returns a list ov virtual switches
func (*Manager) RemoveVMSwitch ¶
RemoveVMSwitch will delete a VMSwitch
type NetAdapter ¶
type NetAdapter struct { Caption string Description string Name string Status string Availability uint16 CreationClassName string DeviceID string ErrorCleared bool ErrorDescription string LastErrorCode uint32 PNPDeviceID string PowerManagementCapabilities []PowerManagementCapability PowerManagementSupported bool StatusInfo uint16 SystemCreationClassName string SystemName string Speed string MaxSpeed uint64 RequestedSpeed uint64 UsageRestriction uint16 PortType uint16 OtherPortType string OtherNetworkPortType string PortNumber int32 LinkTechnology uint16 OtherLinkTechnology string PermanentAddress string NetworkAddresses []string FullDuplex bool AutoSense bool SupportedMaximumTransmissionUnit uint64 ActiveMaximumTransmissionUnit string InterfaceDescription string InterfaceName string NetLuid string InterfaceGUID string InterfaceIndex int32 DeviceName string NetLuidIndex int32 Virtual bool Hidden bool NotUserRemovable bool IMFilter bool InterfaceType int32 HardwareInterface bool WdmInterface bool EndPointInterface bool ISCSIInterface bool State int32 NdisMedium int32 NdisPhysicalMedium int32 InterfaceOperationalStatus int32 OperationalStatusDownDefaultPortNotAuthenticated bool OperationalStatusDownMediaDisconnected bool OperationalStatusDownInterfacePaused bool OperationalStatusDownLowPowerState bool InterfaceAdminStatus int32 MediaConnectState int32 MtuSize int32 VlanID int16 TransmitLinkSpeed string ReceiveLinkSpeed string PromiscuousMode bool DeviceWakeUpEnable bool ConnectorPresent bool MediaDuplexState int32 DriverDate string DriverDateData string DriverVersionString string DriverName string DriverDescription string MajorDriverVersion int32 MinorDriverVersion int32 DriverMajorNdisVersion uint8 DriverMinorNdisVersion uint8 PnPDeviceID string DriverProvider string ComponentID string LowerLayerInterfaceIndices []int32 HigherLayerInterfaceIndices []int32 AdminLocked bool // contains filtered or unexported fields }
NetAdapter is the equivalent of MSFT_NetAdapter. More info here: https://msdn.microsoft.com/en-us/library/hh968170%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
func GetNetworkAdapters ¶
func GetNetworkAdapters(name ...string) ([]NetAdapter, error)
GetNetworkAdapters returns a list of network adapters
func (*NetAdapter) Disable ¶
func (n *NetAdapter) Disable() error
Disable will disable this net adapter
func (*NetAdapter) GetIPAddresses ¶
func (n *NetAdapter) GetIPAddresses() ([]NetIPAddress, error)
GetIPAddresses returns an array of NetIPAddress for this adapter
func (*NetAdapter) Rename ¶
func (n *NetAdapter) Rename(name string) error
Rename will set a new name to this net adapter
type NetAdapterState ¶
type NetAdapterState int32
NetAdapterState is the plug and play state of the network adapter.
const ( AdapterUnknown NetAdapterState = iota AdapterPresent AdapterStarted AdapterDisabled )
These are the values for the PnP adapter states. Details at: https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/hh968170(v%3Dvs.85)
type NetIPAddress ¶
type NetIPAddress struct { InstanceID string Caption string ElementName string InstallDate string StatusDescriptions []string Status string HealthState uint16 CommunicationStatus uint16 DetailedStatus uint16 OperatingStatus uint16 PrimaryStatus uint16 OtherEnabledState string RequestedState int32 EnabledDefault int32 SystemCreationClassName string SystemName string CreationClassName string Description string Name string OperationalStatus []uint16 EnabledState uint16 TimeOfLastStateChange string NameFormat string ProtocolType uint16 OtherTypeDescription string ProtocolIFType int32 IPv4Address string IPv6Address string Address string SubnetMask string PrefixLength uint8 AddressType uint16 IPVersionSupport uint16 AddressOrigin int32 InterfaceIndex int32 InterfaceAlias string IPAddress string AddressFamily int32 Type uint8 Store uint8 PrefixOrigin int32 SuffixOrigin int32 AddressState int32 ValidLifetime string PreferredLifetime string SkipAsSource bool }
NetIPAddress is a representation of the MSFT_NetIPAddress cim class: https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/hh872425(v%3Dvs.85)
func GetNetIPAddresses ¶
func GetNetIPAddresses(index int) ([]NetIPAddress, error)
GetNetIPAddresses returns IP addresses for a particular network adapter.
type PowerManagementCapability ¶
type PowerManagementCapability uint16
PowerManagementCapability represents an adapters power management capabilities.
const ( Unknown PowerManagementCapability = iota NotSupported Disabled Enabled AutoPowerSavings PowerStateSettable PowerCycling TimedPowerOn )
Power management capabilities for net adapters. For details see: https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/hh968170(v%3Dvs.85)
type VirtualSwitch ¶
type VirtualSwitch struct {
// contains filtered or unexported fields
}
VirtualSwitch represents one virtual switch
func (VirtualSwitch) ClearExternalPort ¶
func (v VirtualSwitch) ClearExternalPort() (bool, error)
ClearExternalPort will attach an external ethernet port to this switch. This operation will make this VMswitch an "external" VM switch.
func (VirtualSwitch) ClearInternalPort ¶
func (v VirtualSwitch) ClearInternalPort() (bool, error)
ClearInternalPort will remove the internal port from this switch, disabling the management OS.
func (VirtualSwitch) ID ¶
func (v VirtualSwitch) ID() (string, error)
ID returns the ID of the switch
func (VirtualSwitch) Name ¶
func (v VirtualSwitch) Name() (string, error)
Name returns the name of the switch
func (VirtualSwitch) Path ¶
func (v VirtualSwitch) Path() (string, error)
Path returns the WMI locator path of this switch
func (VirtualSwitch) SetExternalPort ¶
func (v VirtualSwitch) SetExternalPort(interfaceID string) error
SetExternalPort will attach an external ethernet port to this switch. This operation will make this VMswitch an "external" VM switch.
func (VirtualSwitch) SetInternalPort ¶
func (v VirtualSwitch) SetInternalPort() error
SetInternalPort will create an internal port which will allow the OS to manage this switches network settings.
func (VirtualSwitch) SetNAT ¶
func (v VirtualSwitch) SetNAT(cird string) error
SetNAT will enable NAT on an "internal" VM switch. This mode is not supported on older versions of Windows.
func (VirtualSwitch) SetName ¶
func (v VirtualSwitch) SetName(newName string) error
SetName renames the switch.