VMware {code} Community
benma
Hot Shot
Hot Shot
Jump to solution

ERROR: No session file or username/password provided

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;

  1. connect to the server and login

Util::connect();

my $cpucount=0;

my $corecount=0;

my $threadcount=0;

  1. 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";

  1. close server connection

Util::disconnect();

Reply
0 Kudos
1 Solution

Accepted Solutions
lamw
Community Manager
Community Manager
Jump to solution

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:

Twitter: @lamw

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

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

View solution in original post

Reply
0 Kudos
2 Replies
lamw
Community Manager
Community Manager
Jump to solution

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:

Twitter: @lamw

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

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

Reply
0 Kudos
benma
Hot Shot
Hot Shot
Jump to solution

Hey William,

thanks for your help

<code>Opts::parse();
Opts::validate()</code>

did the trick! 

Reply
0 Kudos