VMware {code} Community
Aristizabal
Enthusiast
Enthusiast
Jump to solution

Simple Perl code to get VM parent host

Hello,

I am struggling with the object usage in perl; my goal is to pass a VM name as parameter and return some information of the ESXi parent host:

use strict;

use Data::Dumper;

use VMware::VIRuntime;

# Auth options

Opts::set_option('server', 'vCenter');

Opts::set_option('username', 'user1l');

Opts::set_option('password', 'password1');

print "Connecting \n";

Util::connect();

print "Connected \n";

my $VMView = Vim::find_entity_view(

'view_type' => 'VirtualMachine',

'filter' => { 'name' => 'eduv0002',}

);

print $VMView->summary->config->name,"\n";

                  print $VMView->runtime->host,"\n";

my $HostRef = $VMView->runtime->host;

print $HostRef;

Util::disconnect();

But the output is:


Connecting

Connected

vm-test

ManagedObjectReference=HASH(0x2435648)

Undefined subroutine &ManagedObjectReference::name called at ./test.pl line 24

So it looks like I can get the host with no issues but I don't know how to access its properties having a Managed Object Reference.

Any help is appreciated, thank you.

Juan.

Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
stumpr
Virtuoso
Virtuoso
Jump to solution

You have a MOREF from the runtime.host property, you need another get_view call on it.

my $host = Vim::get_view(mo_ref => $HostRef);

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

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

View solution in original post

2 Replies
stumpr
Virtuoso
Virtuoso
Jump to solution

You have a MOREF from the runtime.host property, you need another get_view call on it.

my $host = Vim::get_view(mo_ref => $HostRef);

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

Reuben Stump | http://www.virtuin.com | @ReubenStump
Aristizabal
Enthusiast
Enthusiast
Jump to solution

Perfect, thanks for the quick reply.

Reply
0 Kudos