#NEWLINE# def lookup( session , name_label , check_rescue = False ) : #NEWLINE# #INDENT# "Look the instance up and return it if available.\n    :param:check_rescue: if True will return the 'name'-rescue vm if it\n    exists, instead of just 'name'\n    " #NEWLINE# if check_rescue : #NEWLINE# #INDENT# result = lookup ( session , ( name_label + '-rescue' ) , False ) #NEWLINE# if result : #NEWLINE# #INDENT# return n #NEWLINE# #UNINDENT# #UNINDENT# vm_refs = session . call_xenapi ( 'VM.get_by_name_label' , name_label ) #NEWLINE# n = len ( vm_refs ) #NEWLINE# if ( n == 0 ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( n > 1 ) : #NEWLINE# #INDENT# raise exception . InstanceExists ( name = name_label ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return vm_refs [ 0 ]