rlaborius
Contributor
Contributor

Help with getting dvsport id from given vm

Hi

i try to find out the dvsport id from a given vmname and vnic.

Maybe someone can give some hints or solution.

I tried to get it from the VM object

my $vm = Vim::find_entity_view(view_type => 'VirtualMachine',
                                                        filter => { 'name' => $vmname },
                                                        properties => ['config.hardware.device']);

The VM has 3 Interfaces.

I want to find out for example the portKey for inteface key 4001.

Thanks

Ronny

0 Kudos
3 Replies
lamw
Community Manager
Community Manager

IRRC, you only get the DvPortgroup key associated with a VM's interface, it will not provide you with the dvport ID. You can however use the FetchDVPortKeys() http://pubs.vmware.com/vsphere-50/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc_50%2Fvim.Distribute... method and basically search for your VM and return it's dvport ID and match that up with the VM

Here is a vSphere SDK for Perl script which leverages this method along with providing various data about a VDS and one of the examples provides a mapping to the DvPortgroup portID

http://www.virtuallyghetto.com/2011/12/retrieving-information-from-distributed.html

0 Kudos
rlaborius
Contributor
Contributor

Hi lamw

I tried this script some times before.

My problem is, that we have 500 VM's, so i wrote some functions to retrive the infos from one VM.

The main thing is, that Script uses 11 seconds to complete.

5 Seconds for fetching only.

I wite on a client to change the portgroups via script for automatic testing.

So my idea was, to get the changed port after the change (set) of the portgroup via

$vm_view->update_view_data();

bless( {
                                                      'macAddress' => '00:50:56:99:06:27',
                                                      'backing' => bless( {
                                                                            'port' => bless( {
                                                                                               'connectionCookie' => '149733205',
                                                                                               'switchUuid' => '34 ec 19 50 aa a2 a1 b9-0a 99 ab 4a ef 31 55 a4',
                                                                                               'portKey' => '1379',
                                                                                               'portgroupKey' => 'dvportgroup-80'
                                                                                             }, 'DistributedVirtualSwitchPortConnection' )
                                                                          }, 'VirtualEthernetCardDistributedVirtualPortBackingInfo' ),
                                                      'wakeOnLanEnabled' => '0',
                                                      'key' => '4001',
                                                      'connectable' => bless( {
                                                                                'allowGuestControl' => '1',
                                                                                'status' => 'untried',
                                                                                'connected' => '0',
                                                                                'startConnected' => '1'
                                                                              }, 'VirtualDeviceConnectInfo' ),
                                                      'addressType' => 'assigned',
                                                      'deviceInfo' => bless( {
                                                                               'summary' => 'vm.device.VirtualPCNet32.DistributedVirtualPortBackingInfo.summary',
                                                                               'label' => 'Network adapter 2'
                                                                             }, 'Description' ),
                                                      'unitNumber' => '8',
                                                      'controllerKey' => '100'
                                                    }, 'VirtualPCNet32' ),

regards

Ronny

0 Kudos
lamw
Community Manager
Community Manager

Not sure I understand what you're trying to do, but if you have a large environment it could take a bit of time to lookup. You may want to tweak the criteria to futher limit the scope to help reduce the amount of time it takes to run. Another option that you could try is if you know which VMs you wish to retrieve the dvport id, you could store the dvportgroup portkey and then lookup the dvportgroup on the VDS and then quickly map that to the VM in question.

0 Kudos