Save to My DOJO
There are times when you need to keep certain virtual machines from being moved to particular nodes in your Hyper-V VM cluster. In my case, I’m architecting a six-node cluster that will have its nodes split evenly across two sites connected with high speed fibre.
We want the virtual machines for each site to stay within their sites even if a cluster failover event occurs. We want to have the option to quickly LiveMigrate them from site to site if we have reason to. This is just one of any number of scenarios in which you might want to have control over how your guests can be isolated. We’ll look at a couple of ways to make that happen.
Method 1: Hard Restriction Using the GUI
Using this method, it will not be possible to move a virtual machine to an excluded node by any method without first removing the restriction. I read a complaint in another forum that System Center Virtual Machine Manager’s automated Live Migration routines may attempt to move a guest to a node it has been restricted from using. That migration will fail, but as long as it isn’t because of the original host being offline, the guest should continue running. I currently have no method of testing this behavior myself, so be advised of the possibility. If you are not using SCVMM with automated Intelligent Placement, this is probably not likely to happen to you anyway.
To use the GUI to restrict which hosts a virtual machine can run on:
Hyper-V 2008 R2
- Open Failover Cluster Manager.
- On the left pane, expand “Service and applications”.
- Still on the left pane, highlight the VM to modify.
- In the center pane, right-click on the virtual machine resource object and click “Properties”.
- Switch to the “Advanced Policies” tab.
- Uncheck any hosts you do not wish the guest to be able to migrate to. Click OK.
If the “Advanced Policies” tab is missing, then start over at step 3. If you highlight the “Services and applications” node and then right-click on the virtual machine in the list that is presented in the center pane and bring up its properties there, you get an entirely different dialog box. However, if you double-click on the virtual machine in the center pane’s list, you are taken to the screen that you wanted to be on initially.
Hyper-V 2012
- Open Failover Cluster Manager.
- In the left pane, highlight “Roles”.
- In the center pane, highlight the virtual machine you want to modify.
- At the very bottom of the center pane, switch the tab from “Summary” to “Resources”.
- In the lower center pane, either double-click the virtual machine or right-click on it and choose “Properties”.
- Switch to the “Advanced Policies” tab.
- Uncheck any hosts you do not wish the guest to be able to migrate to. Click OK.
Method 2: Hard Restriction Using PowerShell
If you have several virtual machines to modify, this might suit your solution better. I’ll show you the command, and you can use it to work up a script that sets your virtual machines in a way that suits your needs.
First, on 2008 R2, you have to import the module:
Import-Module FailoverClusters
For 2012, you just have to run the command on a system that has the Failover Clusters PowerShell module already installed. If you haven’t, run this:
DISM /ONLINE /ENABLE-FEATURE /FEATURENAME:FailoverCluster-PowerShell
After that, both versions are the same. You’ll need the name of the virtual machine to modify. To list all of them:
Get-ClusterResource
On 2012, the command accepts wildcards. So, if your virtual machine is named “svtest”, then you can run the following:
Get-ClusterResource -Name "*svtest*"
Notice that each item has two entries: one is the virtual machine and the other is its configuration resource. The one that you really want to set is the virtual machine. You generally do not want to restrict configuration ownership.
Get-ClusterResource -Name "Virtual Machine svtest1" | Set-ClusterOwnerNode -Owners svhyperv1,svhyperv3
The above command will restrict the virtual machine named “svtest1” so that it only runs on nodes svhyperv1 and svhyperv3. If you try to exclude the virtual machine it is currently running on, the command will fail.
Remember what I said earlier about scripting potential? You can send in more than one virtual machine at a time:
Get-ClusterResource -Name "Virtual Machine svtest1", "Virtual Machine svtest2" | Set-ClusterOwnerNode -Owners svhyperv1,svhyperv3
With 2012, you can use wildcards. I’d advise caution with that method, however, because you’re likely to restrict ownership of the configuration file as well and that has the potential to cause problems. Consider this an open challenge: first, if anyone can demonstrate a method to trap for a “ResourceType” of “Virtual Machine” on the Get-ClusterResource command prior to sending it through the Set-ClusterOwnerNode command, please leave us a comment.
What’s Coming
Stay tuned and I’ll show you how to loosen these restrictions so that virtual machines prefer certain nodes but aren’t completely prevented from being migrated to others. I’ll also show you how to set it so that certain virtual machines will try not to be on the same host as other guests that you specify.
Not a DOJO Member yet?
Join thousands of other IT pros and receive a weekly roundup email with the latest content & updates!
6 thoughts on "How to Restrict Clustered Hyper-V VMs to Specific Cluster Nodes – Part 1"
[…] the previous part of this series, I showed you how to prevent virtual machines from being migrated to specific hosts. In part 2, […]
[…] exact steps to get this message are in on this blog post on the 2012 section of Method 1, but on Windows 8 with Remote Server Administration Tools installed […]
Thank you,helped me a lot
Why is there not a policy for this, like in VMware? This is crazy… SO many simple things in vSphere that I can’t do in Hyper-V. Very frustrating.
Hyper-V is a component. vSphere is a component stack plus management environment. I acknowledge your frustrations, but your comparison is unfair. How would you do these sorts of things in an ESXi-only environment without vSphere?