I'm trying to get the list of Hosts in a specific datacenter. I have the code below (VB.NET) to create the PropertyFilterSpec that gives me the info I need from Datastores and Networks but I can't get the Hosts names. Many tries, all failed. Any ideas?
thanks!
======== code ==========
Public Function createPfSpecDatacenter(ByVal dCenterRef As ManagedObjectReference) As PropertyFilterSpec
Dim tspec As TraversalSpec = New TraversalSpec()
tspec.type = "Datacenter"
tspec.path = "datastore"
Dim NWspec As TraversalSpec = New TraversalSpec()
NWspec.type = "Datacenter"
NWspec.path = "network"
Dim pspec As PropertySpec = New PropertySpec()
pspec.type = "Datastore"
pspec.all = False
pspec.pathSet = New String() \{"summary.freeSpace", "summary.name"}
Dim NWpspec As PropertySpec = New PropertySpec()
NWpspec.type = "Network"
NWpspec.all = False
NWpspec.pathSet = New String() \{"name"} ', "host"}
Dim ospec As ObjectSpec = New ObjectSpec
ospec.obj = dCenterRef
ospec.skip = True
ospec.selectSet = New SelectionSpec() \{NWspec, tspec}
Dim pfSpec As PropertyFilterSpec = New PropertyFilterSpec()
pfSpec.propSet = New PropertySpec() \{NWpspec, pspec}
pfSpec.objectSet = New ObjectSpec() \{ospec}
Return pfSpec
End Function
Inplace of
pspec.pathSet = New String() \{"summary.freeSpace", "summary.name"}
try
pspec.pathSet = New String() \{"host.Summary.ConfigSummary.name"}
I tried that but it doesn't seem to be a correct path: RetrieveProperties returns Null.
On the other hand just leaving 'host' (pspec.pathSet = New String() \{"host"} ) does return values but none have the actual host name.
IMHO, your problem is that you don't have a traversal spec that will traverse down to the level of HostSystems. Datacenter doesn't have a direct link to HostSystem, like it does for Datastore and Network.
To be slightly more specific, you need a traversal spec from Datacenter to the "hostFolder" property, from Folder to the "childEntity" property, and from ComputeResource to the "host" property. You then need a property spec for "HostSystem" that grabs the "name" property.
I'm not coding in VB so I've got no code to give you, but if you look through the forum there should be multiple examples of building a full traversal hierarchy.
@bclow,
that's not the answer I was hoping for but the one I was expecting nonetheless. I already have a traversal spec to get the HostSystem name but I was hoping to retrieve a specific datacenter's Datastores, Networks AND Hosts all in one swoop. I guess not...
Thanks!