VMware {code} Community
KFukumoto
Contributor
Contributor

How to get dVS portgroup connected to guestNic

Hi

I am trying to get portgroupName connected to specific guestNic.

In case of standard vSwitch , I can get the portgroupName connencted the guestNic

by following sample code. I got the portgroupName in the Data object guestNicInfo->network.

But, In case of dVS , the sample do not work well. No data in the guestNicInfo->network.

How can I get the dVS-porgroupName connected to guestNic ?

#= sample code ==

my $vm_views = Vim::find_entity_views(view_type=>"VirtualMachine");

foreach my $vm_view(@$vm_views){

print "=== virtualMachine : ". $vm_view->name ."\n";

my $guestInfo = $vm_view->guest;

my $guestNicInfos = $guestInfo->net;

foreach my $guestNicInfo(@$guestNicInfos){

print "---- guestNicInfos----


\n";

print " deviceConfigId:" . $guestNicInfo->deviceConfigId ."\n"; #DeviceKey

print " porgroupName connected to the guestNic" . $guestNicInfo->network ."\n";

}

}

#=================

0 Kudos
2 Replies
lamw
Community Manager
Community Manager

Here is a vSphere SDK for Perl script that may help you extract out the distributed portgroup for your virtual machines: . I do have to say it's definitely not pretty and you may also want to take a look at this thread for a cleaner solution: which requires a manual update to the Perl client stubs to extract out information from a distributed vSwitch than having to do multiple nested calls.

=========================================================================

William Lam

VMware vExpert 2009,2010

VMware VCP3,4

VMware VCAP4-DCA

VMware scripts and resources at:

Twitter: @lamw

Getting Started with the vMA (tips/tricks)

Getting Started with the vSphere SDK for Perl

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

KFukumoto
Contributor
Contributor

Thank you lamw.

I executed the script on my system.

But, the script seems like return not-definite portgroupName connected to guestNic.

I also see your sample execution on DOC-11581.

The sample execution listed 2 lines like this.

VM MAC PORTGROUP

-


vm-4 00:50:56:92:63:61 - VM Network

-


vm-4 00:50:56:92:63:61 - Internet.

-


It seems one vNic(00:50:56:92:63:61) connected two portgroup VM Network and Internet .

My execution listed same as this.

How can I definite the portgroupName connected to the guestNic ?

0 Kudos