kcvman
Contributor
Contributor

Enable CDP on vSwitch on all hosts

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}

0 Kudos
10 Replies
alanrenouf
VMware Employee
VMware Employee

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

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
LucD
Leadership
Leadership

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


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

kcvman
Contributor
Contributor

Thank you gentlemen.

0 Kudos
aenagy
Hot Shot
Hot Shot

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.

0 Kudos
lamw
Community Manager
Community Manager

@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 Smiley Happy 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

0 Kudos
argiesen
Contributor
Contributor

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

0 Kudos
maishsk
Expert
Expert

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

Maish Saidel-Keesing • @maishsk • http://technodrone.blogspot.com • VMTN Moderator • vExpert • Co-author of VMware vSphere Design
0 Kudos
LucD
Leadership
Leadership

Nice one Maish, waiting for the function now Smiley Wink


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

0 Kudos
maishsk
Expert
Expert

Here you go Luc Smiley Happy

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

Maish Saidel-Keesing • @maishsk • http://technodrone.blogspot.com • VMTN Moderator • vExpert • Co-author of VMware vSphere Design
0 Kudos
LucD
Leadership
Leadership

Nice one Maish


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

0 Kudos