Skip to content

Instantly share code, notes, and snippets.

@jwadolowski
Last active October 7, 2015 15:09
Show Gist options
  • Save jwadolowski/618991ad379d191b0d53 to your computer and use it in GitHub Desktop.
Save jwadolowski/618991ad379d191b0d53 to your computer and use it in GitHub Desktop.
Number of allocated vCPUs on XenServer
xe vm-list params=VCPUs-number --minimal | tr ',' '\n' | paste -sd+ | bc
@jwadolowski
Copy link
Author

Human-readable version:

for id in $(xe vm-list | grep uuid | awk '{print $5}'); do 
  if [[ $(xe vm-param-list uuid=${id} | grep -Po "(?<=power-state\ \(\ RO\):\ )\w+") == "running" ]]; then 
    xe vm-param-list uuid=${id} | grep -Po "(?<=VCPUs-number\ \(\ RO\):\ )[0-9]+"
  fi
done | paste -s -d+ | bc

@jwadolowski
Copy link
Author

As my colleague pointed out there's a much faster way to achieve the same as presented above, hence this gist was updated.

@jwadolowski
Copy link
Author

One last thing - when VM is not in running state it reports 0 vCPUs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment