Hey guys,
i wrote(tried) to create a script that counts my cpus, cores, threads in my vcenter.
I receive the following error "ERROR: No session file or username/password provided"
My Code:
#!/usr/bin/perl -w
use warnings;
use VMware::VIRuntime;
use VMware::VILib;
connect to the server and login
Util::connect();
my $cpucount=0;
my $corecount=0;
my $threadcount=0;
get all hosts under Cluster
my $host_view = Vim::find_entity_views(view_type => 'HostSystem',);
foreach (@$host_view) {
print "Hostname: ", $_->name, "\n";
print "CPUs: ", $_->hardware->cpuInfo->numCpuPackages, "\n";
$cpucount = $cpucount + $_->hardware->cpuInfo->numCpuPackages;
print "CPU cores: ", $_->hardware->cpuInfo->numCpuCores, "\n";
$corecount = $corecount + $_->hardware->cpuInfo->numCpuCores;
print "CPU Threads: ", $_->hardware->cpuInfo->numCpuThreads, "\n";
$threadcount = $threadcount + $_->hardware->cpuInfo->numCpuThreads;
print "\n";
}
print "Summary :\n";
print "CPUs: ", $cpucount, "\n";
print "Cores: ", $corecount, "\n";
print "Threads: ", $threadcount, "\n";
close server connection
Util::disconnect();
You're missing your credentials section for gathering username and password and I guess it defaults to expecting you provides a session file which includes the username and password. Take a look at any of the vCLI example scripts, you'll want to add the following:
Opts::parse(); Opts::validate(); Util::connect();
This will force the script to validate for --server, --username and --pasword if you have not already specified.
=========================================================================
William Lam
VMware vExpert 2009,2010
VMware scripts and resources at:
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
You're missing your credentials section for gathering username and password and I guess it defaults to expecting you provides a session file which includes the username and password. Take a look at any of the vCLI example scripts, you'll want to add the following:
Opts::parse(); Opts::validate(); Util::connect();
This will force the script to validate for --server, --username and --pasword if you have not already specified.
=========================================================================
William Lam
VMware vExpert 2009,2010
VMware scripts and resources at:
Getting Started with the vMA (tips/tricks)
Getting Started with the vSphere SDK for Perl
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
Hey William,
thanks for your help
<code>Opts::parse(); Opts::validate()</code>
did the trick!