#NEWLINE# def pick_disk_driver_name( hypervisor_version , is_block_dev = False ) : #NEWLINE# #INDENT# 'Pick the libvirt primary backend driver name\n\n    If the hypervisor supports multiple backend drivers we have to tell libvirt\n    which one should be used.\n\n    Xen supports the following drivers: "tap", "tap2", "phy", "file", or\n    "qemu", being "qemu" the preferred one. Qemu only supports "qemu".\n\n    :param is_block_dev:\n    :returns: driver_name or None\n    ' #NEWLINE# if ( CONF . libvirt . virt_type == 'xen' ) : #NEWLINE# #INDENT# if is_block_dev : #NEWLINE# #INDENT# return 'phy' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( hypervisor_version >= 4002000 ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# execute ( 'xend' , 'status' , run_as_root = True , check_exit_code = True ) #NEWLINE# #UNINDENT# except OSError as exc : #NEWLINE# #INDENT# if ( exc . errno == errno . ENOENT ) : #NEWLINE# #INDENT# LOG . debug ( 'xend is not found' ) #NEWLINE# return 'qemu' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# #UNINDENT# except processutils . ProcessExecutionError : #NEWLINE# #INDENT# LOG . debug ( 'xend is not started' ) #NEWLINE# return 'qemu' #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# ( out , err ) = execute ( 'tap-ctl' , 'check' , check_exit_code = False ) #NEWLINE# if ( out == 'ok\n' ) : #NEWLINE# #INDENT# if ( hypervisor_version > 4000000 ) : #NEWLINE# #INDENT# return 'tap2' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return 'tap' #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# LOG . info ( _LI ( 'tap-ctl check: %s' ) , out ) #NEWLINE# #UNINDENT# #UNINDENT# except OSError as exc : #NEWLINE# #INDENT# if ( exc . errno == errno . ENOENT ) : #NEWLINE# #INDENT# LOG . debug ( 'tap-ctl tool is not installed' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# #UNINDENT# return 'file' #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( CONF . libvirt . virt_type in ( 'kvm' , 'qemu' ) ) : #NEWLINE# #INDENT# return 'qemu' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return None