Perl Toolkit: pNIC to vSwitch information

Another itch to scratch: which vSwitch is a pNIC connected to? To solve this simple problem I created a quick perl script…

This script also lets me see the driver in use, connection speed and duplex setting, and the MAC address of the pNIC.

6 thoughts on “Perl Toolkit: pNIC to vSwitch information”

  1. Would it be possible to get your script to also output the PCI slot location of each vmnic? I forget what the field is titled at the moment however I usually access that information via the “esxcfg-nics -l” command.

    Just a though as would be nice to get the output in one go in your script.

  2. Sure, just print the pci attribute…

    # starting at line 80, the print statement(s) should read like this:
    print "Adaptor (Driver)tPCI    tSpeed (Duplex)ttMACtttvSwitchn";
    print "----------------t-------t--------------tt---ttt-------n";
    foreach (@$pnics) {
    	print $_->device . " (" . $_->driver . ")" . "tt"
    		. $_->pci . "t"
    		. $_->linkSpeed->speedMb . " (" . ($_->linkSpeed->duplex eq "1" ? "Full" : "Half") . ")tt"
    		. $_->mac . "t"
    		. $pnic_to_vswitch{$_->key} . "n";

    There is quite a bit of information available, so I may adjust this script (when I can test it, which wouldn’t be until Monday) so that it shows a couple of fields by default, but providing some options will display additional information.

  3. Would it be possible to extend this script and get the virtual machine info (like mac address…)
    connected to vswitch. So one script will display the virtual machine, vswitch and physical adapter info.

  4. While running this script I am hitting this error
    Can’t call method “networkSystem” on an undefined value at line 63, line 2.

  5. ashish,

    Yes, it should be possible to add the virtual machines to the output. I’ll work on that when I get some spare time and post about it.

    As for the error you’re getting, it looks like the host object is not being created. Make sure that name is correct and ensure that the host object is being populated with the correct data. You can use Data::Dumper to print the object out.

    At line 55, add the following:

    print Dumper($host); exit;

    Which will show you the contents of that variable.

  6. Hi Andrew.

    I have the same problem as ashish.

    when I dump the content of the variable, I can see pnic, proxySwitch, consoleVnic, dnsConfig, etc but not vswitch.

    Do you have any idea about this situation?

    Thanks in advance…


Leave a Reply