Another post from our Dutch VMUG Event 2011 presentation. This time it’s about number 5 in the Top-10, Network I/O Control. This feature allows user-defined network resource pools and end-to-end QoS.
Note that this feature requires distributed Switches (dvSwitch). In fact I could have also written this post in my dvSwitch series with the title dvSwitch scripting – Part 10 – NetIOC.
The script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
function New-dvSwNetworkResourcePool{ <# .SYNOPSIS Create a user-defined network resource pool .DESCRIPTION The function will create a user-defined resourcepool on a specific dvSwitch. .NOTES Author: Luc Dekens .PARAMETER dvSw The dvSwitch on which the user-defined network resource pool will be created. .PARAMETER Name The name of the user-defined network resource pool. .PARAMETER Description The description of the user-defined network resource pool. .PARAMETER QoSTag The QoSTag that will be assigned to the user-defined network resource pool. A value from the range 0-7. .PARAMETER Limit The QoSTag that will be assigned to the user-defined network resource pool. A value from the range 0-7. .PARAMETER Shares The number of shares allocated. Can be "low","normal","high" or a number (a relative value compared with the shares value on other resource pools in case of contention) .EXAMPLE PS> New-dvSwNetworkResourcePool -dvSw $dvSw -Name "NetPool1" ` PS>> -Description "Dutch VMUG 2011" .EXAMPLE PS> New-dvSwNetworkResourcePool -dvSw $dvSw -Name "NetPool2" ` PS>> -Description "Dutch VMUG 2011" -Shares 75 -QoSTag 3 #> param( [parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)] [VMware.Vim.VmwareDistributedVirtualSwitch]$dvSw, [parameter(Position = 1, Mandatory = $true)] [string]$Name, [parameter(Position = 2)] [string]$Description, [string]$QoSTag, [long]$Limit = -1, [string]$Shares = "normal" ) $spec = New-Object VMware.Vim.DVSNetworkResourcePoolConfigSpec $spec.Name = $Name $spec.Description = $Description $spec.Key = "dummy" $spec.allocationInfo = New-Object VMware.Vim.DVSNetworkResourcePoolAllocationInfo $spec.allocationInfo.Limit = $Limit $spec.allocationInfo.priorityTag = &{if($QoSTag){[int]$QoSTag}} $spec.allocationInfo.Shares = New-Object VMware.Vim.SharesInfo if("high","low","normal" -contains $Shares){ $spec.allocationInfo.Shares.Level = $Shares } else{ $spec.allocationInfo.Shares.Level = "custom" $spec.allocationInfo.Shares.Shares = [int]$Shares } $dvSw.AddNetworkResourcePool(@($spec)) } function Remove-dvSwNetworkResourcePool{ <# .SYNOPSIS Remove a user-defined network resource pool .DESCRIPTION The function will remove a user-defined resource pool from a specific dvSwitch. .NOTES Author: Luc Dekens .PARAMETER dvSw The dvSwitch on which the user-defined network resource pool shall be removed. .PARAMETER Name The name of the user-defined network resource pool. .EXAMPLE PS> Remove-dvSwNetworkResourcePool -dvSw $dvSw -Name "NetPool1" #> param( [parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)] [VMware.Vim.VmwareDistributedVirtualSwitch]$dvSw, [parameter(Position = 1, Mandatory = $true)] [string]$Name ) $pool = $dvSw.NetworkResourcePool | where {$_.Name -eq $Name} if($pool){ $dvSw.RemoveNetworkResourcePool($pool.Key) } } function Get-dvSwNetworkResourcePool{ <# .SYNOPSIS Retrieve user-defined network resource pool(s) .DESCRIPTION The function return all or a specific set of user-defined network resource pools from a dvSwitch .NOTES Author: Luc Dekens .PARAMETER dvSw The dvSwitch from which the user-defined network resource pool shall be retrieved. .PARAMETER Name The name of the user-defined network resource pool. If no name is specified, all user-defined network resource pools on the dvSwitch will be returned. .EXAMPLE PS> Get-dvSwNetworkResourcePool -dvSw $dvSw .EXAMPLE PS> Get-dvSwNetworkResourcePool -dvSw $dvSw -Name "Net*" #> param( [parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)] [VMware.Vim.VmwareDistributedVirtualSwitch]$dvSw, [parameter(Position = 1)] [string]$Name = "*" ) $dvSw.UpdateViewData() $dvSw.NetworkResourcePool | where {$_.Name -like $Name} | %{ New-Object PSObject -Property @{ Name = $_.Name Description = $_.Description Limit = $_.AllocationInfo.Limit QoSTag = &{if($_.AllocationInfo.PriorityTag -eq 0){"none"}else{$_.AllocationInfo.PriorityTag}} Shares = &{if($_.AllocationInfo.Shares.Level -eq "custom"){$_.AllocationInfo.Shares.Shares}else{$_.AllocationInfo.Shares.Level}} } } } function Set-dvSwSIOC{ <# .SYNOPSIS Enable/disable NetIOC on a dvSw .DESCRIPTION The function will enable or disable I/O Control on a dvSwitch .NOTES Author: Luc Dekens .PARAMETER dvSw The dvSwitch on which I/O Control will be enabled/disabled .PARAMETER Enabled A switch that allows control of I/O Control. When the switch is $True, IOC will be enabled. If $False IOC will be disabled .EXAMPLE PS> Set-dvSwSIOC -dvSw $dvSw -Enabled #> param( [parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)] [VMware.Vim.VmwareDistributedVirtualSwitch]$dvSw, [parameter(Position = 1)] [switch]$Enabled ) $dvSw.EnableNetworkResourceManagement($Enabled) } function Get-dvSwSIOC{ <# .SYNOPSIS Retrieve the IOC status .DESCRIPTION Returns the status of IOC on a dvSwitch .NOTES Author: Luc Dekens .PARAMETER dvSw The dvSwitch from which the status of I/O Control will be returned .EXAMPLE PS> Get-dvSwSIOC -dvSw $dvSw -Enabled #> param( [parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)] [VMware.Vim.VmwareDistributedVirtualSwitch]$dvSw ) $dvSw.UpdateViewData() New-Object PSObject -Property @{ Name = $dvSw.Name SIOCEnabled = $dvSw.Config.NetworkResourceManagementEnabled } } |
Annotations
Line 38: Although the QosTag is an [int], we use the [string] cast. Otherwise the absence of the parameter would set QosTag to 0, which is a valid 802.1p value.
Line 38-40: The absence of these 3 parameters on a call to the function will create a user-defined network resource pool with the same settings as if the resource pool was created in the vSphere Client.
Line 51-57: If the Shares parameter is not set to “normal”, “high” or “low”, it will be set to “custom” and the Shares value will be used as an [int] value.
Line 80: The removal of a user-defined network resource pool requires the Name parameter to be set.
Line 111: If no Name parameter is used, all the user-defined network resource pools on the dvSwitch will be returned.
Line 114: To get the most recent data, the script refreshes the dvSwitch object.
Line 120: This test will make sure, that the function returns the same values as displayed in the vSphere Client.
Line 121: When the Shares level is “custom”, the [int] value of the share will be returned.
Sample usage
We start with an empty dvSwitch. The Get-dvSwitch function can be found in my dvSwitch scripting – Part 2 – dvPortgroup post.
First we get the dvSwitch and we get a list of the current network resource pools.
1 2 |
$dvSw = Get-dvSwitch -DatacenterName "DC1" -dvSwitchName "dvSw1" Get-dvSwNetworkResourcePool -dvSw $dvSw | ft -AutoSize |
This will return the system network resource pools.
The same information as we can see in the vSphere Client under System network resource pools.
Note that NetIOC is not enabled by default.
Next we create a number of user-defined network resource pools.
1 2 3 4 |
New-dvSwNetworkResourcePool -dvSw $dvSw -Name "NetPool1" -Description "Dutch VMUG 2011" New-dvSwNetworkResourcePool -dvSw $dvSw -Name "NetPool2" -Description "Dutch VMUG 2011" -Shares 75 -QoSTag 3 New-dvSwNetworkResourcePool -dvSw $dvSw -Name "NetPool3" -Description "Dutch VMUG 2011" -Limit 4500 Get-dvSwNetworkResourcePool -dvSw $dvSw | ft -AutoSize |
The result shows the 3 newly created network resource pools.
And we see the same in the vSphere Client.
As we noticed earlier, NetIOC is not enabled by default. Let’s display the current setting.
1 |
Get-dvSwSIOC -dvSw $dvSw | ft -AutoSize |
We change the setting and retrieve the value again
1 2 |
Set-dvSwSIOC -dvSw $dvSw -Enabled Get-dvSwSIOC -dvSw $dvSw | ft -AutoSize |
This gives
To conclude we will clean up the demo pools and disable NetIOC again.
1 2 3 4 5 |
Set-dvSwSIOC -dvSw $dvSw -Enabled:$false Remove-dvSwNetworkResourcePool -dvSw $dvSw -Name "NetPool1" Remove-dvSwNetworkResourcePool -dvSw $dvSw -Name "NetPool2" Remove-dvSwNetworkResourcePool -dvSw $dvSw -Name "NetPool3" |
Enjoy !