Home > vSphere API > How to Differentiate Folders in vSphere

How to Differentiate Folders in vSphere

January 28th, 2011 Leave a comment Go to comments

As we know Folder is a container object in vSphere. It’s used to hold other managed objects in a similar way as directory holding files in an OS. There is an interesting question asking in VI Java API forum on how to tell whether a folder is vmFolder or hostFolder. BTW, you don’t see these two folders displayed in vSphere Client.

The questioner guessed correctly that you can find out by a folder’s childType property. Here is the documentation in API reference on the possible values of the childType property:

Lost VMs or Containers? Too Many Consoles? Too Slow GUI? Time to learn how to "Google" and manage your VMware and clouds in a fast and secure HTML5 App.

  • { “vim.Folder”, “vim.Datacenter” } – Identifies the root folder and its descendant folders. Data center folders can contain child data center folders and Datacenter managed objects. Datacenter objects contain virtual machine, compute resource, network entity, and datastore folders.
  • { “vim.Folder”, “vim.Virtualmachine”, “vim.VirtualApp” } – Identifies a virtual machine folder. A virtual machine folder may contain child virtual machine folders. It also can contain VirtualMachine managed objects, templates, and VirtualApp managed objects.
  • { “vim.Folder”, “vim.ComputeResource” } – Identifies a compute resource folder, which contains child compute resource folders and ComputeResource hierarchies.
  • { “vim.Folder”, “vim.Network” } – Identifies a network entity folder. Network entity folders can contain Network, DistributedVirtualSwitch, and DistributedVirtualPort managed objects.
  • { “vim.Folder”, “vim.Datastore” } – Identifies a datastore folder. Datastore folders can contain child datastore folders and Datastore managed objects.

Note that the values in the childType have vim. prefix, which stands for virtual infrastructure management. That is what the convention is.

This may seemingly solve the problem. But the Folder object can be recursive meaning a Folder can contain another folder. For example, a virtual machine folder can contain another virtual machine which has the same childType property. In that case, you have to check its parent. For that, you will find my post on inventory hierarchy very helpful.

The hostFolder is a little tricky because it does not contain HostSystem but ComputeResource instead. Only from the ComputerResource or its subtype ClusterComputerResource can you find HostSystem array. Unlike the virtual machine folder, it’s not recursive. Thanks to Ben North for pointing this out and helping the community on many questions!

  1. Ben
    January 28th, 2011 at 09:28 | #1

    I assume the “it” in the penultimate sentence refers to the HostSystem array, not the host Folder.
    Host folders (which as you point out are actually
    used for ComputeResources) can be recursive, it’s
    just that not many people use this feature of
    vCenter.

    Ditto for datacenter Folders: I’ve never seen
    anyone use anything but the single root.

  2. January 28th, 2011 at 10:42 | #2

    Thanks Ben, you are right – according to the childType, the ComputeResource folder can be recursive.
    Steve

  3. jack
    March 11th, 2014 at 10:57 | #3

    Is there a community or forum however small using the pyVmomi ?

    Jack

  4. Janardan
    July 21st, 2014 at 08:54 | #4

    while creating host , folder, datacenter etc facing [NotSupportedFault: null] The Operation is not supported on this object exception.
    can anyone help me?
    giving parent folder as “ha-folder-root”
    Thanks

  1. No trackbacks yet.