HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
HPE Storage Tech Insiders
cancel
Showing results for 
Search instead for 
Did you mean: 

Reload inaccessible or invalid VMs

mamatadesaiNim

 

Have you ever had a blip in your network, or a temporary network outage?  Has your VMware vSphere environment recovered completely after that?  Or did you end up in an annoying situation where your network/FC storage (iSCSI, FCoE, NFS, FC) took a little "longer" to come up, as compared to your ESXi servers?  In such cases, you may end up with a situation where the VMs in your vSphere environment show up as "inaccessible".  One way to remedy the situation is to unregister each VM and re-register the VM's vmx file to vCenter or the ESXi host.  But if you have an environment larger than 10 VMs, this can become a tedious, manual task.  Within our QA environments, we often end up breaking things and need a fast, automated way to recover.


Inaccessible_VMs.PNGInaccessible VMs

Command-line scripts with vim-cmd

VMware KB 1026043 outlines this solution: reload the VM's vmx file on the ESXi host using the vim-cmd commands: 

  1. Get the VM's Vmid with this command, to identify your VM:      #vim-cmd vmsvc/getallvms
  2. Reload the VMX using the reload command:      #vim-cmd vmsvc/reload Vmid

A one-liner script combining the two steps above, to be run on each ESXi server in your environment, as root:

for a in $(vim-cmd vmsvc/getallvms 2>&1 | grep invalid | awk '{print $4}' | cut -d \' -f2); do vim-cmd vmsvc/reload $a; done

In large environments, this can be a tedious job.  Within a QA environment with 8 servers too, we wanted this automated.  An option was indeed to configure password-less root ssh into each ESXi server, and run the script from a central desktop.  But we wanted something more secure, less error-prone and with fewer breaking points.

PowerCLI to the rescue

A little more searching fetched us a PowerCLI one-liner solution!  Logging in as administrator in your vCenter, you can execute this and it runs on ALL VMs in your inventory, on ALL ESXi servers.

(Get-View -ViewType VirtualMachine) | ?{$_.Runtime.ConnectionState -eq "invalid" -or $_.Runtime.ConnectionState -eq "inaccessible"} | %{$_.reload()}

Source: from techazine or hypervisor.fr

Let's break it down to understand the parts of this one-liner:

  • Get-View -ViewType VirtualMachine
    Retrieves all VMs in your vCenter inventory.  The next part:
  •  ?{$_.Runtime.ConnectionState -eq "invalid" -or $_.Runtime.ConnectionState -eq "inaccessible"}
    This filters the VMs and looks for invalid or inaccessible VMs only.  The last part:
  • %{$_.reload()}
    This calls the vSphere reload API.

Voila!  Just like that, your VMs are all back online and accessible!

HPE Nimble Storage
About the Author

mamatadesaiNim

VMware and Nimble Storage QA engineer

Events
Nov 27 - 29
Madrid, Spain
HPE Discover 2018 Madrid
Learn about all things HPE Discover 2018 in Madrid, Spain, 27 - 29 November, 2018.
Read more
See posts for
dates/locations
HPE at 2018 Technology Events
Learn about the technology events where Hewlett Packard Enterprise will have a presence in 2018.
Read more
View all