VMware Cloud Community
DieterA
Contributor
Contributor
Jump to solution

Rename distributed switch uplinks

We are implementing distributed switches in our environment, we are trying to migrate using powercli and it works great.

My question is purely cosmetic. Is it possible to rename the different uplinks via powercli? I haven't found anything to do so.

Now it's dvuplink1, ... and so on, but we want to have meaningful names to it, saying to which networks this is an uplink and even mention the group to which it is connected on our core switch, for quicker troubleshooting.

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this

$vdsName = 'vds1'

$oldUplinkName = 'dvUplink'

$newUplinkName = 'MyUplink'

$vds = Get-VDSwitch -Name $vdsName

$spec = New-Object VMware.Vim.DVSConfigSpec

$spec.ConfigVersion = $vds.ExtensionData.Config.ConfigVersion

$spec.UplinkPortPolicy = New-Object VMware.Vim.DVSNameArrayUplinkPortPolicy

$vds.ExtensionData.Config.UplinkPortPolicy.UplinkPortName | %{

    $spec.UplinkPortPolicy.UplinkPortName += $_.Replace($oldUplinkName,$newUplinkName)

}

$vds.ExtensionData.ReconfigureDvs($spec)


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

View solution in original post

Reply
0 Kudos
10 Replies
erikverbruggen
Hot Shot
Hot Shot
Jump to solution

It is possible to rename the uplink ports but I'm not sure if this is possible with PowerCLI. Maybe you can use the Set-VDport PowerCLI cmdlet?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try something like this

$vdsName = 'vds1'

$oldUplinkName = 'dvUplink'

$newUplinkName = 'MyUplink'

$vds = Get-VDSwitch -Name $vdsName

$spec = New-Object VMware.Vim.DVSConfigSpec

$spec.ConfigVersion = $vds.ExtensionData.Config.ConfigVersion

$spec.UplinkPortPolicy = New-Object VMware.Vim.DVSNameArrayUplinkPortPolicy

$vds.ExtensionData.Config.UplinkPortPolicy.UplinkPortName | %{

    $spec.UplinkPortPolicy.UplinkPortName += $_.Replace($oldUplinkName,$newUplinkName)

}

$vds.ExtensionData.ReconfigureDvs($spec)


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

Reply
0 Kudos
DieterA
Contributor
Contributor
Jump to solution

This seems to work. Thank you!

I now have another problem, when I try this script on Distributed switches created by powerCLI I get following error:

"The resource 'dvUplink1' is in use. Uplink or Link Aggregation group name dvUplink1 is in use by the teaming policy defined at DVPortgroup dvpg-373"

If I do this on manually created Distributed switches, the script works like a charm.

This looks like a problem described in https://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=20436.... However I am doing this on a vcenter 6.5 appliance, which is much newer than vcenter 5.5.

I found out that if you create a New Distributed Switch in vCenter 6.5 it is created with uplinks named "Uplink 1, Uplink 2,...". When I create the same switch using powerCLI, the uplinks are named "dvUplink1, dvUplink2,..." probably here in lies the problem.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can't you test the vCenter version, and then update the content of the $oldUplinkName variable accordingly?


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

Reply
0 Kudos
robbielozier
Enthusiast
Enthusiast
Jump to solution

I am trying to do something very similar. I want to rename the dvUplinks to a very specific name and assign the vmnic to the correct dvUplink.  I have 6 uplinks and would like to name the dvUplinks dvUplink0, dvUplink1, dvUplink4, dvUplink5, dvUplink6 and dvUplink8.  When I attempt to modify the script above I receive the error "Exception calling reconfiguredvs with "1" argument. Cannot complete operation due to concurrent modification by another operation."
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Most of the time that indicates there is something wrong with $spec.ConfigVersion

Can you check if the value corresponds with the one in $vds.ExtensionData.Config.ConfigVersion


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

Reply
0 Kudos
robbielozier
Enthusiast
Enthusiast
Jump to solution

Thank you for the quick response. Here is what I have as a test with 2 dvuplinks.  Any help is appreciated.

$dvduplink1 = 'dvUplink1'
$Uplink0 = 'Uplink0"

$vds = Get-VDSwitch -Name Test-VDS
$spec = New-Object VMware.Vim.DVSConfigSpec

$spec.ConfigVersion = $vds.ExtensionData.Config.ConfigVersion

$spec.UplinkPortPolicy = New-Object VMware.Vim.DVSNameArrayUplinkPortPolicy

$vds.ExtensionData.Config.UplinkPortPolicy.UplinkPortName | %{

    $spec.UplinkPortPolicy.UplinkPortName += $_.Replace($dvduplink1,$Uplink0)

}

$vds.ExtensionData.ReconfigureDvs($spec)
#
$dvduplink2 = 'dvUplink2'
$Uplink1 = 'Uplink1"

$vds = Get-VDSwitch -Name Test-VDS
$spec = New-Object VMware.Vim.DVSConfigSpec

$spec.ConfigVersion = $vds.ExtensionData.Config.ConfigVersion

$spec.UplinkPortPolicy = New-Object VMware.Vim.DVSNameArrayUplinkPortPolicy

$vds.ExtensionData.Config.UplinkPortPolicy.UplinkPortName | %{

    $spec.UplinkPortPolicy.UplinkPortName += $_.Replace($dvduplink2,$Uplink1)

}

Reply
0 Kudos
robbielozier
Enthusiast
Enthusiast
Jump to solution

$vds.ExtensionData.ReconfigureDvs($spec) is at the end of the script as well.
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, but you are using the old value (the one before the 1st call to ReconfigureDvs).

You can do them all in 1 call, something like this.

I use a hash table to lookup the new name.

$dvsLink = @{

    'dvUplink1' = 'dvUplink0'

    'dvUplink2' = 'dvUplink1'

    'dvUplink3' = 'dvUplink4'

    'dvUplink4' = 'dvUplink5'

    'dvUplink5' = 'dvUplink6'

    'dvUplink6' = 'dvUplink8'

}

$vds = Get-VDSwitch -Name vds1

$spec = New-Object VMware.Vim.DVSConfigSpec

$spec.ConfigVersion = $vds.ExtensionData.Config.ConfigVersion

$spec.UplinkPortPolicy = New-Object VMware.Vim.DVSNameArrayUplinkPortPolicy

$vds.ExtensionData.Config.UplinkPortPolicy.UplinkPortName | %{

    $spec.UplinkPortPolicy.UplinkPortName += $dvsLink[$_]

}

$vds.ExtensionData.ReconfigureDvs($spec)


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

robbielozier
Enthusiast
Enthusiast
Jump to solution

That worked perfectly. Thank you again. Now I just have to figure out how to map thev vmnics to the uplinks.
Reply
0 Kudos