VMware Cloud Community
pod86
Contributor
Contributor
Jump to solution

List all hosts connected to Datastore

Hi all,

I'm trying to perform a simple task which doesn't seem to work as expected.

vRO, i would like to input a datastore and output a list of hosts connected to that datastore:

action element:

in param = datastore

type VC:datastore

return type: ARRAY/VC:HostSystem

script:

return datastore.host;

error:

Unable to convert object, no sdk type defined for class : com.vmware.vim.vi4.DatastoreHostMount@

Many thanks for your help.

Regards,

Pod

1 Solution

Accepted Solutions
sbeaver
Leadership
Leadership
Jump to solution

I am going to assume that you are creating this as an action and if so, did you define the output of the action as a HostSystem?

Give this a shot

script:

var hosts = new Array();

var dsMounts = datastore.host;

for each (var i in dsMounts) {

     host.push(i.key);

}

return hosts;

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.**

View solution in original post

2 Replies
sbeaver
Leadership
Leadership
Jump to solution

I am going to assume that you are creating this as an action and if so, did you define the output of the action as a HostSystem?

Give this a shot

script:

var hosts = new Array();

var dsMounts = datastore.host;

for each (var i in dsMounts) {

     host.push(i.key);

}

return hosts;

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.**
jacksonecac
Enthusiast
Enthusiast
Jump to solution

This looks correct as the array that datastore.host does not return an array of hostsystems as thought by the author.

0 Kudos