User Tools

Site Tools


unix:scripts:libvirt

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
unix:scripts:libvirt [2024/09/20 20:32] – created rodolicounix:scripts:libvirt [2024/09/20 21:23] (current) rodolico
Line 4: Line 4:
  
 This little one liner grabs the lines that define the vnc ports used by all defined on a node (hypervisor) and returns them as a tab delimited string. This little one liner grabs the lines that define the vnc ports used by all defined on a node (hypervisor) and returns them as a tab delimited string.
 +
 +==== Code ====
  
 <code bash> <code bash>
Line 22: Line 24:
 libvirt (virsh) stores it's domain (virtual) definitions in /etc/libvirt/qemu/*.xml. The //grep// command only returns those lines (along with the file name) in the form libvirt (virsh) stores it's domain (virtual) definitions in /etc/libvirt/qemu/*.xml. The //grep// command only returns those lines (along with the file name) in the form
 <code> <code>
-/media/shared/havirt/conf/andrei.dailydata.noc.xml:    <graphics type='vnc' port='5917' autoport='no' listen='127.0.0.1'>+/etc/libvirt/qemu/andrei.dailydata.noc.xml:    <graphics type='vnc' port='5917' autoport='no' listen='127.0.0.1'>
 </code> </code>
  
 We then pass those lines to a Perl one liner which grabs the filename (without the .xml) and the port, then prints them to STDOUT, tab separated. Using the -n flag to perl turns the one liner into a filter, which will run the code on all lines received via STDIN. For the above line, the following is sent to STDOUT We then pass those lines to a Perl one liner which grabs the filename (without the .xml) and the port, then prints them to STDOUT, tab separated. Using the -n flag to perl turns the one liner into a filter, which will run the code on all lines received via STDIN. For the above line, the following is sent to STDOUT
 <code>andrei.dailydata.noc 5917</code> <code>andrei.dailydata.noc 5917</code>
 +
 +==== Caveats ====
 +
 +  * If there is only one domain defined, grep does not return the filename, so the system breaks.
 +  * This is totally dependent on how libvirt stores the data; path, key and whether the key is on the same line. Any changes to the libvirt storage will break the script.
 +  * We use [[https://unixservertech.com/havirt/|havirt]] for our clusters. havirt stores the domain definitions in <installdir>/conf, so the grep command will need to be changed.
unix/scripts/libvirt.1726882376.txt.gz · Last modified: 2024/09/20 20:32 by rodolico