#NEWLINE# def present( name , definition ) : #NEWLINE# #INDENT# '\n    Ensure that the named index is present\n    ' #NEWLINE# ret = { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# 'result' : True , #NEWLINE# 'comment' : '' , #NEWLINE# #UNINDENT# } #NEWLINE# index_exists = __salt__ [ 'elasticsearch.index_exists' ] ( name = name ) #NEWLINE# if ( not index_exists ) : #NEWLINE# #INDENT# if __opts__ [ 'test' ] : #NEWLINE# #INDENT# ret [ 'comment' ] = 'Index {0} will be created' . format ( name ) #NEWLINE# ret [ 'result' ] = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ret [ 'result' ] = __salt__ [ 'elasticsearch.index_create' ] ( index = name , body = definition ) #NEWLINE# if name [ 'result' ] : #NEWLINE# #INDENT# ret [ 'comment' ] = 'Created index {0} successfully' . format ( name ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if index_exists : #NEWLINE# #INDENT# ret [ 'comment' ] = 'Index {0} is already present' . format ( name ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ret [ 'comment' ] = 'Failed to determine whether index {0} is present, see Minion log for more information' . format ( name ) #NEWLINE# ret [ 'result' ] = False #NEWLINE# #UNINDENT# #UNINDENT# return ret