Deployment planning and resource allocation is one of the important features of CloudStack. This document highlights various planning heuristics applied by CloudStack while placing a VM.
Planning and allocation in CloudStack is handled by DeploymentPlanner modules and Host/StoragePooAllocators. These implementations decide the order in which resource(pods,clusters,hosts,storage pools) will be considered for a VM deployment/migration.
Following are the existing flavors of these modules:
Random: This just shuffles the list of clusters/hosts/pools that is returned by the DB lookup. Random does not mean round-robin - So if you are looking for a new host being picked up on every deployment - that may not happen.
FirstFit: This makes sure that clusters are ordered by available capacity and first hosts/pools having enough capacity is chosen within a cluster.
UserDispersing: For a given account, this makes sure that VM's are dispersed - so clusters/hosts with minimum number of running VM's for that account are chosen first. Storage Pool with minimum number of Ready storage pools for the account is chosen first.
Userconcentratedpod: Always choose the pod/cluster with max. number of VMs for the account - concentrating VM's at one pod.
You can find the source code related to above under: server/src/com/cloud/deploy, plugins/deployment-planners, plugins/host-allocators, plugins/storage-allocators