libvirt: Add some try...except and a function to check cpu mode is valid or not

Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com>