#NEWLINE# def str2vg( ns , vg ) : #NEWLINE# #INDENT# '\n    Convert string with name of volume group to LMIInstance of the\n    LMI_VGStoragePool.\n\n    If LMIInstance is provided, nothing is done and the instance is just\n    returned. If string is provided, appropriate LMIInstance is looked up and\n    returned.\n\n    This functions throws an error when the device cannot be found.\n\n    The main purpose of this function is to convert parameters in functions,\n    where both string and LMIInstance is allowed.\n\n    :type vg: LMIInstance/LMI_VGStoragePool or string\n    :param vg: VG to retrieve.\n    :rtype: LMIInstance/LMI_VGStoragePool\n\n    ' #NEWLINE# if isinstance ( vg , LMIInstance ) : #NEWLINE# #INDENT# return vg #NEWLINE# #UNINDENT# if ( not isinstance ( vg , str ) ) : #NEWLINE# #INDENT# raise TypeError ( ( 'string or LMIInstance expected, got %s' % vg . __class__ . __name__ ) ) #NEWLINE# #UNINDENT# query = ( 'SELECT * FROM LMI_VGStoragePool WHERE ElementName="%(vg)s"' % { #NEWLINE# #INDENT# 'vg' : escape_cql ( vg ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# vgs = ns . wql ( query ) #NEWLINE# if ( not vgs ) : #NEWLINE# #INDENT# raise LmiFailed ( ( "Volume Group '%s' not found." % ( vg , ) ) ) #NEWLINE# #UNINDENT# if ( len ( vgs ) > 1 ) : #NEWLINE# #INDENT# raise LmiFailed ( ( "Too many volume groups with name '%s' found." % ( vg , ) ) ) #NEWLINE# #UNINDENT# LOG ( ) . debug ( "String %s translated to Volume Group '%s'." , vg , vgs [ 0 ] . InstanceID ) #NEWLINE# return vgs [ 0 ]