#NEWLINE# def get_vdi_for_vm_safely( session , vm_ref , userdevice = '0' ) : #NEWLINE# #INDENT# 'Retrieves the primary VDI for a VM.' #NEWLINE# vbd_refs = _vm_get_vbd_refs ( session , vm_ref ) #NEWLINE# for vbd_ref in vbd_refs : #NEWLINE# #INDENT# vbd_rec = _vbd_get_rec ( vdi_ref , vbd_ref ) #NEWLINE# if ( vbd_rec [ 'userdevice' ] == userdevice ) : #NEWLINE# #INDENT# vdi_ref = vbd_rec [ 'VDI' ] #NEWLINE# vdi_rec = _vdi_get_rec ( session , vdi_ref ) #NEWLINE# return ( vdi_ref , vdi_rec ) #NEWLINE# #UNINDENT# #UNINDENT# raise exception . NovaException ( ( _ ( 'No primary VDI found for %s' ) % vm_ref ) )