As William pointed out, there aren't really any direct accessor methods and as you found out, the object's are exposed as a series of nested, anonymous hashes.
You can create a utility function if you would like a cleaner accessor. This is probably a good idea since you can build exception handling into it and avoid a lot of messy test code in your main logic branch.
Something like the following would be a good starting point:
#!/usr/bin/perl
use strict;
use warnings;
use VMware::VIRuntime;
Opts::parse();
Opts::validate();
Util::connect();
my ($host_views);
$host_views = Vim::find_entity_views( view_type => "HostSystem",
);
foreach ( @{$host_views} ) {
print "summary.config.name = " . get_value($_, "summary.config.name") . "\n";
print "summary.managementServerIp = " . get_value($_, "summary.managementServerIp") . "\n";
print "summary.bogusProperty = " . get_value($_, "summary.bogusProperty") . "\n";
}
sub get_value {
my ($entity, $value_path) = @_;
my @keys = split(/\./, $value_path);
my $key_ref = $entity;
foreach my $key ( @keys ) {
eval {
$key_ref = $key_ref->{$key};
};
if ($@ || not(defined($key_ref)) ) {
return '';
}
}
return $key_ref;
}
Sample Output:
summary.config.name = vlab-esx-01.vlab.local
summary.managementServerIp =
summary.bogusProperty =
That function will at least catch undefined properties (not all properties from the SDK are guaranteed to be set and accessing them can raise an exception). It does this by making it an empty string to avoid perl warnings about undefined concatenations.
Bear in mind if you use properties => named arguments to your find_entity_view calls, you'll need to access the properties as a full key path. For example, if asked for just "summary.config.name" in such a manner, you'd access it from the host object like $_->{"summary.config.name"}.
You could easily enhance the makeshift accessor method above to check for that possibility (have it just eval the full key path, if that raises an exception, go through the key list as usual).
This might help if you're finding the long, nested anonymous hash references a bit frustrating to work with. I know I find it ugly when I have to deal with numerous, nested hash refs and validate each in the chain is not undefined (unset by the SDK returnval). I use similar accessor methods to avoid my code getting ugly for more complicated perl work.