exlistconfig.pl
Copyright © 2008 VMware, Inc. All rights reserved.
#!/usr/bin/perl -w ####################################################################################### # 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; ####################################################################################### # # exlistconfig.pl # Example script that lists the Config options for a Virtual Machine # Parameters: # -- serverserver name (either VC or ESX dns or ip address) # -- username credentials # -- password # -- vm name of virtual machine to query ####################################################################################### my %opts = ( vm => { type => "=s", variable => "vmName", help => "Virtual Machine Name", required => 1}); # validate options, and connect to the server Opts::add_options(%opts); Opts::parse(); Opts::validate(); Util::connect(); my $vm_name = Opts::get_option ('vm'); my $vm_view = Vim::find_entity_view(view_type => 'VirtualMachine', filter => {'name' => "^$vm_name\$"}); Fail ("Virtual Machine $vm_name was not found.\n") unless ($vm_view); ################################################################################################## # # The environment browser provides information about the vm environment # The QueryConfigOption operation allows you to discover the valid options for ReconfigVM ####################################################################################################### my $env = Vim::get_view (mo_ref => $vm_view->environmentBrowser); my $configOption = $env->QueryConfigOption(); print "Information for Virtual Disk devices for Virtual Machine $vm_name.\n"; my $virtualDeviceOptions = $configOption->hardwareOptions->virtualDeviceOption; #################### Iterate through each virtual device foreach my $descriptor (sort {$a->type cmp $b->type} @$virtualDeviceOptions) { print "Type: ", $descriptor->type, "\n"; print " Online operations: ", ($descriptor->plugAndPlay == 1) ? 'Yes' : 'No', "\n"; print " Controller type: ", $descriptor->controllerType, "\n" if (defined ($descriptor->controllerType)); if ($descriptor->can ('capacityInKB')) { my $size = $descriptor->capacityInKB; my $default = $size->defaultValue; my $min = $size->min; my $max = $size->max; print " Capacity (KB): Default: $default, Min: $min, Max: $max", "\n"; } print " Connectable: Yes" if ($descriptor->can ('connectable')); if (defined ($descriptor->backingOption)) { print " Backing Options:\n"; my $i = 0; foreach my $backing (@{$descriptor->backingOption}) { print " ", $backing->type, ($descriptor->defaultBackingOptionIndex == $i++) ? ' (Default)' : '', "\n"; my @modes; my @extensions; if ($backing->can ('diskMode')) { foreach my $mode (@{$backing->diskMode->choiceInfo}) {push (@modes, $mode->key); } print " Disk modes: ", join (",", @modes), "\n"; print " Growable: ", ($backing->growable == 1) ? 'Yes' : 'No', "\n" if ($backing->can('growable')); } if ($backing->can ('fileNameExtensions')) { foreach (@{$backing->fileNameExtensions->choiceInfo}) {push (@extensions, $_->key); } print " Extensions: ", join (", ", @extensions), "\n"; } elsif ($backing->can ('descriptorFileNameExtensions')) { foreach (@{$backing->descriptorFileNameExtensions->choiceInfo}) {push (@extensions, $_->key); } print " Extensions: ", join (", ", @extensions), "\n"; } } } print "\n"; } # logout Util::disconnect(); sub Fail { my ($msg) = @_; Util::disconnect(); die ($msg); exit (); }
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.