cmartinvalle
Contributor
Contributor

Help with a script that tries to gather info

Hi,

I have this piece of code:

my $vm_view = Vim::find_entity_views(view_type => 'VirtualMachine');
my $vnic_name;
my $vnic_device;
foreach(@$vm_view) {
        my $vm_name = $_->summary->config->name;
        my $devices =$_->config->hardware->device;
        my $mac_string;
        my $network = "";
        foreach(@$devices) {
                if($_->isa("VirtualEthernetCard")) {
                        $mac_string .= "\t\t[" . $_->deviceInfo->label . "] : " . $_->macAddress . "\n";
                }
                if ($_->deviceInfo->label eq $vnic_name){
                        $vnic_device=$_;
                        print "\t$vnic_device\n";
                        my $currMac = $vnic_device->macAddress;
                        print "\t$currMac\n";
                        my $network = Vim::get_view(mo_ref => $_->backing->network, properties => ['name']);
                        print "\t" . $network->{'name'} . "\n";
                }
        }

And when executing it, the output is:

Undefined subroutine &VirtualEthernetCardDistributedVirtualPortBackingInfo::network called at getAllVMMacs.pl line 38

But I want to gather info from the object VirtualEthernetCardNetworkBackingInfo, not from VirtualEthernetCardDistributedVirtualPortBackingInfo, I suppose the problem is in this line: "my $network = Vim::get_view(mo_ref => $_->backing->network, properties => ['name']);" but I don't know how to invoke to the right object, does anyone know how to do it?

Many thanks.

Reply
0 Kudos