But when the operation isn't supported for a particular hypervisor type, you better be prepared to handle this scenario. Libvirt only defines a single exception type but we can determine that it is a hypervisor interface support issue by looking at the error code.
This is shown below. The following operation on the domain will fail on KVM.
import libvirt
if __name__ == "__main__":
conn = libvirt.open("qemu:///system")
for id in conn.listDomainsID():
domain = conn.lookupByID(id)
try:
domain.reboot(0)
except libvirt.libvirtError, e:
if e.get_error_code() == libvirt.VIR_ERR_NO_SUPPORT:
print "Cannot Reboot"
No comments :
Post a Comment