News

ESX and CDP (Cisco Discovery Protocol)

One of my favorite features of ESX 3.5.0 is the inclusion of the Cisco Discovery Protocol (CDP), from an administrative perspective, it allows me to click on a bubble next to my network ports and get the switch name, switch ip, switch blade and port that the vmnic is connected to. Since documentation isn't always 100% reliable it's nice to be able to verify it with the CDP information that you can gleam from ESX. If you upgraded your ESX host from a pre 3.5.0 version, CDP likely isn't enabled though it is enabled by default with a new 3.5.0+ installation. To correct this you need to fix it from the command line. The following command will set the ESX vSwitch to start listening for CDP information from your switch:


vmprofessional #>esxcfg-vswitch -B listen vSwitch0


After that, you just need to wait a few minutes for the information to populate and be available in the VIC. One drawback about looking at the data in the VIC is that it is presented in a field that is non-selectable so you can't copy the data out. If you have a large number of ports to get information on the process of transcribing can be cumbersome and error-prone. I developed a script to pull this data from the command line to make the data more usable. Behold!


#!/usr/bin/perl -w
use strict;
use warnings;
use Getopt::Long;
use Term::ANSIColor qw(:constants);
$Term::ANSIColor::AUTORESET = 1;
use VMware::VIRuntime;

my $username = "username";
my $password = "password";

my @service_urls = qw|
https://esxhost_or_vc1.yourdomain.com/sdk
https://esxhost_or_vc2.yourdomain.com/sdk
|;


foreach (@service_urls){
my $service_url = $_;
print "Gathering host information from server: ";
print BLUE "$service_url\n";
Vim::login(service_url => $service_url, user_name => $username, password => $password);
my $hostViews = Vim::find_entity_views(view_type => 'HostSystem' );

foreach (@$hostViews ) {
print "Host: ", $_->name, ".\n";
my $version = $_->config->product->fullName;
$version =~ s/.*-(\d+)/$1/;
# Only hosts > ESX 3.5.0 ( build 64607 ) could have CDP information
unless ( $version > 64607 ){
print "Host: ", $_->name, " < ESX 3.5.0, Skipping \n";
next;
}
my $netMgr = Vim::get_view(mo_ref => $_->configManager->networkSystem);
my @physicalNicHintInfo = $netMgr->QueryNetworkHint();
foreach (@physicalNicHintInfo){
foreach ( @{$_} ){
my $device = $_->device;
if ( defined $_->connectedSwitchPort ){
my $port = $_->connectedSwitchPort->portId;
my $switch = $_->connectedSwitchPort->devId;
my $vlan = $_->connectedSwitchPort->vlan;
print "$device $switch $port $vlan\n";
}
}
}
print "\n";
}
}
Vim::logout();



I've been thinking about extending the script a bit too but haven't found time yet. Since CDP yields the name of the physical switch, it's possible to use this data to determine if your vSwitch has redundant links that head to seperate physical switches.

Labels:

Posted by Dominic Rivera at Tuesday, June 23, 2009.


Archives

10/01/2006 - 11/01/2006 | 03/01/2007 - 04/01/2007 | 04/01/2007 - 05/01/2007 | 05/01/2007 - 06/01/2007 | 06/01/2007 - 07/01/2007 | 07/01/2007 - 08/01/2007 | 09/01/2007 - 10/01/2007 | 10/01/2007 - 11/01/2007 | 11/01/2007 - 12/01/2007 | 12/01/2007 - 01/01/2008 | 01/01/2008 - 02/01/2008 | 02/01/2008 - 03/01/2008 | 03/01/2008 - 04/01/2008 | 04/01/2008 - 05/01/2008 | 05/01/2008 - 06/01/2008 | 06/01/2008 - 07/01/2008 | 08/01/2008 - 09/01/2008 | 09/01/2008 - 10/01/2008 | 10/01/2008 - 11/01/2008 | 03/01/2009 - 04/01/2009 | 06/01/2009 - 07/01/2009 | 07/01/2009 - 08/01/2009 |