I am wanna to connect my Vcenter to show one cluster all vms ,but it report error :Can't call method "serialize" on unblessed reference at /usr/lib/perl5/5.8.8/VMware/VICommon.pm line 2435.
I want to show cpu ,mem ,net ,io static ,and write all these data to mysql ,but I am stuck here .
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use utf8;
use VMware::VIRuntime;
use VMware::VILib;
my %opts = (
cluster => {
type =>"=s" ,
help => "Enter the Cluster name" ,
required => 1,
}
);
#connect the host
Opts::add_options(%opts);
Opts::parse();
Opts::validate();
Util::connect();
#script start
my $cluster = Vim::find_entity_views (view_type =>'ClusterComputeResource',
properties => ['name'],
filter =>{'name' =>Opts::get_option('cluster')});
my $vms = Vim::find_entity_views( view_type=>'VirtualMachine',
properties => ['name'],
begin_entity => $cluster );
foreach my $vm ( @{$vms || []} ) {
my $vmname = '"' . $vm->{'name'} . '"';
print $vmname;
}
Util::disconnect;
~