I'm a windows tech by trade and I'm looking at a patching script to download all of the patches via ftp and apply. Thanks \[Dominic Rivera (dominic@vmprofessional.com)]. What I'd like to do is at the top of the script, check to see if the ESX host is in maintenace mode because I don't want anybody patching servers with VMs up and running (obviously most of the patches fail anyhow).
Could someone post a snippet of perl that would check if the host is in maintenance mode, if so echo that it is and break out of the script?
Much appreciated.
here we go (perl):
sub get_host_view {
my $view_name = $_[0];
$view_name =~ s/ //g;
my $host_view = Vim::find_entity_view(view_type => 'HostSystem',
filter => \{'name' => $view_name});
if(!$host_view) {
return undef;
}
return $host_view;
}
sub querymaintenance{
my ($args) = @_;
my($host) = $args =~ /(.+)/;
if (!$host){
return;
}
$host =~s/ //g;
my $host_view = get_host_view($host);
if($host_view){
print $host_view->\{summary}->\{runtime}->\{inMaintenanceMode} ."\n";
}
}
querymaintenance("HostName");
#####
Or simply on the shell. This might be more relevant for you due to using the batchscript on the shell anyway:
if \[ -n "`vimsh -n -e hostsvc/runtimeinfo |grep Maintenance |grep true`" ];
then echo 1; #is in mm
else echo 0; #is not in mm
fi
Hope this helps!
Ryan,
Check out the following thread: http://www.vmware.com/community/thread.jspa?messageID=502871񺱗
Mittel indicates that there are some sample scripts with the VI perl toolkit. I can look at it tomorrow when I get back to work and perhaps assist.
Keep in mind that maintenance mode only migrates all the vm's off the host if it is part of a DRS cluster. If you do not use DRS, the VM's will keep running, you just can't power up any new VM's.
Sincerely,
Daniel Bischops
Keep in mind that maintenance mode only migrates all
the vm's off the host if it is part of a DRS cluster.
If you do not use DRS, the VM's will keep running,
you just can't power up any new VM's.
Partially True Statement.
When you request to put a host in maintenance mode, if it is in fully automated DRS mode. DRS will migrate all vms and then the host will go into maintenance mode.
When you request to put a host in maintenance mode and do not have fully automated DRS. The host will state "entering maintenance mode" will not allow new vms to power on and will wait until all vms are powered off or migrated manually before going into maintenance mode.
here we go (perl):
sub get_host_view {
my $view_name = $_[0];
$view_name =~ s/ //g;
my $host_view = Vim::find_entity_view(view_type => 'HostSystem',
filter => \{'name' => $view_name});
if(!$host_view) {
return undef;
}
return $host_view;
}
sub querymaintenance{
my ($args) = @_;
my($host) = $args =~ /(.+)/;
if (!$host){
return;
}
$host =~s/ //g;
my $host_view = get_host_view($host);
if($host_view){
print $host_view->\{summary}->\{runtime}->\{inMaintenanceMode} ."\n";
}
}
querymaintenance("HostName");
#####
Or simply on the shell. This might be more relevant for you due to using the batchscript on the shell anyway:
if \[ -n "`vimsh -n -e hostsvc/runtimeinfo |grep Maintenance |grep true`" ];
then echo 1; #is in mm
else echo 0; #is not in mm
fi
Hope this helps!
Awesome. Exactly what I was looking for.
Thanks!
Dont suppose you would also have the VB commands for the SDK to put a host in maintenance mode?
no VB, sorry
Can anyone help out to integrate this bit of code into esx-autopatch.pl so that patching stops of the host isn't in maintenance mode????
Sorry - haven't found my feet with perl yet!!
Patches that can not be installed with live VMs already have logic to abort if this is the case, not sure why you need this check again? The very first patch released is such an example.