I was reading over some of the already generated perl scripts such as vminfo.pl, although it does not tell me the power status of a VM.
How can I retrieve the power status of a VM? Whether it be on/off/suspended etc.
I've searched around the forum here a little bit and have not found an answer to this yet.
Try something like:
my $vms = Vim::find_entity_views(view_type => 'VirtualMachine');
foreach (@$vms) {
print "VM: " . $_->config->name . ", powerstate: " . $_->runtime->powerState->val . "\n";
}
Try something like:
my $vms = Vim::find_entity_views(view_type => 'VirtualMachine');
foreach (@$vms) {
print "VM: " . $_->config->name . ", powerstate: " . $_->runtime->powerState->val . "\n";
}
Ah, This works perfect!
Output is:
VM: Demo4, powerstate: poweredOn
Great! Thanks!
Quick question...
Is there a way to setup "options" for this file similar to the vm apps files?
e.g powerstatus.pl --vm = somevm
You can indeed setup the command line options similar to other vm apps files by declaring the option as a hash, adding the option to the default options and then parsing and validating the options before connecting to the server:
my %opts = (
entity => {
type => "=s",
variable => "vmname",
help => "Virtual Machine name",
required => 1,
},
);
Opts::add_options(%opts);
Opts::parse();
Opts::validate();
Please refer to "Writing VI Perl Toolkit Scripts" section of VI Perl Toolkit Programming Guide for details:
http://www.vmware.com/support/developer/viperltoolkit/viperl16/doc/viperl_proggd.pdf