10 Replies Latest reply on Dec 7, 2017 10:09 AM by robbielozier

    Rename distributed switch uplinks

    DieterA Novice

      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. Re: Rename distributed switch uplinks
          erikverbruggen Hot Shot

          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?

          • 2. Re: Rename distributed switch uplinks
            LucD Guru
            User ModeratorsCommunity WarriorsvExpert

            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)

             

            • 3. Re: Rename distributed switch uplinks
              DieterA Novice

              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=2043652. 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.

              • 4. Re: Rename distributed switch uplinks
                LucD Guru
                vExpertUser ModeratorsCommunity Warriors

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

                • 5. Re: Rename distributed switch uplinks
                  robbielozier Enthusiast
                  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."
                  • 6. Re: Rename distributed switch uplinks
                    LucD Guru
                    Community WarriorsvExpertUser Moderators

                    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

                    • 7. Re: Rename distributed switch uplinks
                      robbielozier Enthusiast

                      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)

                      }

                      • 8. Re: Rename distributed switch uplinks
                        robbielozier Enthusiast
                        $vds.ExtensionData.ReconfigureDvs($spec) is at the end of the script as well.
                        • 9. Re: Rename distributed switch uplinks
                          LucD Guru
                          Community WarriorsvExpertUser Moderators

                          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)

                           

                          1 person found this helpful
                          • 10. Re: Rename distributed switch uplinks
                            robbielozier Enthusiast
                            That worked perfectly. Thank you again. Now I just have to figure out how to map thev vmnics to the uplinks.