Reply to Message

View discussion in a popup

Replying to:
Sergio81
Contributor
Contributor

How to retrieve the network information (NIC) for each VM (perl vim)

Hi,

I have this simple code to retrieve the name of all VirtualMachines in my infrastructure (filtered for datacenter)

[...other code...]

use VMware::VILib;
    Opts::add_options(%opts);
    Opts::parse();
    Opts::validate();
    Util::connect();

my $datacenter = $DCFILTER;

my $clusterFilter = $CLFILTER ;

my $datacenter_view = Vim::find_entity_view(view_type => 'Datacenter', filter => { name => $datacenter });

my @values = split(/\|/, $clusterFilter);

foreach my $val (@values) {

    my $cluster_view = Vim::find_entity_view(view_type => 'ClusterComputeResource', filter => { name => qr/$val/});

    my $vm_views = Vim::find_entity_views(view_type => 'VirtualMachine', begin_entity => $cluster_view);

    foreach (@$vm_views) {

   print $_->name . "\n";
   $vm = $_->name;

    }

}

Util::disconnect();

This code runs, but now I need to recover some information about network of each VM, specifically:

1)the network labels of each NIC  (for each VM)

2)the Adapter  Type (optionally)

3)Device status: Connected at power on (yes/no) (optionally).

I saw that exists the Managed Object - Network, property of Managed Object - VirtualMachine, but i don't know how to use it in my code and if contains the information i need (maybe "Summary")

Here one example:

network-examples.jpg

in this case i would like to know for this VM

1)LANBACKUP.... ; dvPP_LABO...; dvp_LABO...

and if is possible the information 2) and 3) for each NIC...in this case for NIC LANBAKUP...

2)Flexible

3)Connected at the power on: Yes

Can you help me to integrate my code for retrieve the above information?

Thank you very much, for your help.

Sergio

Reply
0 Kudos