I am using RebootHost_Task API, pinging the ESX server to check if it is up(using Net::Ping module) and then using ExitMaintenanceMode_Task to exit the maintenance mode for the ESX server.
I sometimes get InvalidHostConnectionState fault when I trigger ExitMaintenanceMode_Task. This is because even though the ESX host is pingable, the SOAP request is unsuccessful. Which Vmware perl SDK API can be used to check the host status before triggering ExitMaintenanceMode_Task aPI
Probably the easiest way is to check the HostSystem's runtime.connectionState.
$host = Vim::find_entity_view(view_type => 'HostSystem', properties => ['name', 'runtime.connectionState'], filter => {'name' => $host_name});
$connected = 0;
until ($connected) {
$host->update_view_data();
$connected = $host->{'runtime.connectionState'};
# Add a timeout break here
}
# ...do something with newly rebooted host
I've also used runtime.bootTime in the past, where I wait for the value to be greater than the previous time XSD string recorded before the reboot request (with a long timeout to avoid any problems). This is better than the connectionState option since it handles the window between the reboot request and the actual reboot. It *shouldn't* update until the host is connected again (and available for you call to leave maintenanceMode).
Using these values works even when the host is not connected (cached by the vCenter API service), so you can wait for them to change (and in the case of connectionState, change again). You'll just have to account for the window from the request to reboot and the actual reboot before you start polling using connectionState.
You can probably drop your ping logic as well if you properly code around the API state variables for the Host.
Probably the easiest way is to check the HostSystem's runtime.connectionState.
$host = Vim::find_entity_view(view_type => 'HostSystem', properties => ['name', 'runtime.connectionState'], filter => {'name' => $host_name});
$connected = 0;
until ($connected) {
$host->update_view_data();
$connected = $host->{'runtime.connectionState'};
# Add a timeout break here
}
# ...do something with newly rebooted host
I've also used runtime.bootTime in the past, where I wait for the value to be greater than the previous time XSD string recorded before the reboot request (with a long timeout to avoid any problems). This is better than the connectionState option since it handles the window between the reboot request and the actual reboot. It *shouldn't* update until the host is connected again (and available for you call to leave maintenanceMode).
Using these values works even when the host is not connected (cached by the vCenter API service), so you can wait for them to change (and in the case of connectionState, change again). You'll just have to account for the window from the request to reboot and the actual reboot before you start polling using connectionState.
You can probably drop your ping logic as well if you properly code around the API state variables for the Host.
Hi stumpr,
Thank you for suggesting use of $host->{'runtime.connectionState'};
I needed one more help. How can we find the ESX Host is up, if it is not managed by Vcenter server, before enrolling it to the Vcenter.
You can handle that in a few different ways.
I usually do something like an eval loop and try to hit the ESXi API (assuming it isn't in lockdown mode). Once the API is up, you can be pretty sure it can be added to vCenter. Since you'll need the SSL thumbprint of the ESXi host anyway, usually you can just get that from ESXi API endpoint, or the web file service.
lamw explains how to do it with openssl here
I explain it here
I once looked at using the Net::SSLeay library (if you are comfortable with the CTX_* properties from the OpenSSL C lib) to do the thumbprint extract as well.
Basically, you'll loop-eval the call to the ESXi web service(s), generate the thumbprint, and add the host to vCenter. I usually implement a method with a timeout-waitloop for the host reboot (e.g., 10m timeout & 30s retry intervals)
