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


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(
    url='https://mydomain.com/ovirt-engine/api',
    username='myuser@internal',
    password='******',
    ca_file='pki-resource.cer',
    debug=False,
    log=logging.getLogger(),
)

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

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

    for cl in cls:
      print('\n\n---',dc.name,cl.name.split('-',2)[2],'-'.ljust(135,'-'))
      host_service = connection.system_service().hosts_service()
      hosts = host_service.list(search='cluster='+cl.name)

      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
        tit=('')

        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',host.name,'\t ',tit)
        vms_service = connection.system_service().vms_service()
        virtual_machines = vms_service.list(search='Hosts.name='+host.name)
        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!')
            else:
              str_pin = ('    WARN: '+ str(total_vcpus) + ' vCPUs configured but not pinned')
            
            print('\t\t',vm.name.split('.')[0],str_pin.ljust(130),'|',vm.comment[0:40].ljust(42))
   
# Close the connection to the server:
connection.close()



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