Automation

 View Only
  • 1.  Listing Physical NIC Auto-negotiation Setting

    Posted Jun 09, 2012 08:36 AM

    Hello all I hope someone can help me out here.  I am trying to find out if there is a way using powercli to list/audit all hosts physical NIC settings.  Specifically I need to know if the NIC is hard codes to a specific speed or if it's set to auto negotiate.  And also its current speed / duplex and/or if it's down.

    I have looked at the get-view results from a host but have not been able to figure out exactly what indicates Iftar Physical NICs actual settings -v- what it is running at. 

    Thanks for the Help.



  • 2.  RE: Listing Physical NIC Auto-negotiation Setting

    Posted Jun 09, 2012 09:43 AM

    The following PowerCLI command will show you all the physical nic's for all your hosts and their speed and duplex setting:

    Get-VMHostNetworkAdapter |
    Where-Object {$_.GetType().Name -eq "PhysicalNicImpl"} |
    Select-Object -Property VMHost,Name,BitRatePerSec,FullDuplex,
      @{Name="AutoNegotiateSupported";Expression={$_.ExtensionData.AutoNegotiateSupported}}
    
    

    Unfortunately I could not find how to see if the nic is down.

    Regards, Robert

    Message was edited by: RvdNieuwendijk Added the AutoNegotiateSupported property to the script.



  • 3.  RE: Listing Physical NIC Auto-negotiation Setting

    Posted Jun 09, 2012 09:18 PM

    Thank you, I'll give that a try this evening.  I did see that property during my exploring but in my quick testing it seemed it reported true for all the physical NIC on the host I was testing even after I had used set-vmhostnetworkadapter to hard set duplex and speed.  So I assumed it was reporting that the NIC was capable of auto and not that it was set to auto. Again it was only a very quick exploring / test so I'll circle back to it again this evening and report back.

    Thanks again for the quick response.



  • 4.  RE: Listing Physical NIC Auto-negotiation Setting

    Posted Jun 10, 2012 07:46 AM

    Follow-Up:

    Ok I believe I may have answered part of my own question; but I am not sure exactly why this works so if someone could

    verify / confirm this and then if possible explain what is actually happpening that would be great!

    So I continued to dig into the results returned by  get-view of a vmhost and I found a results that changed based on if the  NIC has been hard coded

         (Get-VMHostNetworkAdapter $vmhost2 -physical -name vmnic0 | set-vmhostnetworkadapter -Duplex Full -BitRatePerSecMb 1000)

    or if it was set to AutoNegotiate

         (Get-VMHostNetworkAdapter $vmhost2 -physical -name vmnic0 | set-vmhostnetworkadapter -AutoNegotiate)

    Here are the PowerCli Command I used and results:  (Hard Coded NIC)

    $vmhost2=get-vmhost test-vmhost1

    $hstview2=get-view $vmhost2

    $hstview2.config.Network.pnic[0]

         Key                                                     : key-vim.host.PhysicalNic-vmnic0

         Device                                                 : vmnic0

         Pci                                                      : 01:00.0

         Driver                                                   : bnx2

         LinkSpeed                                            : VMware.Vim.PhysicalNicLinkInfo

         ValidLinkSpecification                            : {VMware.Vim.PhysicalNicLinkInfo,  VMware.Vim.PhysicalNicLinkInfo, VMware.Vim.PhysicalNicLinkInfo,                                                                     VMware.Vim.PhysicalNicLinkInfo...}

         Spec                                                    : VMware.Vim.PhysicalNicSpec

         WakeOnLanSupported                           : True

         Mac                                                      : a1:aa:aa:40:00:00

         VmDirectPathGen2Supported                  : False

         VmDirectPathGen2SupportedMode           :

         ResourcePoolSchedulerAllowed                : True

         ResourcePoolSchedulerDisallowedReason :

         AutoNegotiateSupported                           : True

         DynamicType                                           :

         DynamicProperty                                      :

    $hstview2.config.Network.pnic[0].spec

    Ip                                            LinkSpeed                                   DynamicType                    DynamicProperty    

    --                                             ---------                                          -----------                             ---------------

    VMware.Vim.HostIpConfig         VMware.Vim.PhysicalNicLinkInfo

    And Here are the PowerCli Commands I used and the results on the same NIC after I configured if AutoNegotiate using:

                    (Get-VMHostNetworkAdapter $vmhost2 -physical -name vmnic0 | set-vmhostnetworkadapter -AutoNegotiate)

    $vmhost2=get-vmhost test-vmhost1

    $hstview2=get-view $vmhost2

    $hstview2.config.Network.pnic[0]

         Key                                                     : key-vim.host.PhysicalNic-vmnic0

         Device                                                 : vmnic0

         Pci                                                      : 01:00.0

         Driver                                                   : bnx2

         LinkSpeed                                            : VMware.Vim.PhysicalNicLinkInfo

         ValidLinkSpecification                            : {VMware.Vim.PhysicalNicLinkInfo,  VMware.Vim.PhysicalNicLinkInfo, VMware.Vim.PhysicalNicLinkInfo,                                                                     VMware.Vim.PhysicalNicLinkInfo...}

         Spec                                                    : VMware.Vim.PhysicalNicSpec

         WakeOnLanSupported                           : True

         Mac                                                      : a1:aa:aa:40:00:00

         VmDirectPathGen2Supported                  : False

         VmDirectPathGen2SupportedMode           :

         ResourcePoolSchedulerAllowed                : True

         ResourcePoolSchedulerDisallowedReason :

         AutoNegotiateSupported                           : True

         DynamicType                                           :

         DynamicProperty                                      :

                                         :

    $hstview2.config.Network.pnic[0].spec

    Ip                                            LinkSpeed                                   DynamicType                    DynamicProperty    

    --                                             ---------                                          -----------                             ---------------

    VMware.Vim.HostIpConfig

    The difference I found is that on a hard coded  Physical NIC the $hstview2.config.Network.pnic[0].spec.LinkSpeed will  return VMware.Vim.PhysicalNicLinkInfo Object. 

    But when I reconfigured the NIC for AutoNegotiate  the $hstview2.config.Network.pnic[0].spec.LinkSpeed returns nothing  (empty/null).

    I tested against a few other hosts and NICs and  this seems to hold true; so my assumption is I can test each physical nic in each host for the .spec.LinkSpeed and if its NULL then its set to autonegotiate and if it returns any value then the NIC has been manually configured for speed and duplex.

    Now while I love finding a way to accomplish  things (especially part of something I need to get done), I also rather understand why it works than just  knowing that it does.  SO if anyone who understands the API / Management  Objects, or results of Get-View better than I do could try to explain if (A) this is an accurate way  to validate this setting and (B) why exactly this changes I would  really appriciate it.

    Thanks

    Joe



  • 5.  RE: Listing Physical NIC Auto-negotiation Setting
    Best Answer

    Posted Jun 10, 2012 08:38 AM

    Hi Joe,

    I should have read the documentation yesterday. :smileywink:

    You are right about the AutoNegotiate. You can find that in the PhysicalNicSpec documentation. It says about the LinkSpeed property:

    The link speed and duplexity that this physical network adapter is currently configured to use. If this property is not set, the physical network adapter autonegotiates its proper settings.

    According to the PhysicalNic documentation if the LinkSpeed property in that object is not set, then the link is down.

    That brings me to the following new version of my script:

    Get-VMHostNetworkAdapter |
    Where-Object {$_.GetType().Name -eq "PhysicalNicImpl"} |
    Select-Object -Property VMHost,Name,BitRatePerSec,FullDuplex,
      @{Name="AutoNegotiate";Expression={
        if ($_.ExtensionData.Spec.LinkSpeed)
          {$false} else {$true}
      }},
      @{Name="LinkState";Expression={
        if ($_.ExtensionData.LinkSpeed)
         {"Up"} else {"Down"}
      }}
    
    



  • 6.  RE: Listing Physical NIC Auto-negotiation Setting

    Posted Jun 11, 2012 08:23 PM

    After some additional exploring, and using the info you provided here is what I came up with.  Script is designed to run against several vcenters / host.  I tested in my enviroment this morning and script took 1 minute 50 seconds to run against just over 300 ESX hosts.

    $ScriptPath   = (Split-Path ((Get-Variable MyInvocation).Value).MyCommand.Path)  
    $ScriptPluginPath  = $ScriptPath + "\plugin\"  
    $ScriptToolsPath  = $ScriptPath + "\tools\"  
    $ScriptOutputPath  = $ScriptPath + "\Output\" 
    $ScriptInputPath =  $ScriptPath + "\Input\"
    $DateFormat   = Get-Date -Format "MMddyyyy_HHmmss"

    $inputfile = $ScriptInputPath + "\vc-servers.txt"

    $properties = "Name","config.network.pnic"

    $rptname = $ScriptOutputPath +"VMhost-pNic-CFG_" +$DateFormat +".csv"

    $scripttimer = Measure-Command { #Used to calculate how long the entirer script takes to run.
     
    $vcenters = Get-Content $inputfile #Import the list of VM's to be modified from vsv file
    $visrvconnected = Connect-VIServer $vcenters -WarningAction SilentlyContinue -ErrorAction SilentlyContinue

    Foreach ($vcenter in $visrvconnected) {
      $hstview = Get-View -Server $vcenter.Name -viewtype "hostsystem" -property $properties
      Foreach ($hst in $hstview) {
       Foreach ($pnic in $hst.config.network.pnic) {
        $pnicrpt = "" | Select vcenter,vmhost,pnic,driver,status,mac,cfgspeed,cfgduplex,runspeed,runduplex
        $pnicrpt.vcenter = $vcenter.name
        $pnicrpt.vmhost = $Hst.Name
        $pnicrpt.pnic = $pnic.Device
        $pnicrpt.driver = $pnic.Driver
        $pnicrpt.mac = $pnic.Mac
        $pnicrpt.status = if($pnic.linkspeed -ne $null){"up"}else{"down"}
        $pnicrpt.cfgspeed = if($pnic.spec.linkspeed -ne $null){$pnic.Spec.LinkSpeed.SpeedMb}else{"AUTO"}
        $pnicrpt.cfgduplex = if($pnic.spec.linkspeed -ne $null){$pnic.Spec.LinkSpeed.Duplex}else{"AUTO"}
        $pnicrpt.runspeed = $pnic.linkspeed.speedmb
        $pnicrpt.runduplex = $pnic.LinkSpeed.Duplex
        $Report +=$pnicrpt
       }
      }
    disconnect-viserver -Server $vcenter.Name -Confirm:$false -Force:$true -WarningAction SilentlyContinue
    }
    } # Close Script Timer Loop

    $Report | Select vcenter,vmhost,pnic,driver,status,mac,cfgspeed,cfgduplex,runspeed,runduplex | Export-Csv $rptname -NoTypeInformation

    Write-Host "Script Execution Time: " $scripttimer