def reboot_vm(vm_name, boot_devs=None):
LI('Begin to reboot VM %s', vm_name)
conn = libvirt.open('qemu:///system')
try:
vm = conn.lookupByName(vm_name)
except libvirt.libvirtError as e:
LE(e)
err_exit('VM %s is not found: ' % vm_name)
if boot_devs:
if vm.isActive():
vm.destroy()
LI('Destroy VM %s' % vm_name)
root = ET.fromstring(vm.XMLDesc())
LI('Modify the boot order %s' % boot_devs)
modify_vm_boot_order(root, boot_devs)
LI('Re-define and start the VM %s' % vm_name)
vm.undefine()
vm = conn.defineXML(ET.tostring(root))
vm.create()
vm.setAutostart(1)
else:
vm.reset()
conn.close()
评论列表
文章目录