Is there any libvirt command that can be used to change boot order for a VM? I know edit xml file can complete this, but I need a command to do this becos I have to shell the command in a script.
Thanks, Leo
There is no such virsh
call. However libvirt comes with a python binding. You can easily write a tiny python script you could invoke from your script. Something like this would help you getting started:
import libvirt
from xml.etree import ElementTree
try:
cnx = libvirt.open()
domain = cnx.lookupByName('yournamename')
desc = ElementTree.fromstring(domain.XMLDesc())
os_node = desc.find('os')
if os_node is not None:
boot_nodes = os_node.findall('boot')
for boot_node in boot_nodes:
os_node.remove(boot_node)
# TODO Change the order of boot_nodes here
for boot_node in boot_nodes:
os_node.append(boot_node)
# Write back the definition
cnx.defineXML(ElementTree.tostring(desc).decode())
except libvirt.libvirtError as err:
print(err.get_error_message())