qc4vmware
Virtuoso
Virtuoso

Can't create a vm with VC:HostFolder.createVM_Task()

Jump to solution

When I try to create a vm using VC:HostFolder.createVM_Task() I get an error "The operation is not supported on the object".  I've only been successful when using VC:VmFolder.createVM_Task().  Can anyone confirm using the methods on the host folder of other folder types works from vRO?  All the canned examples also always use a VmFolder for the task creation.  I have a situation where VmFolders are not always specified so I'd like to simply deploy to the host.  I'd like to at least know this works for someone else out there before I spend too many more hours troubleshooting the issue.

Paul.

0 Kudos
1 Solution

Accepted Solutions
tschoergez
Leadership
Leadership

As Ilian mentioned, this is by design (not vRO, but vCenter). Every VM needs to be placed in a VmFolder (shown in the "VMs and Templates" view in vCenter).

If you don't have an explicit folder structure for the VM folders, you can pick the "root" one of a datacenter.

datacenter.vmFolder gives you that, it's always named "vm", and this one is not visible in the vSphere Client.

If you just have a HostSystem (or any other managed Entity btw.), use the com.vmware.library.vc.basic.getDataCenterForVimObject Action of the vCenter Library to the the datacenter its in.

Regards,

Joerg

View solution in original post

3 Replies
iiliev
VMware Employee
VMware Employee

Hi Paul,

Excerpt from Folder documentation at https://code.vmware.com/apis/358/vsphere#/doc/vim.Folder.html#createVm

This operation only works if the folder's childType includes VirtualMachine

Also, here is the documentation for the childType property that shows how to check if you can create a vm inside a given folder:

Specifies the object types a folder may contain. When you create a folder, it inherits its childType from the parent folder in which it is created. childType is an array of strings. Each array entry identifies a set of object types - Folder and one or more managed object types. The following list shows childType values for the different folders:

  • { "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 on a vCenter Server can contain Network, DistributedVirtualSwitch, and DistributedVirtualPortgroup managed objects. Network entity folders on an ESXi host can contain only Network objects.
  • { "vim.Folder", "vim.Datastore" } - Identifies a datastore folder. Datastore folders can contain child datastore folders and Datastore managed objects.
tschoergez
Leadership
Leadership

As Ilian mentioned, this is by design (not vRO, but vCenter). Every VM needs to be placed in a VmFolder (shown in the "VMs and Templates" view in vCenter).

If you don't have an explicit folder structure for the VM folders, you can pick the "root" one of a datacenter.

datacenter.vmFolder gives you that, it's always named "vm", and this one is not visible in the vSphere Client.

If you just have a HostSystem (or any other managed Entity btw.), use the com.vmware.library.vc.basic.getDataCenterForVimObject Action of the vCenter Library to the the datacenter its in.

Regards,

Joerg

View solution in original post

qc4vmware
Virtuoso
Virtuoso

Thanks!  That all makes sense and I'll traverse to the root folder to create the vm.  Why does this method exist then VC:HostFolder.createVM_Task() .  I would expect it to just select the root folder on its own maybe?  Or does this work if the host is not in a cluster?

0 Kudos