vmware / vmware/pyvmomi

Inventory Traversal not traversing

Open
#332 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Python
Stars
2.3k
Forks
763
PR merge metrics
No merged PRs in 30d

Description

This is a question about Inventory Traversal. The code below returns values for vim.VirtualMachine and vim.Network. But they are each an individual vmodl.query.PropertyCollector.ObjectContent

I would have thought that the vim.Network values would have been a subset of each vim.VirtualMachine.

Does anyone know how to do write this so that the properties of the vim.Network are listed as properties of each vim.VirtualMachine that they belong to?

    objView = content.viewManager.CreateContainerView(content.rootFolder,
                                                      [vim.VirtualMachine],
                                                      True)

    collector = content.propertyCollector

    obj_spec = vmodl.query.PropertyCollector.ObjectSpec()
    obj_spec.obj = objView
    obj_spec.skip = True

    traversal_spec = vmodl.query.PropertyCollector.TraversalSpec()
    traversal_spec.name = 'traverseEntities'
    traversal_spec.path = 'view'
    traversal_spec.skip = False
    traversal_spec.type = vim.ContainerView
    obj_spec.selectSet.append(traversal_spec)

    traversal_spec_nw = vmodl.query.PropertyCollector.TraversalSpec()
    traversal_spec_nw.type = vim.VirtualMachine
    traversal_spec_nw.path = 'network'
    traversal_spec_nw.skip = False

    traversal_spec.selectSet.append(traversal_spec_nw)

    property_spec = vmodl.query.PropertyCollector.PropertySpec()
    property_spec.type = vim.VirtualMachine
    property_spec.pathSet.extend(['name', 'guest.hostName'])

    property_spec_nw = vmodl.query.PropertyCollector.PropertySpec()
    property_spec_nw.type = vim.Network
    property_spec_nw.pathSet.append('summary.accessible')

    filter_spec = vmodl.query.PropertyCollector.FilterSpec()
    filter_spec.objectSet.append(obj_spec)
    filter_spec.propSet.append(property_spec)
    filter_spec.propSet.append(property_spec_nw)

    props = collector.RetrieveContents([filter_spec])
    pprint.pprint(props)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the PropertyCollector ObjectSpec, TraversalSpec, and PropertySpec entry points shown in the issue, then inspect how RetrieveContents handles objects reached through multiple traversal paths. Verify the resulting ObjectContent structure and determine what behavior would associate network properties with each virtual machine; document the confirmed limitation or required change.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.