I am trying to setup an automation script to read from a file and create
10-20 VMs at a time. I am not haveing issue getting the information
for the script, or the syntax, but I am curious how you create a VM in a
specific Cluster within a Datacaenter. I have multiple datacenters and
clusters, and I need to create the vms in the correct location. With
the new-vm command, it does not give you an option to specify a cluster,
it is looking for a specific host.
I am sorry if this has been asked beofre, but I did search around the
forums and web and could not find the answer to a specific cluster
installation.
Thanks,
You can create the new guest in cluster in several ways.
1) You can use the -ResourcePool parameter and pick a resource pool that belongs to a cluster
2) You can use the -VMHost parameter and specify one the hosts in the cluster.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I don't have resource pools, and I was hoping to avoid having to select a specific host. So I guess the best thing for me to do is parse through my hosts within a cluster and have it auto select based on resources and number of VMs per host and let DRS sort it out later?
How does vCenter handle this when you select a cluster to create a new vm in? It doesn't ask for a specific host.
Thanks for the reposnse.
There is always a hidden resource pool for each cluster.
It's called 'Resources'.
So you can do
New-VM -ResourcePool (Get-Cluster -Name <clustername> | Get-ResourcePool -Name "Resources") ....
The new guest will appear at the root of the cluster.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You could do something like this:
New-VM -VMHost (Get-Cluster <CLUSTER NAME> | Get-VMHost | Select-Object -First 1) -Name <VM NAME>
Of course you'd want to add other pertinent info like datastore, guest OS, template to deploy from, etc.
The -VMHost parameter is required, so if you wanted to pick a specific resource pool you'd still have to specify a host, right?
You are correct, I was extrapolating what is possible with the CreateVM_Task method. There you can just specify a resourcepool and "For a stand-alone host or a cluster with DRS, host can be omitted, and the system selects a default. ".
That's a feature that should be made available in my opinion.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
How does vCenter select the host when deploying from a template? Does it just find the best suited host based on resources? This is if you select a Cluster to deploy to.
I have not got a chance to get back to my code, but I will try to come up with something that evaluates resources to select a host and post what I come up with.
No, Alan's remark is correct.
The New-VM cmdlet makes the -VMHost parameter required. This is not always required as can be seen in the CreateVM_Task method.
When you use the SDK method and only specify a resourcepool from a cluster, it's DRS that will decide on which host in the cluster the new guest will be created. And DRS uses its own algorithm, based on available resources and the spread of the load, to decide which host it is.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
With the method I mentioned, it does indeed force the VM to a particular host in the selected cluster, but as long as you are using DRS, that won't matter much since DRS will move the VM at power-on to the best host. The advantage of my method (as opposed to actually picking a specific host and no cluster or resource pool at all) is that you aren't hard-coding anything to a specific host--so if the hosts (or their names) in your cluster change, it'll still work as it just picks the first one (as determined by Get-Cluster | Get-VMHost).
This is how I choose the best host to put my vm on.
$BestHost = get-vmhost | Sort-Object 'MemoryUsageMB' | Select-Object -first 1
You could make it smarter and measure CPU usage also, but this works well for me.