XenServer – Map all VMs disks to Storage Repositories
Below I will supply a small shell script to run on a XenServer node which will create a file /tmp/storage_map.csv you can import into Excel or LibreOffice without problems. The delimiter is comma (,).
#!/bin/bash echo "VM Name,VM UUID,VM Power Status,Disk Name,Disk UUID,Disk size in GB,SR Name" > /tmp/storage_map.csv for i in `xe vm-list --minimal is-control-domain=false | tr , ' '` do VM_UUID=$i VM_NAME="`xe vm-param-get uuid=$VM_UUID param-name=name-label`" POWER_STATE=`xe vm-param-get uuid=$VM_UUID param-name=power-state` for j in `xe vbd-list vm-uuid=$VM_UUID type=Disk --minimal | tr , ' '` do VDI_UUID=`xe vbd-param-get param-name=vdi-uuid uuid=$j` VDI_NAME="`xe vdi-param-get uuid=$VDI_UUID param-name=name-label`" VDI_SR_NAME="`xe vdi-param-get uuid=$VDI_UUID param-name=sr-name-label`" VDI_SR=`xe vdi-param-get uuid=$VDI_UUID param-name=sr-uuid` VDI_SIZE=`xe vdi-param-get uuid=$VDI_UUID param-name=virtual-size` let SIZE=$VDI_SIZE/1024/1024/1024 # Now we write it nicely echo "$VM_NAME,$VM_UUID,$POWER_STATE,$VDI_NAME,$VDI_UUID,$SIZE,$VDI_SR_NAME" >> /tmp/storage_map.csv done done