VMware Communities > Developer Community > VMware vSphere™ Web Services SDK, CIM SDK > Discussions

This Question is Answered

2 "helpful" answers available (6 pts)
8 Replies Last post: Feb 6, 2008 11:14 PM by A.Mikkelsen
Reply

list VMs with disks and show value in vcenter

Jan 30, 2008 9:43 AM

Click to view meistermn's profile Master meistermn 1,094 posts since
Dec 7, 2004
Can one show how to combined the script from hrobison and the script from run-virtual.com

At the end of the thread http://communities.vmware.com/thread/115635?tstart=0 is script exprintcustomfield.com

From the script http://www.run-virtual.com/files/vi3_diskfree.zip I took the part

that creates the custom field:

if (defined $customFieldsManager->{field}) #---- Are there any custom fields?
{
my $fields = $customFieldsManager->{field};
foreach(@$fields) #---- Check existing custom fields if 'DiskFree' or 'DiskFree%' exists
{
#print "Field name:\t" . $_->name . "\n";
if ($_->name eq "DiskFree")
{
$diskFreeKey = $_->key;
}
if ($_->name eq "DiskFree%")
{
$diskPercentKey = $_->key;
}
if ($_->name eq "DiskFree Alert")
{
$diskAlertKey = $_->key;
}
}
}

if ($diskFreeKey == -1 ) #---- If no custom field called 'DiskFree' is found, let's create it
{
my $result = $customFieldsManager-> AddCustomFieldDef(name=>"DiskFree");
$diskFreeKey = $result->key;
}
if ($diskPercentKey == -1 ) #---- If no custom field called 'DiskFree%' is found, let's create it
{
my $result = $customFieldsManager-> AddCustomFieldDef(name=>"DiskFree%");
$diskPercentKey = $result->key;
}
if ($diskAlertKey == -1 ) #---- If no custom field called 'DiskFree Alert' is found, let's create it
{
my $result = $customFieldsManager-> AddCustomFieldDef(name=>"DiskFree Alert");
$diskAlertKey = $result->key;
}

The problem part is to get the value in the field. It is $thisVM variable.

$customFieldsManager -> SetField(entity => $thisVM,
key=> $diskFreeKey,
value => int($diskFreeTotalMB). " MB"
);

Reply Re: list VMs with disks and show value in vcenter Jan 30, 2008 10:43 PM
Click to view ssurana's profile Hot Shot ssurana 132 posts since
Oct 1, 2007
VMware
Hi,

I had a quick look at the code exprintcustomfield.pl and found a minor issue that was causing the problem.
I have modified the code at line# 151 in the script and now it works fine.

In the Code:

$customFieldsManager -> SetField(entity => $thisVM,
key=> $diskFreeKey,
value => int($diskFreeTotalMB). " MB"
);

the "$thisVM" needs to be the MOR of the VM whereas you were passing the name of the VM.

Hope this helps

~ Sidharth
Attachments:
Reply Re: list VMs with disks and show value in vcenter Feb 4, 2008 12:06 AM
in response to: ssurana
Click to view A.Mikkelsen's profile Expert A.Mikkelsen 452 posts since
Feb 27, 2006

Take a look at my script to add information to VC.

It is based on the one from Run-virtual.com but heavelly modified to show more info.

http://www.amikkelsen.com/?p=44

Regards
A. Mikkelsen

Reply Re: list VMs with disks and show value in vcenter Feb 4, 2008 12:08 PM
in response to: A.Mikkelsen
Click to view meistermn's profile Master meistermn 1,094 posts since
Dec 7, 2004
Your Script has a Bug
Reply Re: list VMs with disks and show value in vcenter Feb 4, 2008 11:51 PM
in response to: meistermn
Click to view A.Mikkelsen's profile Expert A.Mikkelsen 452 posts since
Feb 27, 2006

Where ?

In what section ?

Regards
A. Mikkelsen

Reply Re: list VMs with disks and show value in vcenter Feb 5, 2008 4:18 AM
in response to: A.Mikkelsen
Click to view meistermn's profile Master meistermn 1,094 posts since
Dec 7, 2004
it seems to be in 228 to 253 , the diskfree part.
Reply Re: list VMs with disks and show value in vcenter Feb 6, 2008 2:45 AM
in response to: meistermn
Click to view A.Mikkelsen's profile Expert A.Mikkelsen 452 posts since
Feb 27, 2006

I know that the script has that bug.

But if one VM has tools installed the bug isn't a problem and the script runs.

Regards
A. Mikkelsen

Reply Re: list VMs with disks and show value in vcenter Feb 6, 2008 11:47 AM
in response to: A.Mikkelsen
Click to view meistermn's profile Master meistermn 1,094 posts since
Dec 7, 2004

i removed the diskfree part and the script runs without a problem.

I tested this for 340 vm's. Anyway you did a good job.

Reply Re: list VMs with disks and show value in vcenter Feb 6, 2008 11:14 PM
in response to: meistermn
Click to view A.Mikkelsen's profile Expert A.Mikkelsen 452 posts since
Feb 27, 2006

Thanks

I'll try to fix the bug asap.

Regards
A. Mikkelsen

Actions