Updating View
Objects
In any view, the values of the view
properties represent the state of the server-side objects at the time the view
was created. These property values are not updated automatically.
In a production environment, the state of managed
objects on the server is likely to change frequently. If your client script
depends on the server being in a particular state (
poweredOn
or
poweredOff
, for example), then you can refresh the view
object’s state. You can use the vSphere SDK for Perl
Vim::update_view_data()
subroutine to refresh the values of client-side views with server-side values.
Updating the State of View Objects
uses
Vim::update_view_data()
to
refresh view data.
Updating the State of View Objects
#!/usr/bin/perl use strict; use warnings; use VMware::VIRuntime; . . . # Get all VirtualMachine objects my $vm_views = Vim::find_entity_views(view_type => 'VirtualMachine'); # Power off virtual machines. foreach my $vm (@$vm_views) { # Refresh the state of each view $vm->update_view_data(); if ($vm->runtime->powerState->val eq 'poweredOn') { $vm->PowerOffVM(); print " Stopped virtual machine: " . $vm->name . "\n"; } else { print " Virtual machine " . $vm->name . " power state is: " . $vm->runtime->powerState->val . "\n"; } }