VMware Cloud Community
Aramaki
Contributor
Contributor
Jump to solution

How to create a VM on a standalone host?

Hello,

as you know from my other threads, i have created a workflow to create multiple identical VMs on a cluster.

Since we do not only have clustered hosts, but also some standalone machines, i need to modify the workflow to be able to create the VMs on those hosts.

The main step of the workflow is obviously the one that actually creates the VMs.

It is derived from one of the workflows provided within the library of orchestrator, but in the end there is no big difference.

The original Workflow is using this method to create a VM:

task = vmFolder.createVM_Task( configSpec, vmResourcePool, vmHost );

I omitted vmHost in my workflow, because i didn't want the user to select the host of the Cluster.

So my method execution looks like this:

task = vmFolder.createVM_Task( configSpec, vmCluster.resourcePool);

Now i tried to get this method to create a VM on a standalone host, but whatever i tried, it failed.

Does anyone have a solution or a hint, what i could try to get this to work?

Thanks a lot

Andreas

Reply
0 Kudos
1 Solution

Accepted Solutions
cdecanini_
VMware Employee
VMware Employee
Jump to solution

For the root folder try this:

var parent = vmHost.parent;
while(!(parent instanceof VcDatacenter)){
        parent = parent.parent;
}
var vmFolder = parent.vmFolder;

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter

View solution in original post

Reply
0 Kudos
15 Replies
admin
Immortal
Immortal
Jump to solution

Hi Andreas,

i had a similar question these days. In my opinion there is no direct way. I tried is as vCenter connection (because of the SDK path) as you can see in the screenshot (192.168.220.10). The only workaround is to add the ESXi host to a "transfer" cluster with no hosts, establish the VM and disconnect the host from the vCenter.

hope this helps, best regards

Christian

Bildschirmfoto 2011-03-16 um 13.27.19.png

Reply
0 Kudos
mmarinov
VMware Employee
VMware Employee
Jump to solution

Hi Andreas,

Could you provide what is the failure reason?

Keep in mind that the createVM_Task will perform execution on the vmFolder object. Thus the folder you are invoking this method should be VcFolder. See for reference the docmentation:

https://www.vmware.com/support/orchestrator/doc/vco_vsphere41_api/html/VcFolder.html#createVM_Task

Regards,

--Martin

Martin Marinov VMware Software Engineer If you found this or any other answer useful please consider the use of the Helpful or correct buttons to award points
Reply
0 Kudos
Aramaki
Contributor
Contributor
Jump to solution

Hi Christian and Martin,

@Christian:

The host is within a vCenter and i can connect to it.

I just can't create VMs on this host, because the createVM_task method needs a resourcepool and a host has no such attribute.

@Martin:

This is the error i get, when i just provide a vcHost instead of a resourcepool:

