Xenserver script to assign vCPU and vGPU to VM’s

When working with HDX3D and HDX3DPRO you will probably need to more than 2 cpu’s on a XenDesktop VM and more than 4 cpu’s on a XenApp VM. To work around the license limit in windows (max 2 CPU’s on a desktop OS and max 4 CPU’s on a standard server license), you need to tell the hypervisor to present the CPU’s as cores instead of CPU’s. To do this in XenServer you need several commands:

  • xe vm-param-set platform:cores-per-socket=6 uuid=<VM-UUID>
  • xe vm-param-set VCPUs-max=6 uuid=<VM-UUID>
  • xe vm-param-set VCPUs-at-startup=6 uuid=<VM-UUID>

Doing this when you have many VM’s certainly requires automation. As far as I know the XenDesktop MCS does not allow you to specify this, I hope it will in the future. The same goes for assigning GPU to the VM’s.

So, I’ve made this xenserver script to do the task. Run once on the XenServer console for each XenServer pool master after all VM’s has been created.

In this case I’m assigning 6 CPU cores to each VM in the pool and assigning a Nvidia GPU to each VM in the pool.

This script assumes all VM’s in the pool needs to have the same config.

Before you run, determine the number of vcpu’s you want, and replace the number “6” in the script with the number you desire (marked yellow). You need to get the name of the GPU group that you want to assign to the VM’s, and replace it in the script (marked yellow). To do this run this command:

xe gpu-group-list

The script:

echo Fetching GPU ID
GPULIST=`xe gpu-group-list name-label="Group of nVidia Corporation GF106GL [Quadro 2000] GPUs" | grep "uuid ( RO) " | awk '{print $5}'`
echo Setting GPU and vCPUs on all VMs
VMLIST=`xe vm-list is-control-domain=false power-state=halted | grep "uuid ( RO) " | awk '{print $5}'`
for VM in $VMLIST
do
echo Setting cores-per-socket on $VM
xe vm-param-set platform:cores-per-socket=6 uuid=$VM
echo Setting VCPUs-max on $VM
xe vm-param-set VCPUs-max=6 uuid=$VM
echo Setting VCPUs-at-startup on $VM
xe vm-param-set VCPUs-at-startup=6 uuid=$VM
echo Assigning GPU to $VM
xe vgpu-create vm-uuid=$VM gpu-group-uuid=$GPULIST
done

DISCLAIMER! You may use this script for free, but it’s completely on your own risk, I provide no warranties for it. Always test in test environment first!

2 thoughts on “Xenserver script to assign vCPU and vGPU to VM’s

  1. Great Script. I wanted to target vm’s based on tags so i used the following in my variable:

    VMLIST=`xe vm-list is-control-domain=false power-state=halted tags=Civil | grep “uuid ( RO) ” | awk ‘{print $5}’`

Leave a Reply

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

*