VMware Cloud Community
orian
Hot Shot
Hot Shot
Jump to solution

query hosts

Hi,

I get all the hosts from a cluster with the command:

var hosts = cluster.getAllHostSystemOfCluster();

I want to pass over the array of hosts, and check if the host is available and not in maintenance mode and get all the datastore from the host.

Thanks!

0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Check documentation for host system object (VcHostSystem / VC:HostSystem) - it has a property named datastore which returns an array of datastores that are available in this host system.

Here is some sample code showing how to enumerate datastores for a given host system (input variable is host of type VC:HostSystem)

var all = host.datastore;

for each (var ds in all) {

  System.log("datastore: " + ds);

}

View solution in original post

0 Kudos
4 Replies
sbeaver
Leadership
Leadership
Jump to solution

ok to find out if a host is in MM the command is :   vcHost.summary.runtimre.inMaintenanceMode

To get all the datastores for a host there is an action called getAllDatastoreOnVimHost that will do that for you.  You can find that here: com.vmware.library.vc.datastore

As for status, depending on what you want to know you can start here:  var vimStat = vcHost.overallStatus

Cheers!!

Steve Beaver
VMware Communities User Moderator
VMware vExpert 2009 - 2020
VMware NSX vExpert - 2019 - 2020
====
Co-Author of "VMware ESX Essentials in the Virtual Data Center"
(ISBN:1420070274) from Auerbach
Come check out my blog: [www.virtualizationpractice.com/blog|http://www.virtualizationpractice.com/blog/]
Come follow me on twitter http://www.twitter.com/sbeaver

**The Cloud is a journey, not a project.**
0 Kudos
orian
Hot Shot
Hot Shot
Jump to solution

Hi,

Thank you for your answer.

But the action you provided receive for input vCenter object and not esx host.

In your case, I receive all the datastores in the vCenter.

In my case, I have several clusters in my vCenter, and I want to receive the datastores of a specific esx host.

Thanks!

0 Kudos
orian
Hot Shot
Hot Shot
Jump to solution

any idea?

0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Check documentation for host system object (VcHostSystem / VC:HostSystem) - it has a property named datastore which returns an array of datastores that are available in this host system.

Here is some sample code showing how to enumerate datastores for a given host system (input variable is host of type VC:HostSystem)

var all = host.datastore;

for each (var ds in all) {

  System.log("datastore: " + ds);

}

0 Kudos