10.7. Assigning VMs to Hosts
At any point in time, each virtual machine instance is running on a single host. How does CloudStack determine which host to place a VM on? There are several ways:
By defining affinity groups and assigning VMs to them, the user or administrator can influence (but not dictate) which VMs should run on separate hosts. This feature is to let users specify that VMs with the same “host anti-affinity” type won’t be on the same host. This serves to increase fault tolerance. If a host fails, another VM offering the same service (for example, hosting the user's website) is still up and running on another host.
The scope of an affinity group is per user account.
To add an affinity group:
Log in to the CloudStack UI as an administrator or user.
In the left navigation bar, click Affinity Groups.
Click Add affinity group. In the dialog box, fill in the following fields:
Name. Give the group a name.
Description. Any desired text to tell more about the purpose of the group.
Type. The only supported type shipped with CloudStack is Host Anti-Affinity. This indicates that the VMs in this group should avoid being placed on the same VM with each other. If you see other types in this list, it means that your installation of CloudStack has been extended with customized affinity group plugins.
To assign a new VM to an affinity group:
Create the VM as usual, as described in
Section 10.4, “Creating VMs”. In the Add Instance wizard, there is a new Affinity tab where you can select the affinity group.
To assign an existing VM to an affinity group:
Log in to the CloudStack UI as an administrator or user.
In the left navigation bar, click Instances.
Click the name of the VM you want to work with.
Stop the VM by clicking the Stop button.
Click the Change Affinity button.
To see which VMs are currently assigned to a particular affinity group:
In the left navigation bar, click Affinity Groups.
Click the name of the group you are interested in.
Click View Instances. The members of the group are listed.
From here, you can click the name of any VM in the list to access all its details and controls.
To delete an affinity group:
In the left navigation bar, click Affinity Groups.
Click the name of the group you are interested in.
Click Delete.
Any VM that is a member of the affinity group will be disassociated from the group. The former group members will continue to run normally on the current hosts, but if the VM is restarted, it will no longer follow the host allocation rules from its former affinity group.