VMware Cloud Community
internetrush1
Contributor
Contributor
Jump to solution

ReconfigureDVPortGroup_Task($spec) does not work when done more than once

Trying to set the description on our VDS portgroups with the following code:

                                                                Read-Host "Changing $fullportgroupName description to $portGroupDescription"

                                                                # ------- ReconfigureDVPortgroup_Task -------

                                                                $spec = New-Object VMware.Vim.DVPortgroupConfigSpec

                                                                $spec.configVersion = "0"

                                                                $spec.description = $PortGroupDescription

                                                                $spec.type = "earlyBinding"

                                                               

                                                                $_this = $portGroup | Get-View

                                                                $_this.ReconfigureDVPortgroup_Task($spec)

The Portgroups in question set the first time around, no problem; however, lets say i want to RESET the same port group, if i attempt to use the same code to set the portgroup to another description, the task fails as "Cannot complete operation due to concurrent modification by another operation"

Using powercli 5.5.0.0 and tested against vcenter server 5.1 and 5.5.

Any suggestions? Is there an easier way to set the description?

Thanks!

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Sure, I assume the $portgroup variable contains the dvPortgroup that needs to be changed.

Then you could do

$spec = New-Object VMware.Vim.DVPortgroupConfigSpec
$spec.configVersion = $portGroup.ExtensionData.Config.ConfigVersion
$spec.description = $PortGroupDescription
$spec.type = "earlyBinding"

$portgroup.ExtensionData.ReconfigureDVPortgroup_Task($spec)

You can also find an example in one of my posts in my dvSwitch series.

See dvSwitch scripting – Part 9 – Traffic Shaping, line 61.


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

View solution in original post

Reply
0 Kudos
7 Replies
LucD
Leadership
Leadership
Jump to solution

Your problem comes from the ConfigVersion property.

You can't hardcode that, you have to fetch the actual value from the portgroup.

This number is used to avoid concurrent updates to the same vSphere object.


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

internetrush1
Contributor
Contributor
Jump to solution

I'm pretty sure i can figure it out, but do you happen to know where i can get that information? (sorry but am new to using view as a modification resource, that code was gotten from thealpha ONYX version.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure, I assume the $portgroup variable contains the dvPortgroup that needs to be changed.

Then you could do

$spec = New-Object VMware.Vim.DVPortgroupConfigSpec
$spec.configVersion = $portGroup.ExtensionData.Config.ConfigVersion
$spec.description = $PortGroupDescription
$spec.type = "earlyBinding"

$portgroup.ExtensionData.ReconfigureDVPortgroup_Task($spec)

You can also find an example in one of my posts in my dvSwitch series.

See dvSwitch scripting – Part 9 – Traffic Shaping, line 61.


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

Reply
0 Kudos
internetrush1
Contributor
Contributor
Jump to solution


Worked, once again Luc, you are the man.

Thanks again!    

Reply
0 Kudos
Darophill
Contributor
Contributor
Jump to solution

Hi, is there a requirement to set the portgroup type to early binding if you are just trying to change the description. Would the below code work?

$spec = New-Object VMware.Vim.DVPortgroupConfigSpec
$spec.configVersion = $portGroup.ExtensionData.Config.ConfigVersion
$spec.description = $PortGroupDescription

$portgroup.ExtensionData.ReconfigureDVPortgroup_Task($spec)


Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

According to the SDK Reference, that is not required (see the red asterisk next to the type property in the DVPortgroupConfigSpec).

dvpg-type.png


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

Reply
0 Kudos
Darophill
Contributor
Contributor
Jump to solution

Thats what I thought. Thank you for confirming.

Reply
0 Kudos