Cannot convert ComputeResource<domain-s8>'si0vmh24.de.bosch.com' to com.vmware.vmo.plugin.vi4.model.VimResourcePool (Workflow:Create VM / add VM (item2)#71)

The vcFolder is the same on all our hosts, so i've set it as a constant for the whole workflow.

The resourcepools also are the same everywhere, because we don't use this feature (all the VMs go into the default pool...i think its name is "Resources").

As i said: This does work with clusters, but i can't get it to work with a unclustered host.

Reply
0 Kudos
cdecanini_
VMware Employee
VMware Employee
Jump to solution

It needs a host OR a resource pool.

Try to set the resource pool to null and set the host and other parameters.

The library workflow should work without any changes.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
Reply
0 Kudos
tschoergez
Leadership
Leadership
Jump to solution

Hi!

I haven't read the complete thread (yet 🙂 ), but maybe this helps:

INPUT:(VC:HostSystem) targetHost; (Vc:ResourcePool) pool

OUTPUT: (VC:ResourcPool) poperPool

System.debug("calculating proper pool for cloning");

if (pool == null ) {
    //get hosts parent to see if its a stand alone or a in-cluster-host
    if (targetHost == null) throw "Either host or pool has to be specified for cloning..." ;
    var parent = targetHost.parent;
    System.debug("TargetHosts.parent: " + parent);
    if (parent instanceof VcClusterComputeResource) {
        System.debug("host is part of cluster, taking clusters root-pool");
        properPool = parent.resourcePool;
    }
    if (parent instanceof VcComputeResource) {
        System.debug("host is real standalone host, taking its own root-pool");
        //same line, because vcenter data model is comparable
        properPool = parent.resourcePool;
    }
} else {
    System.debug("Resource pool specfied, so taking this.");
    properPool = pool;
    }

System.debug("proper Pool for cloning: " + properPool);
  

Regards,

Joerg

Reply
0 Kudos
Aramaki
Contributor
Contributor
Jump to solution

@cdecanini_:

This works:

task = vmFolder.createVM_Task( configSpec, vmCluster.resourcePool);

This does not:

task = vmFolder.createVM_Task( configSpec, vmHost);

@Joerg: Hm, looks nice. I'll try this one.

Reply
0 Kudos
cdecanini_
VMware Employee
VMware Employee
Jump to solution

Forgot what I wrote. Host can be set to null if a resource pool is provided, not the other way around.

Even if this is not a host part of a cluster you can provide a resource pool:

Screen shot 2011-03-16 at 2.09.21 PM.png

This works here.

Screen shot 2011-03-16 at 2.12.23 PM.png

Does "Create a simple virtual machine" workflow works for you on your stand alone host ?

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
mmarinov
VMware Employee
VMware Employee
Jump to solution

The second doesn't work because you provide the host as a resource pool. That is why you receive this cast exception.

Based on the VC plugin documentation:

The target host on which the virtual machine will run. This must specify a host that is a member of the ComputeResource indirectly specified by the pool. For a stand-alone host or a cluster with DRS, host can be omitted, and the system selects a default.

So in order to perform a creation of the VM for the standalone host you need to provide the correct resource pool. You can try to pass the host's resource pool vcHost.resourcePool. Or even further you can go to the vcHostResourcePool.resourcePool array.

Hope this help.

--Martin

Martin Marinov VMware Software Engineer If you found this or any other answer useful please consider the use of the Helpful or correct buttons to award points
Reply
0 Kudos
Aramaki
Contributor
Contributor
Jump to solution

@cdecanini_:

Yes the "create a simple VM" does work with a standalon host, but i have to provide all the information by myself. Especially the resourcepool.

But since all our hosts/clusters only use the default resourcepool called "Resources" there is no point of letting the user select it.

@Martin:

i tried using this:

task = vmFolder.createVM_Task( configSpec, vmHost.parent.resourcePool);

since a vcHost has no attribute called "resourcePool", but the parent obviously does/should (see screenshot provided by cdecanini_).

But the problem is, the vcHost.parent attribute contains an object of VcManagedEntity and i can't find this class within the orchestrator API (that small "SearchAPI" button in orchestrators "scripting" view).

I tried to put the output of vmHost.parent into a string, since orchestrator simply converts everything, but the string stays empty.

To me this looks like some feature which is still "work in progress".

I also noticed, that i probably can't pre-set the vmFolder in a constant, but need to set it via code, because the vmFolder is being linked as part of a specific datacenter. This means: different datacenter = different vmFolder, although it has the same name everywhere.

So right now my question is: How can i select all the information (vmFolder and ResourcePool) based on a cluster/host?

Thanks a lot for your help and

regards

Andreas

Reply
0 Kudos
mmarinov
VMware Employee
VMware Employee
Jump to solution

HI Andreas,

In order to get all resource pools you can do it via VcPlugin.getAllResourcePools. This returns you an array of resource pools: https://www.vmware.com/support/orchestrator/doc/vco_vsphere41_api/html/_VcPlugin.html#getAllResource...

In order to get all hosts you can do it via VcPlugin.getAllHostSystems. This returns you an array of VcHostSystem:

https://www.vmware.com/support/orchestrator/doc/vco_vsphere41_api/html/_VcPlugin.html#getAllHostSyst...

On other hand, sorry if this was already discussed but I could missed it - what is the type of vmHost?

Because using the public documentation the VcHostSystem has resourcePool_ResourcePool property:

https://www.vmware.com/support/orchestrator/doc/vco_vsphere41_api/html/VcHostSystem.html

But I might miss something.

Regards,

--Martin

Martin Marinov VMware Software Engineer If you found this or any other answer useful please consider the use of the Helpful or correct buttons to award points
Reply
0 Kudos
cdecanini_
VMware Employee
VMware Employee
Jump to solution

I have tried this: it returns the resource pool:

System.log(vmHost.parent.resourcePool);

[removed confusing code]

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
cdecanini_
VMware Employee
VMware Employee
Jump to solution

@Martin

vmHost is of type VC:HostSystem

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
Reply
0 Kudos
cdecanini_
VMware Employee
VMware Employee
Jump to solution

For the root folder try this:

var parent = vmHost.parent;
while(!(parent instanceof VcDatacenter)){
        parent = parent.parent;
}
var vmFolder = parent.vmFolder;

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
Reply
0 Kudos
tschoergez
Leadership
Leadership
Jump to solution

Hi Andreas,

if nothing helps: Can you export your workflows and actions and post it here that we can try to reproduce everything in the same context?

Regards,

Joerg

Reply
0 Kudos
Aramaki
Contributor
Contributor
Jump to solution

Hi,

i just tried the code of cdecanini_ and it successfully selects the correct vmFolder.

Now the workflow is working like a charm, no matter which host or cluster i select.

Except for that problem with the mailing function, but i think i can figure this one out myself.

A great thank you to all of you.

Regards Andreas

Reply
0 Kudos