Folder APIs
The Folder managed object is a container for storing and organizing inventory objects.
Folders can contain folders and other objects. The childType property identifies a folder's type and determines the types of folders and objects the folder can contain.
- A folder can contain a child folder of the same type as the parent folder.
- All Datacenter objects contain dedicated folders for:
- VirtualMachine, templates, and VirtualApp objects.
- ComputeResource hierarchies.
- Network, DistributedVirtualSwitch, and DistributedVirtualPortgroup objects.
- Datastore objects.
- A folder can contain child objects of type childType. Virtual machine and network entity folders can also contain additional object types.
- The root folder is a data center folder.
See ServiceInstance for a representation of the organization of the inventory.
The Folder managed object also acts as a factory object, meaning it creates new entities in a folder. The object provides methods to create child folders and objects, methods to add existing objects to folders, and methods to remove objects from folders and to delete folders.
Folder inherits the Destroy_Task method. Destroy_Task is a recursive operation that removes all child objects and folders. When you call Destroy_Task to destroy a folder, the system uses the specified folder as a root and traverses its descendant hierarchy, calling Destroy_Task on each object. Destroy_Task is a single operation that treats each recursive call as a single transaction, committing each call to remove an object individually. If Destroy_Task fails on an object, the method terminates at that point with an exception, leaving some or all of the objects still in the inventory.
Notes on the folder destroy method:
- Calling Destroy_Task on a virtual machine folder recursively calls Destroy_Task on all the child virtual machines and vApps, which are then removed from disk. Use UnregisterAndDestroy_Task to unregister virtual machines or vApps recursively without removing them from the disk.
- For virtual machine folders, the Destroy_Task method requires the VirtualMachine.Delete privilege on the folder as well as all virtual machines to be destroyed. It also requires the VirtualApp.Delete privilege on all VirtualApp objects to be destroyed.
- Destroying a host folder or datacenter folder unregisters all child hosts and virtual machines from vCenter. The hosts are simply removed from the inventory, along with their virtual machines. The virtual machines are not removed from disk nor are their runtime states changed.
- You can remove network and datastore folders only if they are empty.
- You cannot destroy, rename, or move the virtual machine, compute resource, network entity, and datastore child folders of a Datacenter.