VMware Cloud Community
dawoo
Enthusiast
Enthusiast
Jump to solution

When I set traffic shaping I lose my VLAN ID, how I can I set both?

Hi.

Having 'borrowed' the code to set Traffic Shaping on a Port Group from Alan (Renouf) Virtu-Al it works a treat. I noticed earlier that having set all my port groups up with VLAN IDs the Traffic Shaping overwrites the value of my VMotion Port Group to zero.

Foreach ($PG in ($VMHost | Get-VirtualSwitch -Name "vSwitch0" | Get-VirtualPortGroup))

{

$vswitchName = "vSwitch0"

$pgName = $PG.Name

if ( $pgName -match "vmotion" -eq $true )

{

Write-Host " ---> Found VMotion switch, applying Traffic Shaping policy." -Backgroundcolor Black -ForegroundColor White

$HS = $VMHost | Get-View

$nwSys = $HS.ConfigManager.NetworkSystem

$mor = Get-View $nwSys

$portgrp = New-Object VMware.Vim.HostPortGroupSpec

$portgrp.Name = $pgName

$portgrp.VswitchName = $vswitchName

$portgrp.policy = New-Object VMware.Vim.HostNetworkPolicy

$portgrp.policy.shapingPolicy = New-Object VMware.Vim.HostNetworkTrafficShapingPolicy

$portgrp.policy.shapingPolicy.enabled = $true

$portgrp.policy.shapingPolicy.averageBandwidth = 700000000

$portgrp.policy.shapingPolicy.peakBandwidth = 700000000

$portgrp.policy.shapingPolicy.burstSize = 1

$mor.UpdatePortGroup($pgName, $portgrp)

}

}

I assume there must be a value I add into the $portgroup but I've yet to understand what it is.

Any assistance is appreciated and rewarded with points.

Cheers,

Darren.

10 Print "It's all about the Nerdknobs" , 20 GOTO http://blog.vmote.net/
Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The HostPortGroupSpec object contains the VlanId property and by default it is set to 0 (zero).

Just copy the value from the $PG variable and you should be ok.

$vswitchName = <vswitchname>
$tgtPg = <portgroupname>

foreach ($VMHost in Get-VMHost) { 
	foreach ($PG in ($VMHost | Get-VirtualSwitch -Name $vswitchName | Get-VirtualPortGroup)) { 
		$pgName = $PG.Name
# check virtual switch name, match any spelling variant of vMotion 
		if ( $pgName -match $tgtPg) { 
			Write-Host " ---> Found VMotion switch, applying Traffic Shaping policy." -Backgroundcolor Black -ForegroundColor White 
			$HS = $VMHost | Get-View 
			$nwSys = $HS.ConfigManager.NetworkSystem 
			$mor = Get-View $nwSys 
			$portgrp = New-Object VMware.Vim.HostPortGroupSpec 
			$portgrp.Name = $pgName 
			$portgrp.VswitchName = $vswitchName 
			$portgrp.policy = New-Object VMware.Vim.HostNetworkPolicy 
			$portgrp.policy.shapingPolicy = New-Object VMware.Vim.HostNetworkTrafficShapingPolicy
			$portgrp.policy.shapingPolicy.enabled = $true 
			$portgrp.policy.shapingPolicy.averageBandwidth = 700000000 
			$portgrp.policy.shapingPolicy.peakBandwidth = 700000000 
			$portgrp.policy.shapingPolicy.burstSize = 1 
			$portgrp.VlanId = $PG.VLanId
			$mor.UpdatePortGroup($pgName, $portgrp) 
		} 
	}
}

Btw I changed some other things to optimise the code Smiley Wink

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

The HostPortGroupSpec object contains the VlanId property and by default it is set to 0 (zero).

Just copy the value from the $PG variable and you should be ok.

$vswitchName = <vswitchname>
$tgtPg = <portgroupname>

foreach ($VMHost in Get-VMHost) { 
	foreach ($PG in ($VMHost | Get-VirtualSwitch -Name $vswitchName | Get-VirtualPortGroup)) { 
		$pgName = $PG.Name
# check virtual switch name, match any spelling variant of vMotion 
		if ( $pgName -match $tgtPg) { 
			Write-Host " ---> Found VMotion switch, applying Traffic Shaping policy." -Backgroundcolor Black -ForegroundColor White 
			$HS = $VMHost | Get-View 
			$nwSys = $HS.ConfigManager.NetworkSystem 
			$mor = Get-View $nwSys 
			$portgrp = New-Object VMware.Vim.HostPortGroupSpec 
			$portgrp.Name = $pgName 
			$portgrp.VswitchName = $vswitchName 
			$portgrp.policy = New-Object VMware.Vim.HostNetworkPolicy 
			$portgrp.policy.shapingPolicy = New-Object VMware.Vim.HostNetworkTrafficShapingPolicy
			$portgrp.policy.shapingPolicy.enabled = $true 
			$portgrp.policy.shapingPolicy.averageBandwidth = 700000000 
			$portgrp.policy.shapingPolicy.peakBandwidth = 700000000 
			$portgrp.policy.shapingPolicy.burstSize = 1 
			$portgrp.VlanId = $PG.VLanId
			$mor.UpdatePortGroup($pgName, $portgrp) 
		} 
	}
}

Btw I changed some other things to optimise the code Smiley Wink

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
dawoo
Enthusiast
Enthusiast
Jump to solution

Many many thanks for, once again, jumping to the rescue and also for the code tweaking. Smiley Happy

Points awarded.

Cheers,

Darren.

10 Print "It's all about the Nerdknobs" , 20 GOTO http://blog.vmote.net/
0 Kudos