vSphere

 View Only
  • 1.  Help with a script that tries to gather info

    Posted Sep 27, 2012 04:39 PM

    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.



  • 2.  RE: Help with a script that tries to gather info

    Posted Sep 28, 2012 02:38 AM

    You have to check your backing type since there are differences between a DistributeVirtualPortgroup and a standard Portgroup.



  • 3.  RE: Help with a script that tries to gather info

    Posted Sep 28, 2012 10:38 AM

    OK, that's it! Many thanks!

    It only works with Standard Switches. Do you know who is the right object and proporti for Distributed Switches? I'm trying with some of them (VirtualEthernetCardDistributedVirtualPortBackingInfo, DistributedVirtualSwitch, DistributedVirtualPortGroup, etc.) but still without success :smileysad:



  • 4.  RE: Help with a script that tries to gather info

    Posted Sep 28, 2012 02:21 PM

    Working from memory here...

    Your backing type in the case of a Distributed Virtual Switch Portgroup will be a 'VirtualEthernetCardDistributedVirtualPortBackingInfo'.  From that, you can get the 'portgroupKey'.  That key should be a UUID type value, which you can use to find the DistributedVirtualPortgroup by comparing it with the DistributedVirtualPortgroup.key values.  That will have a 'name' property that is probably the value you want (portgroup name).

    You can probably do something like the following once you get your portgroupKey -

    $pgKey = <key value from VirtualEthernetCardDistributedVirtualPortBackingInfo>;

    $dvpg = find_entity_view( view_type => 'DistributedVirtualPortgroup', filter => { 'key' => $pgKey }, properties => [ 'name' ] );

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

    If you were looking for speed in your script, you could fetch all the Network and DistributedVirtualPortgroup entities and store them in a hash for later lookup to avoid the multiple SDK calls.



  • 5.  RE: Help with a script that tries to gather info

    Posted Oct 02, 2012 01:14 PM

    Thank you very much! I will give it a try this week and will share the results with you. From my ignorance, it seems to be right!