Reply to Message

View discussion in a popup

Replying to:
stumpr
Virtuoso
Virtuoso

Well, Flexible is basically just the VirtualPCNet32 adapter; VMware's UI just uses 'flexible' in the UI display.  So in that case you can easily check for it by reviewing the vm.config.hardware.device[] array with isa().

Pseudo logic from reference (not tested):

# For efficient collection, use limited property lists

@vms = Vim::find_entity_views(view_type => 'VirtualMachine', properties => ['name', 'config.hardware.device']);

foreach my $vm ( @vms ) {

print "vm: " . $vm->{'name'} . "\n";

@devs = @{ $vm->{'config.hardware.device'} };

# Pick out just network devices

@net_devs = grep { $_->isa('VirtualEthernetCard'} } @devs;

# iterate the network devices for each VM

foreach my $nic ( @net_devs ) {

     my ($name, $type, $network, $connect, $pg_mo, $pg);

     # NIC type

     if ($nic->isa('VirtualPCNet32') {

          $type = 'Flexible';

     } else {

          $type = ref $nic;

     }

     # The network object is specified as a reference, so it will need to be cross checked against the network objects to get the 'label'

     $pg_mo = $nic->{'backing'}{'network'};

     # You should pre-fetch all the network and DistributedVirtualPortgroup objects, doing a call for each is not efficient, but works

     $pg = Vim::get_view(mo_ref => $pg_mo, properties => ['name']);

     $network = $pg->{'name'};

     # For connect on power on, look at device connectable property

     $connect = ( eval {$nic->{'connectable'}{'startConnected'} ) ? 1 : 0;

     # NIC label (name)

     $name = $nic->{'deviceInfo'}{'label'};

     # Push your values into some csv output data struct or print them

     print "  nic '$name':\n";

     print "    connect on power on: $connect\n";

     print "    network portgroup: $network\n";

     print "    NIC type: $type\n";    

}

}

Reuben Stump | http://www.virtuin.com | @ReubenStump