[Libvirt-cim] [PATCH] [TEST] #2 Add some error checking when detecting hypervisor version
Kaitlin Rupert
kaitlin at linux.vnet.ibm.com
Thu Jan 22 16:02:48 UTC 2009
>> libvirt_ver = virsh_ver.splitlines()[0].split()[4]
>>
>> if virsh_ver.splitlines()[3].find("hypervisor"):
>> - hyp_ver =
>> virsh_ver.splitlines()[3].split("hypervisor")[1]
>> - hyp_ver = hyp_ver.split(": ")[1]
>> + tok = virsh_ver.splitlines()[3].split("hypervisor")
>> + if len(tok) > 1:
>> + tok = tok[1].split(": ")
>> + if len(tok) > 1:
>> + hyp_ver = tok[1]
>>
> Using splitlines() so many times and then subscripting it is a little
> confusing.
Agreed - it is confusing.
> Any specific reason for using it like this ?
>
> Here is an alternative for above:
>
> if virsh_ver != "Unknown":
> libvirt, l2, l3, hyper = virsh_ver.splitlines()
> if libvirt.find("libvir"):
> libvirt_ver = libvirt.split()[4]
> if hyper.find("hypervisor"):
> tok1 = hyper.split(":")
> hyp_ver = tok1[1]
This approach is much cleaner. Will update the patch and resend.
Thanks!
--
Kaitlin Rupert
IBM Linux Technology Center
kaitlin at linux.vnet.ibm.com
More information about the Libvirt-cim
mailing list