Netwerk settings aanpassen

Het onderstaande script kun je gebruiken om binnen vmware de settings van een port group aan te passen, verder zal voordat het script iets doet eerst om je gebruikersnaam en password vragen (wel zo nettjes :-))

De opties die door dit script worden aangepast zijn notify switches (voor gebruik van unicast NLB binnen VMware) en de netwerk kaart volgorde, deze aanpassen wordt meestal gedaan als je 2 netwerk kaarten op een vswitch gebruikt en je bijvoorbeeld NFS op kaart 1 als voorkeur wil gebruiken en bijvoorbeeld de eerste iSCSI op de andere kaart.

Add-PSSnapin -Name "VMware.VimAutomation.core"

[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')

$userename = [Microsoft.VisualBasic.Interaction]::InputBox("Enter your ADMIN userename", "userename", "")

$userename="<ad domein>\$userename"

$userename

[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')

$password = [Microsoft.VisualBasic.Interaction]::InputBox("Enter your ADMIN password", "password", "")

Connect-VIServeR -Server:<vcenter server> -User $userename -Password $password

$esxhostname = "<vmware host>"

###NLB Portgroup aanpassing voor NLB poorten (NotifySwitches op no zetten) - Niet meer nodig icm multicast

$nlbpoorten=Get-VirtualPortGroup -VMHost $esxhostname -Name "*<aan te passen netwerk label>*"

foreach ($nlb in $nlbpoorten)

{

$HS = Get-View -ViewType "HostSystem" -Filter @{"Name" = $esxhostname}

$nwSys = $HS.ConfigManager.NetworkSystem

$nwSys

$mor = Get-View $nwSys

$mor

$portgropspec = New-Object VMware.Vim.HostPortGroupSpec

$portgropspec.vswitchName = $nlb.VirtualSwitchName

$portgropspec.Name = $nlb.name

$portgropspec.VlanId = $nlb.vlanId

$portgropspec.Policy = New-Object VMware.Vim.HostNetworkPolicy

$portgropspec.Policy.NicTeaming = New-Object VMware.Vim.HostNicTeamingPolicy

$portgropspec.Policy.NicTeaming.failureCriteria = New-Object VMware.Vim.HostNicFailureCriteria

$portgropspec.Policy.NicTeaming.NotifySwitches = $false #aanpassen notify swithes settings

#aanpassen netwerk switche volgorde

$portgropspec.Policy.NicTeaming.NicOrder = New-Object VMware.Vim.HostNicOrderPolicy

$portgropspec.Policy.NicTeaming.NicOrder.ActiveNic = ("vmnic4","vmnic2")

$mor.updatePortGroup($nlb.name,$portgropspec)

}

van de site: http://www.rtfm-ed.co.uk/2009/08/12/wee-bit-of-vmware-powershell-standard-vswitches/

is de onderstaande code gekopieerd zodat je kan zien welke settings je kan aanpassen en hoe de code ervan er uit ziet, let op dat de code hier op vswitch de zaken aanpast en niet op port group zoals hier boven.

Natuurlijk is dit makkelijk om te bouwen.

The script is a bit lengthy, because it covers every setting you could possible want to configure in network dialog box. For example, in this sample below – the standard settings are left untouch – except I’m changing the vSwitch to use IP Hash as the load balancing value using the “loadbalance_ip” parameter…

param ( [string]$VMHostName, [string]$VSwitchName )

$vmhost = Get-VMHost $VMHostName

$hostview = $vmhost | Get-View

$ns = Get-View -Id $hostview.ConfigManager.NetworkSystem

$vsSpec = New-Object VMware.Vim.HostVirtualSwitchSpec

$vsSPec.Bridge = New-Object VMware.Vim.HostVirtualSwitchBondBridge

$vsSPec.Bridge.Beacon = New-Object VMware.Vim.HostVirtualSwitchBeaconConfig

$vsSPec.Bridge.Beacon.Interval = 1

$vsSPec.Bridge.NicDevice = (“vmnic2″,”vmnic1″)

$vsSpec.Mtu = 0

$vsSpec.numPorts = 64

$vsSpec.Policy = New-Object VMware.Vim.HostNetworkPolicy

$vsSpec.Policy.NicTeaming = New-Object VMware.Vim.HostNicTeamingPolicy

$vsSpec.Policy.NicTeaming.FailureCriteria = New-Object VMware.Vim.HostNicFailureCriteria

$vsSpec.Policy.NicTeaming.FailureCriteria.checkBeacon = $false

$vsSpec.Policy.NicTeaming.FailureCriteria.checkDuplex = $false

$vsSpec.Policy.NicTeaming.FailureCriteria.checkErrorPercent = $false

$vsSpec.Policy.NicTeaming.FailureCriteria.checkSpeed = “minimum”

$vsSpec.Policy.NicTeaming.FailureCriteria.fullDuplex = $false

$vsSpec.Policy.NicTeaming.FailureCriteria.Percentage = 0

$vsSpec.Policy.NicTeaming.FailureCriteria.Speed = 10

$vsSpec.Policy.NicTeaming.NicOrder = New-Object VMware.Vim.HostNicOrderPolicy

$vsSpec.Policy.NicTeaming.NicOrder.ActiveNic = (“vmnic1″,”vmnic2″)

$vsSpec.Policy.NicTeaming.NotifySwitches = $true

$vsSpec.Policy.NicTeaming.Policy = “loadbalance_ip“

$vsSpec.Policy.NicTeaming.ReversePolicy = $true

$vsSpec.Policy.NicTeaming.RollingOrder = $false

$vsSpec.Policy.OffloadPolicy = New-Object VMware.Vim.HostNetOffloadCapabilities

$vsSpec.Policy.OffloadPolicy.CsumOffload = $true

$vsSpec.Policy.OffloadPolicy.TcpSegmentation = $true

$vsSpec.Policy.OffloadPolicy.ZeroCopyXmit = $true

$vsSpec.Policy.Security = New-Object VMware.Vim.HostNetworkSecurityPolicy

$vsSpec.Policy.Security.AllowPromiscuous = $false

$vsSpec.Policy.Security.ForgedTransmits = $true

$vsSpec.Policy.Security.MacChanges = $true

$vsSpec.Policy.ShapingPolicy = New-Object VMware.Vim.HostNetworkTrafficShapingPolicy

$vsSpec.Policy.ShapingPolicy.AverageBandwidth = 0

$vsSpec.Policy.ShapingPolicy.BurstSize = 0

$vsSpec.Policy.ShapingPolicy.Enabled = $false

$vsSpec.Policy.ShapingPolicy.PeakBandwidth = 0

$ns.UpdateVirtualSwitch($VSwitchName,$vsSpec)

In this example, the vSwitch is setup to be in a Explicit Failover Order mode, with vmnic1 being the Active Adapter, and vmnic2 being the standby adapter. Additionally the number of ports was increase to 128 (sic 120) and rigious security settings

param ( [string]$VMHostName, [string]$VSwitchName )

$vmhost = Get-VMHost $VMHostName

$hostview = $vmhost | Get-View

$ns = Get-View -Id $hostview.ConfigManager.NetworkSystem

$vsSpec = New-Object VMware.Vim.HostVirtualSwitchSpec

$vsSPec.Bridge = New-Object VMware.Vim.HostVirtualSwitchBondBridge

$vsSPec.Bridge.Beacon = New-Object VMware.Vim.HostVirtualSwitchBeaconConfig

$vsSPec.Bridge.Beacon.Interval = 1

$vsSPec.Bridge.NicDevice = (“vmnic2″,”vmnic1″)

$vsSpec.Mtu = 0

$vsSpec.numPorts = 128

$vsSpec.Policy = New-Object VMware.Vim.HostNetworkPolicy

$vsSpec.Policy.NicTeaming = New-Object VMware.Vim.HostNicTeamingPolicy

$vsSpec.Policy.NicTeaming.FailureCriteria = New-Object VMware.Vim.HostNicFailureCriteria

$vsSpec.Policy.NicTeaming.FailureCriteria.checkBeacon = $false

$vsSpec.Policy.NicTeaming.FailureCriteria.checkDuplex = $false

$vsSpec.Policy.NicTeaming.FailureCriteria.checkErrorPercent = $false

$vsSpec.Policy.NicTeaming.FailureCriteria.checkSpeed = “minimum”

$vsSpec.Policy.NicTeaming.FailureCriteria.fullDuplex = $false

$vsSpec.Policy.NicTeaming.FailureCriteria.Percentage = 0

$vsSpec.Policy.NicTeaming.FailureCriteria.Speed = 10

$vsSpec.Policy.NicTeaming.NicOrder = New-Object VMware.Vim.HostNicOrderPolicy

$vsSpec.Policy.NicTeaming.NicOrder.ActiveNic = (“vmnic1″)

$vsSpec.Policy.NicTeaming.nicOrder.standbyNic = (“vmnic2″)

$vsSpec.Policy.NicTeaming.NotifySwitches = $true

$vsSpec.Policy.NicTeaming.Policy = “failover_explicit”

$vsSpec.Policy.NicTeaming.ReversePolicy = $true

$vsSpec.Policy.NicTeaming.RollingOrder = $true

$vsSpec.Policy.OffloadPolicy = New-Object VMware.Vim.HostNetOffloadCapabilities

$vsSpec.Policy.OffloadPolicy.CsumOffload = $true

$vsSpec.Policy.OffloadPolicy.TcpSegmentation = $true

$vsSpec.Policy.OffloadPolicy.ZeroCopyXmit = $true

$vsSpec.Policy.Security = New-Object VMware.Vim.HostNetworkSecurityPolicy

$vsSpec.Policy.Security.AllowPromiscuous = $false

$vsSpec.Policy.Security.ForgedTransmits = $false

$vsSpec.Policy.Security.MacChanges = $false

$vsSpec.Policy.ShapingPolicy = New-Object VMware.Vim.HostNetworkTrafficShapingPolicy

$vsSpec.Policy.ShapingPolicy.AverageBandwidth = 0

$vsSpec.Policy.ShapingPolicy.BurstSize = 0

$vsSpec.Policy.ShapingPolicy.Enabled = $false

$vsSpec.Policy.ShapingPolicy.PeakBandwidth = 0

$ns.UpdateVirtualSwitch($VSwitchName,$vsSpec)