VMware {code} Community
VMinator
Contributor
Contributor

datastore->summary->freespace is WRONG. Please help.

Hello,

I hope dome one can help me out to ensure I am not going crazy..

Here is my script i changed a bit from "WLam"... it's simple...

use strict;

use warnings;

use VMware::VILib;

use VMware::VIRuntime;

my %opts = (

datastore => {

type => "=s",

help => "Name of Datastore",

required => 1,

},

);

  1. validate options, and connect to the server

Opts::add_options(%opts);

  1. validate options, and connect to the server

Opts::parse();

Opts::validate();

Util::connect();

my $datastore = Opts::get_option('datastore');

my $host_views = Vim::find_entity_views(view_type => 'HostSystem');

my $found = 0;

foreach(@$host_views) {

my $datastores = Vim::get_views(mo_ref_array => $_->datastore);

foreach(@$datastores) {

if($_->summary->name ne $datastore && $found ne '1') {

my $freespace = $_->summary->freeSpace;

print $freespace;

$found = 1;

}

}

}

Util::disconnect();

Here are my results all the time regardless of LUN..

# /apps/vm/datastore-free.pl --server X.X.X.X --username

blah --password blah --datastore FC-LUN-1

1996096536576

# /apps/vm/datastore-free.pl --server X.X.X.X --username

blah --password blah --datastore FC-LUN-2

1996096536576

# /apps/vm/datastore-free.pl --server X.X.X.X --username

blah --password blah --datastore FC-LUN-3

1996096536576

# /apps/vm/datastore-free.pl --server X.X.X.X --username

blah --password blah --datastore FC-LUN-4

1996096536576

Thanks in advanced.

Tags (2)
0 Kudos
2 Replies
stumpr
Virtuoso
Virtuoso

So in your conditional:

if($_->summary->name ne $datastore && $found ne '1') {

I think you meant for the first ne to be eq. It looks like you're setting your $freespace scalar when the name doesn't match the $datastore scalar and when $found is not 1. So you're likely getting the same datastore freespace value each time, likely the first one returned in the array structure.

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
KostyantynUA
Contributor
Contributor

Hi,

I'm developing solution which uses vSphere for Perl API to get info from VMware infrastructure. One of our customer experiencing problems wih free space cheking functionality. So the environment include DataCenter with 3 VMware hosts. There is DataStore which is attached to all 3 hosts. In normal conditions cheks to 3 hosts and to DataCenter shows nearly the same value. But in some conditions, like storage vMotion or snapshot creation, checks start to show diffrent values. Correct values showed only by host on which changes occur and by DataCenter, other 2 hosts show previous values.

For example:

checks before manipulations on host iESX1 :

iESX1 - Storage_01=84040.00 MB (16.42%)

iESX2 - Storage_01=84137.00 MB (16.44%)

iESX3 - Storage_01=84137.00 MB (16.44%)

checks after :

iESX1 - Storage_01=125000.00 MB (24.43%)

iESX2 - Storage_01=84137.00 MB (16.44%)

iESX3 - Storage_01=84137.00 MB (16.44%)

Our customer found solution to this by restarting mgmt-vmware service. After he restart mgmt-vmware on iESX2 host it starts to show correct values. Values on iESX3 fixed only after an hour.

I tried to add explicit data refresh to a script but this didn't help. Example :

my $store = Vim::get_view(mo_ref => $ref_store, properties => );

$store->RefreshDatastore();

$store->RefreshDatastoreStorageInfo();

$store->Reload();

Maybe there is other way to refresh data on the host ?

0 Kudos