How to Restrict Clustered Hyper-V VMs to Specific Cluster Nodes – Part 1

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

  1. Open Failover Cluster Manager.
  2. On the left pane, expand “Service and applications”.
  3. Still on the left pane, highlight the VM to modify.
  4. In the center pane, right-click on the virtual machine resource object and click “Properties”.
  5. Switch to the “Advanced Policies” tab.
  6. Uncheck any hosts you do not wish the guest to be able to migrate to. Click OK.
Failover Cluster Manager R2 Advanced Policies Step 1

Failover Cluster Manager R2 Advanced Policies Step 1

Failover Cluster Manager R2 Advanced Policies Step 2

Failover Cluster Manager R2 Advanced Policies Step 1

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

  1. Open Failover Cluster Manager.
  2. In the left pane, highlight “Roles”.
  3. In the center pane, highlight the virtual machine you want to modify.
  4. At the very bottom of the center pane, switch the tab from “Summary” to “Resources”.
  5. In the lower center pane, either double-click the virtual machine or right-click on it and choose “Properties”.
  6. Switch to the “Advanced Policies” tab.
  7. Uncheck any hosts you do not wish the guest to be able to migrate to. Click OK.
Failover Cluster Manager 2012 Advanced Policies

Failover Cluster Manager 2012 Advanced Policies

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.

 

Altaro Hyper-V Backup
Share this post

Not a DOJO Member yet?

Join thousands of other IT pros and receive a weekly roundup email with the latest content & updates!

5 thoughts on "How to Restrict Clustered Hyper-V VMs to Specific Cluster Nodes – Part 1"

Leave a comment or ask a question

Your email address will not be published. Required fields are marked *

Your email address will not be published. Required fields are marked *

Notify me of follow-up replies via email

Yes, I would like to receive new blog posts by email

What is the color of grass?

Please note: If you’re not already a member on the Dojo Forums you will create a new account and receive an activation email.