- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lot!!!!
I did some tests and almost everything works.
The only problem I encounter is with a VM that has two NICs with Distributed Virtual Switch:
The name of this VM is LABO-TEST-MACHINE, and this is the output of the perl scripts:
[...]
VM Name: LABMXXXXX
NIC type: VirtualE1000
nic 'Network adapter 1':
network portgroup: LANBACKUP_LABO
NIC type: VirtualE1000
NIC type: VirtualE1000
nic 'Network adapter 2':
network portgroup: HEARTBEAT_XXX
NIC type: VirtualE1000
VM Name: LABO-TEST-MACHINE
NIC type: Flexible
nic 'Network adapter 1':
network portgroup: LANBACKUP_LABO
NIC type: Flexible
NIC type: Flexible
Can't call method "type" on an undefined value at /usr/share/perl/5.10/VMware/VICommon.pm line 1026.
How you can see, i receive the error above, only when the script try to extract the Network Portgroup of that VM.
I think the code line with the problem is:
$pg = Vim::get_view(mo_ref => $pg_mo, properties => ['name']);
Instead with the Standard Virtual Switch, i didn't encounter problems.
Here's all new code:
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', properties => ['name', 'config.hardware.device'], begin_entity => $cluster_view);
foreach (@$vm_views) {
print $_->name . "\n";
# $vm = $_->name;
my @devs = @{ $_->{'config.hardware.device'} };
my @net_devs = grep { $_->isa('VirtualEthernetCard') } @devs;
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;
}
print " NIC type: $type\n";
$pg_mo = $nic->{'backing'}{'network'};
$pg = Vim::get_view(mo_ref => $pg_mo, properties => ['name']);
$network = $pg->{'name'};
# $connect = ( eval {$nic->{'connectable'}{'startConnected'} ) ? 1 : 0;
$name = $nic->{'deviceInfo'}{'label'};
print " nic '$name':\n";
# print " connect on power on: $connect\n";
print " network portgroup: $network\n";
print " NIC type: $type\n";
}
}
}
Util::disconnect();