{"id":869,"date":"2024-01-18T18:46:44","date_gmt":"2024-01-18T17:46:44","guid":{"rendered":"https:\/\/anjo.pt\/keyword-oracle\/?p=869"},"modified":"2024-04-25T12:34:12","modified_gmt":"2024-04-25T10:34:12","slug":"nice-table-for-oracle-olvm-vms-hosts-clusters-and-vcpu-pinning","status":"publish","type":"post","link":"https:\/\/anjo.pt\/keyword-oracle\/2024\/01\/18\/nice-table-for-oracle-olvm-vms-hosts-clusters-and-vcpu-pinning\/","title":{"rendered":"Nice table for Oracle OLVM: VMs, hosts, clusters and vcpu pinning"},"content":{"rendered":"\n<p>On my client infrastructure, for improved performance, we need to make sure each VM is pinning to different physical cores. <\/p>\n\n\n\n<p>We do the changes for the moment using the web interface. However, to read easily what the current status is, I&#8217;ve wrote a python script that draws a nice table showing where each VM is running and to which cores its vcpu are pinned.<\/p>\n\n\n\n<p>The result is something like this:<\/p>\n\n\n\n<!--more-->\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/anjo.pt\/keyword-oracle\/wp-content\/uploads\/sites\/3\/2024\/01\/image-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"424\" src=\"https:\/\/anjo.pt\/keyword-oracle\/wp-content\/uploads\/sites\/3\/2024\/01\/image-1-1024x424.png\" alt=\"\" class=\"wp-image-871\" srcset=\"https:\/\/anjo.pt\/keyword-oracle\/wp-content\/uploads\/sites\/3\/2024\/01\/image-1-1024x424.png 1024w, https:\/\/anjo.pt\/keyword-oracle\/wp-content\/uploads\/sites\/3\/2024\/01\/image-1-300x124.png 300w, https:\/\/anjo.pt\/keyword-oracle\/wp-content\/uploads\/sites\/3\/2024\/01\/image-1-768x318.png 768w, https:\/\/anjo.pt\/keyword-oracle\/wp-content\/uploads\/sites\/3\/2024\/01\/image-1-1536x635.png 1536w, https:\/\/anjo.pt\/keyword-oracle\/wp-content\/uploads\/sites\/3\/2024\/01\/image-1.png 1620w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>And here is the code, feel free to use:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n#!\/usr\/bin\/env python\n# -*- coding: utf-8 -*-\n\n# Miguel Anjo, 18.01.2024\n# Creates table of all VMs running in OLVM, and pinned vCPUs\n\nimport sys\nimport logging\nimport ovirtsdk4 as sdk\nimport ovirtsdk4.types as types\nimport inspect\nimport subprocess as sp\nfrom pprint import pprint\n\nlogging.basicConfig(level=logging.ERROR, filename=&#039;list_vms.log&#039;)\n\n# Create the connection to the server:\nconnection = sdk.Connection(\n    url=&#039;https:\/\/mydomain.com\/ovirt-engine\/api&#039;,\n    username=&#039;myuser@internal&#039;,\n    password=&#039;******&#039;,\n    ca_file=&#039;pki-resource.cer&#039;,\n    debug=False,\n    log=logging.getLogger(),\n)\n\n       \ndcs_service = connection.system_service().data_centers_service()\ndcs = dcs_service.list()\n\nfor dc in dcs:\n    #print(dc.name)\n    cls_service = connection.system_service().clusters_service()\n    cls = cls_service.list(search=&#039;Datacenter=&#039;+dc.name)\n\n    for cl in cls:\n      print(&#039;\\n\\n---&#039;,dc.name,cl.name.split(&#039;-&#039;,2)&#x5B;2],&#039;-&#039;.ljust(135,&#039;-&#039;))\n      host_service = connection.system_service().hosts_service()\n      hosts = host_service.list(search=&#039;cluster=&#039;+cl.name)\n\n      for host in hosts:\n        num_cpu_cores = host.cpu.topology.cores if host.cpu.topology else 0\n        num_cpu_sockets = host.cpu.topology.sockets if host.cpu.topology else 0\n        tit=(&#039;&#039;)\n\n        for socket in range(num_cpu_sockets):\n          for core in range(num_cpu_cores):\n            tit += (&#039; c&#039;+str(core+(socket*(num_cpu_cores))).zfill(2))\n          tit+= (&#039; |&#039;)\n        \n        print(&#039;\\n\\t&#039;,host.name,&#039;\\t &#039;,tit)\n        vms_service = connection.system_service().vms_service()\n        virtual_machines = vms_service.list(search=&#039;Hosts.name=&#039;+host.name)\n        if len(virtual_machines) &gt; 0:\n          for vm in virtual_machines:\n            total_vcpus = (vm.cpu.topology.sockets * vm.cpu.topology.cores *vm.cpu.topology.threads)\n            if vm.cpu.cpu_tune:\n              init_pin = int(vm.cpu.cpu_tune.vcpu_pins&#x5B;0].cpu_set)            \n              str_pin = (&#039; &#039;.ljust((init_pin*4)+1))\n              # only prepared for 2 sockets and not crossing over socket\n              if init_pin &gt;= num_cpu_cores:\n                str_pin += (&#039;  &#039;)\n              for n in range(len(vm.cpu.cpu_tune.vcpu_pins)):\n                str_pin += (&#039;\u25a0\u25a0\u25a0 &#039;)\n              if total_vcpus != len(vm.cpu.cpu_tune.vcpu_pins):\n                 str_pin += (&#039;    WARN: Not all &#039;+ str(total_vcpus) + &#039; vCPUs are pinned!&#039;)\n            else:\n              str_pin = (&#039;    WARN: &#039;+ str(total_vcpus) + &#039; vCPUs configured but not pinned&#039;)\n            \n            print(&#039;\\t\\t&#039;,vm.name.split(&#039;.&#039;)&#x5B;0],str_pin.ljust(130),&#039;|&#039;,vm.comment&#x5B;0:40].ljust(42))\n   \n# Close the connection to the server:\nconnection.close()\n\n\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>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&#8217;ve wrote a python script that draws a nice table showing where each VM is [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[76,6],"tags":[],"class_list":{"0":"post-869","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-olvm","7":"category-oracle","8":"czr-hentry"},"_links":{"self":[{"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/posts\/869","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/comments?post=869"}],"version-history":[{"count":1,"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/posts\/869\/revisions"}],"predecessor-version":[{"id":872,"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/posts\/869\/revisions\/872"}],"wp:attachment":[{"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/media?parent=869"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/categories?post=869"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/tags?post=869"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}