Nice table for Oracle OLVM: VMs, hosts, clusters and vcpu pinning 2

On my client infrastructure, for improved performance, we need to make sure each VM is pinning to different physical cores.

We do the changes for the moment using the web interface. However, to read easily what the current status is, I’ve wrote a python script that draws a nice table showing where each VM is running and to which cores its vcpu are pinned.

The result is something like this:

And here is the code, feel free to use:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Miguel Anjo, 18.01.2024
# Creates table of all VMs running in OLVM, and pinned vCPUs

import sys
import logging
import ovirtsdk4 as sdk
import ovirtsdk4.types as types
import inspect
import subprocess as sp
from pprint import pprint

logging.basicConfig(level=logging.ERROR, filename='list_vms.log')

# Create the connection to the server:
connection = sdk.Connection(

dcs_service = connection.system_service().data_centers_service()
dcs = dcs_service.list()

for dc in dcs:
    cls_service = connection.system_service().clusters_service()
    cls = cls_service.list(search='Datacenter='

    for cl in cls:
      host_service = connection.system_service().hosts_service()
      hosts = host_service.list(search='cluster='

      for host in hosts:
        num_cpu_cores = host.cpu.topology.cores if host.cpu.topology else 0
        num_cpu_sockets = host.cpu.topology.sockets if host.cpu.topology else 0

        for socket in range(num_cpu_sockets):
          for core in range(num_cpu_cores):
            tit += (' c'+str(core+(socket*(num_cpu_cores))).zfill(2))
          tit+= (' |')
        print('\n\t',,'\t ',tit)
        vms_service = connection.system_service().vms_service()
        virtual_machines = vms_service.list(search=''
        if len(virtual_machines) > 0:
          for vm in virtual_machines:
            total_vcpus = (vm.cpu.topology.sockets * vm.cpu.topology.cores *vm.cpu.topology.threads)
            if vm.cpu.cpu_tune:
              init_pin = int(vm.cpu.cpu_tune.vcpu_pins[0].cpu_set)            
              str_pin = (' '.ljust((init_pin*4)+1))
              # only prepared for 2 sockets and not crossing over socket
              if init_pin >= num_cpu_cores:
                str_pin += ('  ')
              for n in range(len(vm.cpu.cpu_tune.vcpu_pins)):
                str_pin += ('■■■ ')
              if total_vcpus != len(vm.cpu.cpu_tune.vcpu_pins):
                 str_pin += ('    WARN: Not all '+ str(total_vcpus) + ' vCPUs are pinned!')
              str_pin = ('    WARN: '+ str(total_vcpus) + ' vCPUs configured but not pinned')
# Close the connection to the server:

Leave a comment

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

2 thoughts on “Nice table for Oracle OLVM: VMs, hosts, clusters and vcpu pinning