<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>10.7. Assigning VMs to Hosts</title><link rel="stylesheet" type="text/css" href="Common_Content/css/default.css" /><link rel="stylesheet" media="print" href="Common_Content/css/print.css" type="text/css" /><meta name="generator" content="publican 2.8" /><meta name="package" content="Apache_CloudStack-Admin_Guide-4.2.0-en-US-1-" /><script type="text/javascript" src="../../../../../toc.js"></script><script type="text/javascript">
              addID('Apache_CloudStack');
              
	      addID('Apache_CloudStack.4.2.0');
              
              addID('Apache_CloudStack.4.2.0.books');
	      addID('Apache_CloudStack.4.2.0.Admin_Guide');
              </script><link rel="home" href="index.html" title="CloudStack Administrator's Guide" /><link rel="up" href="virtual-machines.html" title="Chapter 10. Working With Virtual Machines" /><link rel="prev" href="stopping-and-starting-vms.html" title="10.6. Stopping and Starting VMs" /><link rel="next" href="vm-snapshots.html" title="10.8. Virtual Machine Snapshots for VMware" /></head><body class="toc_embeded "><div id="tocdiv" class="toc"><iframe id="tocframe" class="toc" src="../../../../toc.html">This is an iframe, to view it upgrade your browser or enable iframe display.</iframe></div><p id="title"><a class="left" href="http://cloudstack.apache.org"><img src="Common_Content/images/image_left.png" alt="Product Site" /></a><a class="right" href="http://cloudstack.apache.org/docs"><img src="Common_Content/images/image_right.png" alt="Documentation Site" /></a></p><ul class="docnav"><li class="previous"><a accesskey="p" href="stopping-and-starting-vms.html"><strong>Prev</strong></a></li><li class="next"><a accesskey="n" href="vm-snapshots.html"><strong>Next</strong></a></li></ul><div xml:lang="en-US" class="section" id="host-allocation" lang="en-US"><div class="titlepage"><div><div><h2 class="title">10.7. Assigning VMs to Hosts</h2></div></div></div><div class="para">
		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:
	</div><div class="itemizedlist"><ul><li class="listitem"><div class="para">
				Automatic default host allocation. CloudStack can automatically pick the most appropriate host to run each virtual machine.
			</div></li><li class="listitem"><div class="para">
				Instance type preferences. CloudStack administrators can specify that certain hosts should have a preference for particular types of guest instances. For example, an administrator could state that a host should have a preference to run Windows guests. The default host allocator will attempt to place guests of that OS type on such hosts first. If no such host is available, the allocator will place the instance wherever there is sufficient physical capacity.
			</div></li><li class="listitem"><div class="para">
				Vertical and horizontal allocation. Vertical allocation consumes all the resources of a given host before allocating any guests on a second host. This reduces power consumption in the cloud. Horizontal allocation places a guest on each host in a round-robin fashion. This may yield better performance to the guests in some cases.
			</div></li><li class="listitem"><div class="para">
				End user preferences. Users can not control exactly which host will run a given VM instance, but they can specify a zone for the VM. CloudStack is then restricted to allocating the VM only to one of the hosts in that zone.
			</div></li><li class="listitem"><div class="para">
				Host tags. The administrator can assign tags to hosts. These tags can be used to specify which host a VM should use. The CloudStack administrator decides whether to define host tags, then create a service offering using those tags and offer it to the user.
			</div></li><li class="listitem"><div class="para">
				Affinity groups. 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 certain VMs won't be on the same host.
			</div></li><li class="listitem"><div class="para">
				CloudStack also provides a pluggable interface for adding new allocators. These custom allocators can provide any policy the administrator desires.
			</div></li></ul></div><div class="section" id="affinity-groups"><div class="titlepage"><div><div><h3 class="title">10.7.1. Affinity Groups</h3></div></div></div><div class="para">
			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.
		</div><div class="para">
			The scope of an affinity group is per user account.
		</div><div class="formalpara"><h5 class="formalpara" id="idp46176496">Creating a New Affinity Group</h5>
				To add an affinity group:
			</div><div class="orderedlist"><ol><li class="listitem"><div class="para">
					Log in to the CloudStack UI as an administrator or user.
				</div></li><li class="listitem"><div class="para">
					In the left navigation bar, click Affinity Groups.
				</div></li><li class="listitem"><div class="para">
					Click Add affinity group. In the dialog box, fill in the following fields:
				</div><div class="itemizedlist"><ul><li class="listitem"><div class="para">
							Name. Give the group a name.
						</div></li><li class="listitem"><div class="para">
							Description. Any desired text to tell more about the purpose of the group.
						</div></li><li class="listitem"><div class="para">
							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.
						</div></li></ul></div></li></ol></div><div class="formalpara"><h5 class="formalpara" id="idp44175584">Assign a New VM to an Affinity Group</h5>
				To assign a new VM to an affinity group:
			</div><div class="itemizedlist"><ul><li class="listitem"><div class="para">
					Create the VM as usual, as described in <a class="xref" href="creating-vms.html">Section 10.4, “Creating VMs”</a>. In the Add Instance wizard, there is a new Affinity tab where you can select the affinity group.
				</div></li></ul></div><div class="formalpara"><h5 class="formalpara" id="idp58556080">Change Affinity Group for an Existing VM</h5>
				To assign an existing VM to an affinity group:
			</div><div class="orderedlist"><ol><li class="listitem"><div class="para">
					Log in to the CloudStack UI as an administrator or user.
				</div></li><li class="listitem"><div class="para">
					In the left navigation bar, click Instances.
				</div></li><li class="listitem"><div class="para">
					Click the name of the VM you want to work with.
				</div></li><li class="listitem"><div class="para">
					Stop the VM by clicking the Stop button.
				</div></li><li class="listitem"><div class="para">
					Click the Change Affinity button. 
					<span class="inlinemediaobject"><img src="./images/change-affinity-button.png" alt="change-affinity-button.png: button to assign an affinity group to a virtual machine" /></span>

				</div></li></ol></div><div class="formalpara"><h5 class="formalpara" id="idp55882976">View Members of an Affinity Group</h5>
				To see which VMs are currently assigned to a particular affinity group:
			</div><div class="orderedlist"><ol><li class="listitem"><div class="para">
					In the left navigation bar, click Affinity Groups.
				</div></li><li class="listitem"><div class="para">
					Click the name of the group you are interested in.
				</div></li><li class="listitem"><div class="para">
					Click View Instances. The members of the group are listed.
				</div><div class="para">
					From here, you can click the name of any VM in the list to access all its details and controls.
				</div></li></ol></div><div class="formalpara"><h5 class="formalpara" id="idp66953120">Delete an Affinity Group</h5>
				To delete an affinity group:
			</div><div class="orderedlist"><ol><li class="listitem"><div class="para">
					In the left navigation bar, click Affinity Groups.
				</div></li><li class="listitem"><div class="para">
					Click the name of the group you are interested in.
				</div></li><li class="listitem"><div class="para">
					Click Delete.
				</div><div class="para">
					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.
				</div></li></ol></div></div></div><ul class="docnav"><li class="previous"><a accesskey="p" href="stopping-and-starting-vms.html"><strong>Prev</strong>10.6. Stopping and Starting VMs</a></li><li class="up"><a accesskey="u" href="#"><strong>Up</strong></a></li><li class="home"><a accesskey="h" href="index.html"><strong>Home</strong></a></li><li class="next"><a accesskey="n" href="vm-snapshots.html"><strong>Next</strong>10.8. Virtual Machine Snapshots for VMware</a></li></ul></body></html>
