Information Technology Reference
In-Depth Information
# define the options we need for our script
my %opts = (
# we can use the special _default_ so that we do not have
# to provide a command line switch when calling our script.
# The last parameter is assumed to be the clustername
'_default_' => {
# this parameter is a string
type => ″=s″,
# what is reported when the user passes the --help option
help => ″Name of the cluster to report hosts for″,
# boolean to determine if the option is mandatory
required => 1
}
);
# add the options to the standard VMware options
Opts::add_options(%opts);
# parse the options from the command line
Opts::parse();
# ensure valid input was passed
Opts::validate();
# the user should have passed, or been prompted for, a
# username and password as two of the standard VMware
# options. connect using them now...
Util::connect();
# search the connected host (should be vCenter) for our cluster
my $clusterName = Opts::get_option('_default_');
my $clusterView = Vim::find_entity_view(
view_type => 'ClusterComputeResource',
filter => { name => qr/($clusterName)/i }
);
# ensure that we found something
if (! $clusterView) {
VIExt::fail(″A cluster with name ″ . $clusterName . ″ was not found!″);
}
# now we want to search for hosts inside the cluster we just
# retrieved a reference to
my $hostViews = Vim::find_entity_views(
Search WWH ::




Custom Search