VMware Virtual Machine Reconfiguration Webinar Sample Code

VMware using the VI API for Enhanced Performance Management Webinar: Printer Intervals Sample Code

printintervals.pl

Copyright © 2008 VMware, Inc. All rights reserved.

#!/usr/bin/perl -w
#
# Copyright 2006 VMware, Inc.  All rights reserved.
#################################################################################
# printintervals.pl
#    Print the intervals for an entity.
#     --server  --username <u> --password 
#	--entity                     VirtualMachine, HostSystem, ComputeResource, ResourcePool
#	Script provided as a sample.
#	DISCLAIMER. THIS SCRIPT IS PROVIDED TO YOU "AS IS" WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
#     WHETHER ORAL OR WRITTEN, EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES 
#     OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. 
###################################################################################

use strict;
use warnings;
use Getopt::Long;
use VMware::VIRuntime;
use VMware::VILib;

my %opts = (
   entity  => {
      type     => "=s",
      variable => "entity",
      help     => "Entity (VirtualMachine, HostSystem, ComputeResource, ResourcePool",
      required => 1});

# validate options, and connect to the server
Opts::add_options(%opts);
Opts::parse();
Opts::validate();
Util::connect();
my $entity = Opts::get_option ('entity');

my $entity_view = Vim::find_entity_view(view_type => $entity);
die "Entity $entity not found\n" unless ($entity_view);

my $service = Vim::get_service_content();
my $perfmgr_view = Vim::get_view(mo_ref => $service->perfManager);
my $historical_intervals = $perfmgr_view->historicalInterval;
my $provider_summary = $perfmgr_view->QueryPerfProviderSummary(entity => $entity_view);
print "Source: " . $service->about->fullName . "\n";
print "Entity Name: ". $entity_view->name . " [" . ref($entity_view) . "]\n";
print "Supports real-time stats: ", ($provider_summary->currentSupported) ? 'Yes' : 'No', "\n";
print "Refresh rate: " , $provider_summary->refreshRate, "\n";
print "Supports historical stats: ", ($provider_summary->summarySupported) ? 'Yes' : 'No', "\n";
my @intervals;
foreach (@$historical_intervals) {
   push @intervals, $_->samplingPeriod;
   }
print "Historical intervals (seconds) : ", join (",", @intervals), "\n";

Util::disconnect();

The sample code is provided "AS-IS" for use, modification, and redistribution in source and binary forms, provided that the copyright notice and this following list of conditions are retained and/or reproduced in your distribution. To the maximum extent permitted by law, VMware, Inc., its subsidiaries and affiliates hereby disclaim all express, implied and/or statutory warranties, including duties or conditions of merchantability, fitness for a particular purpose, and non-infringement of intellectual property rights. IN NO EVENT WILL VMWARE, ITS SUBSIDIARIES OR AFFILIATES BE LIABLE TO ANY OTHER PARTY FOR THE COST OF PROCURING SUBSTITUTE GOODS OR SERVICES, LOST PROFITS, LOSS OF USE, LOSS OF DATA, OR ANY INCIDENTAL, CONSEQUENTIAL, DIRECT, INDIRECT, OR SPECIAL DAMAGES, ARISING OUT OF THIS OR ANY OTHER AGREEMENT RELATING TO THE SAMPLE CODE.

You agree to defend, indemnify and hold harmless VMware, and any of its directors, officers, employees, agents, affiliates, or subsidiaries from and against all losses, damages, costs and liabilities arising from your use, modification and distribution of the sample code.

VMware does not certify or endorse your use of the sample code, nor is any support or other service provided in connection with the sample code.