Automation

 View Only
  • 1.  Enable CDP on vSwitch on all hosts

    Posted Feb 01, 2010 07:42 PM

    I have a somewhat cumbersome way to run vimsh and esxcfg-x scripts on each ESX host via powercli using and .csv file and plink.exe (see code). I want to be able to enable CDP on all the virtual switches across all my hosts, and not have to run a seperate one-liner for every switch. I'm sure there is an easier way and thought I would ask all the experts!

    Thanks.

    import-csv c:\temp\test.csv | %{plink -l root
    root@($_.Server) -pw $_.Password esxcfg-vswitch -B both vSwitch0}



  • 2.  RE: Enable CDP on vSwitch on all hosts

    Broadcom Employee
    Posted Feb 01, 2010 11:17 PM

    Ive had a quick look through the API reference and could see no way of enabling this, there is information in the reference to view the properties of CDP once it is enabled, I used it a while back on this script: http://www.virtu-al.net/2008/12/12/detailed-vmware-host-network-information/

    Looks like your method is the only way that I can see at the moment, Luc (who sleeps with the API reference as a pillow) may find something that I can not.

    I have used a 3rd party tool to make ssh connections before so it is more natural to powershell other than plink, prehaps I will adapt this method to create a invoke-vmhostScript function !

    If you found this information useful, please consider awarding points for Correct or Helpful.

    Alan Renouf

    http://virtu-al.net



  • 3.  RE: Enable CDP on vSwitch on all hosts

    Posted Feb 02, 2010 08:57 AM

    Alan is correct, there is currently no API to do the same as the "esxcfg-vswitch -B both..." command is doing.

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 4.  RE: Enable CDP on vSwitch on all hosts

    Posted Mar 24, 2010 09:25 PM

    I tried the procedure in the link below for ESXi 4.0.0 U1 using vMA 4.0 and it worked. Our network admin was able to see CDP info on our 6509 switches for both access and trunk ports.

    vicfg-vswitch --server <vcenter.domain.com> -h <esxi.domain.com> -B both <vSwitch0>

    Next-Gen Stuff: Enabling CDP in ESX/ESXi

    This would suggest that there is someting in the Perl API to enable CDP.



  • 5.  RE: Enable CDP on vSwitch on all hosts

    Broadcom Employee
    Posted Apr 07, 2011 02:26 PM

    @aenagy

    That's correct, Enabling CDP is available through the vSphere API UpdateVirtualSwitch method and specifying the LinkDiscoveryProtocolConfig in the spec and using protocol => cdp. You may notice that the enum type allows for both "cdp" and "lldp", the latter is something that isn't actually fully implemented on a standard vSwitch, would have been nice to have. LLDP afaik is only supported on vDS

    Though this functionality is not available in canned VMware Powershell cmdlet, one could craft a custom cmdlet to enable CDP without having to resort to plink hack. This is where it pays off to know a bit about the APIs :smileyhappy: and where VMware hasn't provided a cmdlet for every single operation within a vSphere environment and this isn't the only cmdlet that is lacking either



  • 6.  RE: Enable CDP on vSwitch on all hosts

    Posted Aug 19, 2011 03:07 PM

    Has anyone happen to have built a PowerCLI script to do this that they would be willing to share? It would be much appreciated.



  • 7.  RE: Enable CDP on vSwitch on all hosts

    Posted Feb 23, 2012 07:32 PM

    I know this is an old thread - but I did find a solution to this, using Get-Esxcli

    How to Set CDP on a vSwitch–the #PowerCLI Way

    Maish

    VMTN Moderator | vExpert

    Author of VMware vSphere Design

    @maishsk | My Blog



  • 8.  RE: Enable CDP on vSwitch on all hosts

    Posted Feb 23, 2012 07:44 PM

    Nice one Maish, waiting for the function now :smileywink:



  • 9.  RE: Enable CDP on vSwitch on all hosts

    Posted Mar 06, 2012 02:29 PM

    Here you go Luc :smileyhappy:

    function Set-VirtualSwitchCDP {      <#           .SYNOPSIS                Set the CDP setting on a Standard Virtual Switch.           .DESCRIPTION                Using the Get-Esxcli cmdlet you can changed the CDP Settings                on virtual switch on an ESX host.           .NOTES Author: Maish Saidel-Keesing           .PARAMETER  VMHost                ESX server to perform the function.           .PARAMETER  MTU                The MTU settings of the vSwitch, default is 1500.Valid values are                between 1500-9000           .PARAMETER  CDP                The CDP setting for the vSwitch.                Valid values are 'down', 'listen', 'advertise' or 'both'.           .PARAMETER  vSwitch                The Name of the Standard vSwitch on which to perform the action.           .EXAMPLE                PS C:\> Set-VirtualSwitchCDP -VMhost esx1 -MTU 1500 -CDP both -vSwitch vSwitch0           .EXAMPLE                PS C:\> Get-VMhost Myhost | Set-VirtualSwitchCDP -vSwitch vSwitch0           .LINK                http://technodrone.blogspot.com/2012/02/how-to-set-cdp-on-vswitchthe-powercli.html      #>           [CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='High')]     Param(     [Parameter(Position=0,Mandatory=$True,ValueFromPipeline=$True)]     [String]     $VMHost,     [Parameter(Position=1)]      [ValidateRange(1500,9000)]     [Int]     $MTU = 1500,            [Parameter(Position=2)]      [ValidateSet("down","listen","advertise","both")]     [String]     $CDP = "both",            [Parameter(Position=3,Mandatory=$True)]     [String]     $vSwitch      )          Process      {          if ($pscmdlet.ShouldProcess($VMHOST,"Updating $vSwitch with MTU $MTU and CDP setting of $CDP"))     {                foreach ($hostobject in (Get-VMHost $VMHost)) {                     $esxcli = Get-EsxCli -VMHost $hostobject                     $esxcli.network.vswitch.standard.set($CDP,$MTU,$vswitch)                     $esxcli.network.vswitch.standard.list()                }           }      } }

    Maish

    VMware Communities Moderator

    My Blog - @maishsk

    Co-Author of VMware vSphere Design



  • 10.  RE: Enable CDP on vSwitch on all hosts

    Posted Mar 06, 2012 02:46 PM

    Nice one Maish



  • 11.  RE: Enable CDP on vSwitch on all hosts

    Posted Feb 02, 2010 01:02 PM

    Thank you gentlemen.