PowerCLI

 View Only
Expand all | Collapse all

Changing MTU size to vmkernels on dvSwitch

  • 1.  Changing MTU size to vmkernels on dvSwitch

    Posted May 18, 2012 09:27 AM

    Hi all,

    I have around 40 ESX hosts which belong to 6 different dvswitches and 6 different clusters. Each host has 6 vmknics created for the dvswitch and all of them have a 1500 mtu value. Can someone help me out with a power cli script to change all the vmks to 9000 mtu?

    Please let me know if additional information is required

    Thanks in advance.



  • 2.  RE: Changing MTU size to vmkernels on dvSwitch

    Posted May 18, 2012 09:45 AM


  • 3.  RE: Changing MTU size to vmkernels on dvSwitch

    Posted May 18, 2012 09:46 AM

    I'm afraid that is for regular switches, not dvSwitches



  • 4.  RE: Changing MTU size to vmkernels on dvSwitch

    Posted May 18, 2012 09:53 AM

    my humble apologies. I had missed out the "dv ". I had a heavy lunch :smileysilly: .

    looking into my setup for the parameter...

    Thanks LUCD



  • 5.  RE: Changing MTU size to vmkernels on dvSwitch

    Posted May 18, 2012 09:53 AM

    You say that the 6 vmnics are allocated to 1 dvSwitch.

    Are there other portgroups on that dvSwitch besides the VMKernel portgroup ?

    Can all vmnics on the dvSwitch be changed to an MTU of 9000 ?

    In fact you are trying to mix 2 different things, the vnic, which has a MTU value, and the VMKernel portgroup defined on the dvSwitch.



  • 6.  RE: Changing MTU size to vmkernels on dvSwitch

    Posted May 18, 2012 09:59 AM

    Sorry LucD I might have not put it correctly.

    I have 6 dvSwitches with 6 ports groups each. For each host I have 6 vmk virtual adapters, all of them deal with iScsi so they can be changed to 9000 MTU no problem.



  • 7.  RE: Changing MTU size to vmkernels on dvSwitch

    Posted May 18, 2012 10:57 AM

    Ok, I see.

    For a dvSwitch the MTU is defined on the dvSwitch.

    function Set-dvSwMTU{
      param(
      [parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)]
      [VMware.Vim.VmwareDistributedVirtualSwitch]$dvSw,
      [parameter(Position = 1)]   [int]$MTU
      )  
    $spec = New-Object VMware.Vim.VMwareDVSConfigSpec
     
    $spec.configVersion = $dvSw.Config.ConfigVersion
      $spec.MaxMTU = $MTU  $taskMoRef = $dvSw.ReconfigureDvs_Task($spec)   $task = Get-View $taskMoRef
     
    while("running","queued" -contains $task.Info.State){     $task.UpdateViewData("Info")   }   $task.Info.Result
    } function Get-dvSwitch{   param([parameter(Position = 0, Mandatory = $true)][string]$DatacenterName,
      [parameter(Position = 1, Mandatory = $true)][string]$dvSwitchName
      )  
    function Get-dvSwitchInThisLocation{     param(     [parameter(Position = 0, Mandatory = $true)]     [VMware.Vim.ManagedObjectReference]$LocationMoRef,
        [parameter(Position = 1, Mandatory = $true)][string]$dvSwitchName
        )    
    $location = Get-View $LocationMoRef
        foreach($child in $location.ChildEntity){       if($child.Type -eq "Folder"){         Get-dvSwitchInThisLocation $child $dvSwitchName
          }       elseif($child.Type -eq "VmwareDistributedVirtualSwitch"){         $temp = Get-View $child
            if($temp.Name -eq $dvSwitchName){           $temp
            }       }     }   }
      Get-dvSwitchInThisLocation (Get-Datacenter $DatacenterName).Extensiondata.NetworkFolder $dvSwitchName
    }
    Get-dvSwitch -DatacenterName "MyDC" -dvSwitchName "dvSw1" |
    Set-dvSwMTU
    -MTU 9000

    The above will change the MTU value on the dvSwitch, but I'm not sure if that is sufficient.

    It could be that you would also need to change the MTU on the vnics that are connected to the dvSwitch. I'm trying to find out.



  • 8.  RE: Changing MTU size to vmkernels on dvSwitch

    Posted May 18, 2012 11:14 AM

    Thank you for this. Unfortunately the dvswitch it self is already at 9000 mtu, I should have said that from the beggining to save you time. There are only 6 of them so I did that manually, it only took a couple of minutes.

    The time consuming part is changing the mtu in the virtual adapters in each host.



  • 9.  RE: Changing MTU size to vmkernels on dvSwitch
    Best Answer

    Posted May 18, 2012 11:58 AM

    Try it like this.

    $MtuSize = 9000
    
    foreach
    ($dvSw in (Get-VirtualSwitch -Distributed -Datacenter MyDC)){   $dvSw.ExtensionData.Config.Host | %{     $esx = Get-View $_.Config.Host
        foreach($pnic in $_.Config.Backing.PnicSpec){       $netSys = Get-View $esx.configManager.networkSystem
         
    foreach($vnic in $netSys.NetworkConfig.Vnic | where {$_.Spec.DistributedVirtualPort}){         $spec = [VMware.Vim.HostVirtualNicSpec]$vnic.spec
            $spec.mtu = $MTUSize
           
    $netSys.UpdateVirtualNic($vnic.Device,$spec)       }     }   } }

    It will update the MTU for each vnic connected to a dvSwitch



  • 10.  RE: Changing MTU size to vmkernels on dvSwitch

    Posted May 18, 2012 12:20 PM

    Thanks for that, that looks like what I need. What should I change in order to try it only on a test cluster first? Just want to be sure before I push it out to the whole DC.



  • 11.  RE: Changing MTU size to vmkernels on dvSwitch

    Posted May 18, 2012 01:45 PM

    You can manipulate the foreach line.

    For example, change this line

    foreach($dvSw in (Get-VirtualSwitch -Distributed -Datacenter MyDC)){
    

    into something like this

    foreach($dvSw in (Get-VirtualSwitch -Distributed -VMHost (Get-Cluster -Name MyCluster | Get-VMHost))){
    


  • 12.  RE: Changing MTU size to vmkernels on dvSwitch

    Posted May 18, 2012 02:16 PM

    Thanks very much again, it works as it's changing the value, but it doesnt set it to 9000. And for the hosts that I had manually changed it to 9000, it went and put it back to 1500.

    That's what I am running.

    $tgtMtuSize = 9000
    foreach($dvSw in (Get-VirtualSwitch -Distributed -VMHost (Get-Cluster -Name Cluster01 | Get-VMHost))){
      $dvSw.ExtensionData.Config.Host | %{
        $esx = Get-View $_.Config.Host
        foreach($pnic in $_.Config.Backing.PnicSpec){
          $netSys = Get-View $esx.configManager.networkSystem
          foreach($vnic in $netSys.NetworkConfig.Vnic | where {$_.Spec.DistributedVirtualPort}){
            $spec = [VMware.Vim.HostVirtualNicSpec]$vnic.spec
            $spec.mtu = $MTUSize
            $netSys.UpdateVirtualNic($vnic.Device,$spec)
          }
        }
      }
    }

    Edit: Oh.. the $spec.mtu = looks for the $MTUSize but the variable has been set to $tgtMtuSize, that's what I suppose is the problem?

    Editno2: Yes that it, thanks very much!



  • 13.  RE: Changing MTU size to vmkernels on dvSwitch

    Posted May 18, 2012 02:42 PM

    Yes, that was a typo.

    Corrected it.