-
Notifications
You must be signed in to change notification settings - Fork 0
/
New-HCINetConfig.ps1
330 lines (300 loc) · 15.1 KB
/
New-HCINetConfig.ps1
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
[CmdletBinding(DefaultParameterSetName = "NoParameters")]
param(
[Parameter(Mandatory = $false, ParameterSetName = "ConfigurationFile")]
[String] $ConfigurationDataFile = ".\configfiles\HCI-NetworkConfig.psd1"
)
# Script version, should be matched with the config files
$ScriptVersion = "2.0"
#Validating passed in config files
if ($psCmdlet.ParameterSetName -eq "ConfigurationFile")
{
Write-host "Using configuration file passed in by parameter."
$configdata = [hashtable] (iex (gc $ConfigurationDataFile | out-string))
}
elseif ($psCmdlet.ParameterSetName -eq "ConfigurationData")
{
Write-host "Using configuration data object passed in by parameter."
$configdata = $configurationData
}
if ($Configdata.ScriptVersion -ne $scriptversion)
{
Write-host "Configuration file $ConfigurationDataFile version $($ConfigData.ScriptVersion) is not compatible with this version of SDN express."
Write-host "Please update your config file to match the version $scriptversion example."
return
}
winrm set winrm/config/client '@{TrustedHosts="*"}'
$LocalAdminCred = Get-Credential $configdata.LocalAdmin -Message "Please provide password for $($configdata.localAdmin) account"
$LocalAdminPassword = $LocalAdminCred.GetNetworkCredential().Password
foreach ( $node in $configdata.nodes)
{
$HypvNode=$node.HypvNode
$username=$configdata.LocalAdmin
$password= $LocalAdminPassword | ConvertTo-SecureString -asPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential("$HypvNode\$username", $password )
Write-Host -ForegroundColor Yellow "########################################"
Write-Host -ForegroundColor Yellow "# Configuring Networking on $HypvNode"
Write-Host -ForegroundColor Yellow "########################################"
invoke-command -ComputerName $HypvNode -Credential $credential {
$configdata=$args[0]
################
#########
##### Checking pNICs
#########
################
Write-Host "- Checking if pNICs are existing and not bound to any vSwitch or holding TCPIP config"
$pNICs=$configdata.pNICs
foreach( $pNIC in $pNICs)
{
if (! (get-netadapter $pNIC.Name -ea SilentlyContinue ))
{
throw "$($pNIC.Name) cannot be found. Please check the name of the interface. Rename-NetAdapter to change his name to $pNIC"
}
else
{
$NicGuid=((Get-NetAdapter $pNIC.Name).InterfaceGuid).replace("{","").replace("}","")
Write-Host "- Checking that pNICs are not bound to any vSwitch"
$CurrentVswitches=Get-VMSwitch -ea SilentlyContinue
foreach( $CurrentvSwitch in $CurrentVswitches)
{
$NicGuids=$CurrentvSwitch.NetAdapterInterfaceGuid
foreach( $Guid in $NicGuids )
{
if ( $Guid -eq $NicGuid)
{
throw "$($pNIC.Name) is already bound to vSwitch $($CurrentvSwitch.Name). Please investigate!"
}
}
}
Write-Host -ForegroundColor Yellow "Reseting NetAdapterAdvancedProperty for $($pNIC.Name)"
reset-netadapteradvancedproperty $pNIC.Name -DisplayName *
}
#
if ( $pNIC.VmmqEnabled )
{
Write-Host -ForegroundColor Yellow "Enabling VMMQ on $($pNIC.Name)"
Set-NetAdapterAdvancedProperty $pNIC.Name -RegistryKeyword "*RssOnHostVPorts" -RegistryValue 1
Write-Host -ForegroundColor Green "Configuring $($pNIC.NumberOfReceiveQueues) Queues on $($pNIC.Name)"
Set-NetAdapterRss $pNIC.Name -NumberOfReceiveQueues $pNIC.NumberOfReceiveQueues
}
else
{
Set-NetAdapterAdvancedProperty $pNIC.Name -RegistryKeyword "*RssOnHostVPorts" -RegistryValue 0
}
#RDMA mode iWARP or ROCe
if ( $pNIC.RDMAEnabled)
{
Write-Host "+ Enabling RDMA/NetworkDirect on $($pNIC.Name)"
Set-NetAdapterAdvancedProperty $pNIC.Name -RegistryKeyword "*NetworkDirect" -RegistryValue 1
if ( $pNIC.RDMAMode -eq "iWARP")
{
Write-Host -ForegroundColor Yellow "+ Enabling iWARP on $($pNIC.Name)"
Set-NetAdapterAdvancedProperty $pNIC.Name -RegistryKeyword "*NetworkDirectTechnology" -RegistryValue 1
}
elseif ( $pNIC.RDMAMode -eq "RoCE")
{
Write-Host -ForegroundColor Yellow "+ Enabling iWARP on $($pNIC.Name)"
Set-NetAdapterAdvancedProperty $pNIC.Name -RegistryKeyword "*NetworkDirectTechnology" -RegistryValue 3
}
elseif ( $pNIC.RDMAMode -eq "RoCEv2")
{
Write-Host -ForegroundColor Yellow "+ Enabling iWARP on $($pNIC.Name)"
Set-NetAdapterAdvancedProperty $pNIC.Name -RegistryKeyword "*NetworkDirectTechnology" -RegistryValue 4
}
else
{
throw "$($pNIC.Name) bad RDMA/NetworkDirect specified in the config File. Valids are iWARP/RoCE/RoCEv2"
}
}
#JumboFRames
if ( $pNIC.JumboFrames )
{
Write-Host "+ Enabling JumboFrame 9K on $($pNIC.Name)"
Set-NetAdapterAdvancedProperty $pNIC.Name -RegistryKeyword "*JumboPacket" -RegistryValue 9014
}
}
################
#########
##### vSwitch configuration
#########
################
$index=0
$vSwitches=$configdata.vSwitches
foreach( $vSwitch in $vSwitches)
{
if ( Get-VMSwitch $vSwitch.Name -ea SilentlyContinue )
{
throw "$($vSwitch.Name) is already existing. Please do cleanup first"
}
else
{
Write-Host -ForegroundColor Yellow "########################################"
Write-Host -ForegroundColor Yellow "# Creating vSwitch $($vSwitch.Name)"
Write-Host -ForegroundColor Yellow "########################################"
New-VmSwitch -Name $vSwitch.name -EnableEmbeddedTeaming $vSwitch.SetEnabled `
-NetAdapterName $vSwitch.pNICs.Name -AllowManagementOS $vSwitch.MgmtOS
if ( ! (Get-VMSwitch $vSwitch.Name -ea SilentlyContinue) )
{
throw "$($vSwitch.Name) creation has failed. Please investigate"
}
#Creating host vNIC
foreach( $HOSTvNIC in $vSwitch.HostvNICs )
{
Write-Host -ForegroundColor Yellow "+ Adding Host vNIC $($HOSTvNIC.Name)"
Add-VMNetworkAdapter -ManagementOS -Name $HOSTvNIC.Name -SwitchName $vSwitch.Name
#To be sure that the vNIC is well created
sleep 10
$NIC = Get-NetAdapter "*$($HOSTvNIC.Name)*"
Write-Host -ForegroundColor Yellow "+ Configure Host vNIC $($HOSTvNIC.Name) IP Configuration $($HOSTvNIC.IpAddr)/$($HOSTvNIC.CIDR)"
$NIC | New-NetIPAddress -IpAddress $HOSTvNIC.IpAddr -PrefixLength $HOSTvNIC.CIDR -DefaultGateway $HOSTvNIC.GW | Out-Null
if ( $HOSTvNIC.DNS )
{
Write-Host -ForegroundColor Yellow "+ Configure Host vNIC $($HOSTvNIC.Name) DNS Srv=$($HOSTvNIC.DNS)"
$vNIC | Set-DnsClientServerAddress -ServerAddresses $HOSTvNIC.DNS
}
if ( $HOSTvNIC.VmmqEnabled )
{
Write-Host "+ Enabling VMMQ on vNIC $($HOSTvNIC.Name)"
Get-VMNetworkAdapter -ManagementOS $HOSTvNIC.Name | Set-VMNetworkAdapter -VmmqEnabled $HOSTvNIC.VmmqEnabled
}
else
{
Get-VMNetworkAdapter -ManagementOS $HOSTvNIC.Name | Set-VMNetworkAdapter -VmmqEnabled $false
}
if ( $HOSTvNIC.RDMAEnabled )
{
Write-Host "+ Enabling RDMA on vNIC $($HOSTvNIC.Name)"
$NIC | Enable-NetAdapterRdma
}
else
{
$NIC | Disable-NetAdapterRdma
}
#JumboFrames
if ( $pNIC.JumboFrames )
{
Write-Host "+ Enabling JumboFrame 9K on $($HOSTvNIC.Name)"
$NIC | Set-NetAdapterAdvancedProperty -RegistryKeyword "*JumboPacket" -RegistryValue 9014
}
Write-Host -ForegroundColor Yellow "+ Rss Config: forcing base proc to 2 for vNIC $($HOSTvNIC.Name)"
$NIC | Set-NetAdapterRss -BaseProcessorGroup 0 -BaseProcessorNumber 2
#### Configuring SwitchTeamMapping
Write-Host -ForegroundColor Yellow "+ Configuring VMNetworkAdapterTeamMapping for $($HOSTvNIC.Name) on $($pNICs.Name[$index])"
Set-VMNetworkAdapterTeamMapping -VMNetworkAdapterName $HostvNIC.Name -ManagementOS `
-PhysicalNetAdapterName $pNICs.Name[$index] | Out-Null
$index++
}
}
}
################
#########
##### RSS/VMQ/VMMQ Configuration
#########
################
$index=0
if ( $configdata.AutoSyntheticAccelerationConfig )
{
Write-Host -ForegroundColor Yellow "########################################"
Write-Host -ForegroundColor Yellow `
"Configuring Synthetic Acceleration: vRSS/VMMQ/VMQ and so on based on NUMA topology and LPs numbers detected!"
Write-Host -ForegroundColor Yellow "########################################"
$LPs=0
$NUMANode=Get-VMHostNumaNode
foreach ( $NUMA in $NUMANode)
{
$LPs+=$NUMA.ProcessorsAvailability.count
}
Write-Host -ForegroundColor Yellow "+ Trying to pin each pNIC to a different Numa Node"
foreach( $pNIC in $configdata.pNICs)
{
if ( $NUMANode.count -gt 1 )
{
Set-NetAdapterAdvancedProperty -Name $pNIC.Name -RegistryKeyword '*NumaNodeId' -RegistryValue $NUMANode.NodeId[$Index]
#
if ( $NUMANode.NodeId[$Index+1] -lt $NumaNode.Count ){ $index++ }
}
get-NetAdapterRss $pNIC.Name | ft
Write-Host -ForegroundColor Yellow "+ VMQ Config: Using all LPs available except LP=0"
Set-NetAdapterVMQ $pNIC.Name -BaseProcessorGroup 0 -BaseProcessorNumber 2 -MaxProcessors $($LPs/2)
get-NetAdapterVMQ $pNIC.Name | ft
Write-Host -ForegroundColor Yellow "+ Rss Config: Setting NumberOfReceiveQueues to $($pNIC.NumberOfReceiveQueues)"
Set-NetAdapterRss $pNIC.Name -NumberOfReceiveQueues $pNIC.NumberOfReceiveQueues
}
}
################
#########
##### Configuring DCB
#########
################
if ( $configdata.DCBEnabled )
{
Write-Host -ForegroundColor Yellow "########################################"
Write-Host -ForegroundColor Yellow "# Configuring DCB on $node"
Write-Host -ForegroundColor Yellow "########################################"
if ( ! (Get-WindowsFeature Data-Center-Bridging).Installed )
{
#Install DCB
Install-WindowsFeature -Name Data-Center-Bridging
}
#Set policy for Cluster Heartbeats
Write-Host -ForegroundColor Yellow "+ Creating Cluster NetQoSPolicy"
New-NetQosPolicy "Cluster" -Cluster -PriorityValue8021Action 7 | Out-Null
New-NetQosTrafficClass "Cluster" -Priority 7 -BandwidthPercentage 1 -Algorithm ETS | Out-Null
#Set policy for SMB-Direct
Write-Host -ForegroundColor Yellow "+ Creating SMB NetQoSPolicy"
New-NetQosPolicy "SMB" -NetDirectPortMatchCondition 445 -PriorityValue8021Action 3 | Out-Null
Enable-NetQosFlowControl -priority 3 | Out-Null
New-NetQosTrafficClass "SMB" -priority 3 -bandwidthpercentage 50 -algorithm ETS | Out-Null
foreach( $pNIC in $pNICs)
{
#Enabling QoS at NetAdapter Level
Write-Host "+ Enabling NetQos on $($pNIC.NAme) adapter"
Enable-NetAdapterQos -InterfaceAlias $pNIC.Name | Out-Null
#Block DCBX settings from the switch
Write-Host "- Disabling NetQosDcbxSetting on $($pNIC.NAme) adapter"
Set-NetQosDcbxSetting -InterfaceAlias $pNIC.Name -Willing $False -Force | Out-Null
#Disable flow control (Global Pause) on physical adapters
Write-Host "+ Disabling IEEE 802.3 FlowControl on $($pNIC.NAme) adapter"
Set-NetAdapterAdvancedProperty -Name $pNIC.Name -RegistryKeyword "*FlowControl" -RegistryValue 0 | Out-Null
}
#Set policy for the rest of the traffic
Write-Host -ForegroundColor Yellow "+ Creating Default traffic NetQoSPolicy"
New-NetQosPolicy "DEFAULT" -Default -PriorityValue8021Action 0 | Out-Null
Disable-NetQosFlowControl -priority 0,1,2,4,5,6,7 | Out-Null
}
} -ArgumentList $node
}
#########
##### Checking cluster nodes connectivity
#########
################
<#
Write-Host -ForegroundColor Yellow "########################################"
Write-Host -ForegroundColor Yellow "# Checking cluster nodes connectivity"
Write-Host -ForegroundColor Yellow "########################################"
foreach ( $node in $configdata.nodes)
{
$username=$configdata.LocalAdmin
$password= $LocalAdminPassword | ConvertTo-SecureString -asPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential("$node\$username", $password )
invoke-command -ComputerName $node -Credential $credential {
$configdata=$args[0]
foreach ( $node in $configdata.nodes)
{
if ( $node -ne $env:COMPUTERNAME)
{
foreach( $vNIC in $configdata[$node].vSwitches.HostvNICs)
{
Write-Host "Checking networking connectivy from $env:computername to $node/$($vNIC.IpAddr)"
if ( Test-Connection $vNIC.IpAddr ){
Write-Host -ForegroundColor Green "Ping is OK!"
}
else
{
Write-Host -ForegroundColor Red "Ping FAILED!"
}
}
}
}
} -ArgumentList $configdata
}
#>