VMware Cloud Community
sundarkambamgud
Contributor
Contributor
Jump to solution

Host Status

I'm trying to get a list of ESX hosts from cluster and check the connection state of the host eg; maintenance mode, connected, disconnected etc.  I was able to get the list of ESX hosts from cluster using getallhostsystemsofcluster(cluster).  How do I get the state of host using script.  Any ideas ....

Tags (2)
Reply
0 Kudos
1 Solution

Accepted Solutions
KiwiDave
Enthusiast
Enthusiast
Jump to solution

Try looking at VcHostRuntimeInfo, there will find the objects "connectionState" and "inMaintenanceMode" amongst others.

An example (taking a cluster as input):

for (i in Cluster.host) {

     selectedHost=Cluster.host[i];

     System.log("Host: "+selectedHost.name);

     System.log("Power State: "+selectedHost.runtime.powerState.value);

     System.log("In Maintenance?: "+selectedHost.runtime.inMaintenanceMode);

     if (selectedHost.runtime.powerState.value == "poweredOn" && selectedHost.runtime.inMaintenanceMode == false) {

          //do some action based on this scenario

     }

     //If you want to find the number of runningVms on the cluster (for some reason or other)

     runningVms = 0;
     for(j in Cluster.host[i].vm){
          if(Cluster.host[i].vm[j].runtime.powerState.name=="poweredOn"){
               runningVms++;
          }
     }
     System.log("Total number of running hosts: "+runningVms);

}

View solution in original post

Reply
0 Kudos
5 Replies
Burke-
VMware Employee
VMware Employee
Jump to solution

Like this:

var connectionState = host.runtime.connectionState.value;

where "host" is your VC:HostSystem object.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
sundarkambamgud
Contributor
Contributor
Jump to solution

Thanks for your quick response.

Thanks and Regards

Sundar Sankaranarayanan

Reply
0 Kudos
sundarkambamgud
Contributor
Contributor
Jump to solution

The one liner below returns "Connected" for all ESX hosts.  one of the ESX host in cluster is in maintenance mode and still it returns "Connected", is there a way for the one liner to return the actual state of the ESX host i.e if it is in maintenance mode, it should return as maintenance mode instead of connected.

Reply
0 Kudos
KiwiDave
Enthusiast
Enthusiast
Jump to solution

Try looking at VcHostRuntimeInfo, there will find the objects "connectionState" and "inMaintenanceMode" amongst others.

An example (taking a cluster as input):

for (i in Cluster.host) {

     selectedHost=Cluster.host[i];

     System.log("Host: "+selectedHost.name);

     System.log("Power State: "+selectedHost.runtime.powerState.value);

     System.log("In Maintenance?: "+selectedHost.runtime.inMaintenanceMode);

     if (selectedHost.runtime.powerState.value == "poweredOn" && selectedHost.runtime.inMaintenanceMode == false) {

          //do some action based on this scenario

     }

     //If you want to find the number of runningVms on the cluster (for some reason or other)

     runningVms = 0;
     for(j in Cluster.host[i].vm){
          if(Cluster.host[i].vm[j].runtime.powerState.name=="poweredOn"){
               runningVms++;
          }
     }
     System.log("Total number of running hosts: "+runningVms);

}

Reply
0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

Oops... sorry about that, I kinda rushed that in a test lab that only had a single host available Smiley Wink Try Dave's code, likely to get better results...

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
Reply
0 Kudos