el1988
Contributor
Contributor

Inventory List like in VI Client

Hi,

i'm trying to build an inventory list like the VI Client does. I thought retrieving the childEntities from the rootFolder and then recursively retrieving the properties of the ManagedEntities based on their type would work, but i have a problem.

Here is what i have:

I'm running the command: tvInventory.Nodes.Add(GetInventory(VMware.SERVICE_CONTENT.rootFolder))

Private Function GetInventory(ByVal root As ManagedObjectReference) As TreeNode

Dim tNode As New TreeNode

Dim oContent() As ObjectContent

If root.type = "Folder" Then

Dim pSpec As New PropertySpec

Dim subNode As TreeNode

'Get ManagedEntitties from the folder

pSpec.type = "ManagedEntity"

'Get the property "name"

pSpec.pathSet = New String() {"name"}

'Retrive the properties

oContent = VMware.GetFromInventory(New PropertySpec() , root, "childEntity")

'Loop through all found items

For i As Integer = 0 To oContent.Count - 1

'Create a new node

subNode = tNode.Nodes.Add(oContent(i).obj.type & ": " & oContent(i).propSet(0).val)

'Recursively get other properties depending on their type

subNode.Nodes.Add(GetInventory(oContent(i).obj))

Next

ElseIf root.type = "Datacenter"

'Handle other types

End If

Return tNode

End Function

Public Function GetProperties(ByVal SearchObject() As PropertySpec, ByVal rootObject As ManagedObjectReference, ByVal rootObjectProperty As String) As ObjectContent()

Dim propFilterSpec As New PropertyFilterSpec

Dim tSpec As New TraversalSpec

tSpec.type = rootObject.type

tSpec.path = rootObjectProperty

tSpec.name = rootObject.type & ":" & rootObjectProperty

Dim objSpec As New ObjectSpec

objSpec.obj = rootObject

objSpec.skip = True

objSpec.selectSet = New SelectionSpec()

propFilterSpec.propSet = SearchObject

propFilterSpec.objectSet = New ObjectSpec()

Return VIM_SERVICE.RetrieveProperties(SERVICE_CONTENT.propertyCollector, New PropertyFilterSpec() )

End Function

The problem is: If I retrieve the childEntities of a Folder, the folder itself is also being retrieved, which causes my app to infinitely loop. If i delete the GetInventory recursion the output is like this:

Datacenter:

Is this intended? Did i make a mistake? What is the best way to get an inventory list, like the VI Client?

Thanks in advance

Tags (3)
0 Kudos
1 Reply
storm27
Enthusiast
Enthusiast

Hi,

You can refer to the sample SimpleClient shipped with vSphere SDK package. The sample displays the complete inventory view of ESX or vCenter to which you are connecting.

Hope this helps you!

Thanks.

Angela