#NEWLINE# def present( name , if_not_exists = None , schema = None , ext_version = None , from_version = None , user = None , maintenance_db = None , db_password = None , db_host = None , db_port = None , db_user = None ) : #NEWLINE# #INDENT# '\n    Ensure that the named extension is present with the specified privileges\n\n    name\n        The name of the extension to manage\n\n    if_not_exists\n        Add a if_not_exists switch to the ddl statement\n\n    schema\n        Schema to install the extension into\n\n    from_version\n        Old extension version if already installed\n\n    ext_version\n        version to install\n\n    user\n        System user all operations should be performed on behalf of\n\n    maintenance_db\n        Database to act on\n\n    db_user\n        database username if different from config or default\n\n    db_password\n        user password if any password for a specified user\n\n    db_host\n        Database host if different from config or default\n\n    db_port\n        Database port if different from config or default\n    ' #NEWLINE# ret = { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# 'result' : True , #NEWLINE# 'comment' : 'Extension {0} is already present' . format ( name ) , #NEWLINE# #UNINDENT# } #NEWLINE# db_args = { #NEWLINE# #INDENT# 'maintenance_db' : maintenance_db , #NEWLINE# 'runas' : user , #NEWLINE# 'host' : db_host , #NEWLINE# 'user' : db_user , #NEWLINE# 'port' : db_port , #NEWLINE# 'password' : db_password , #NEWLINE# #UNINDENT# } #NEWLINE# mode = 'create' #NEWLINE# mtdata = __salt__ [ 'postgres.create_metadata' ] ( name , schema = schema , ext_version = ext_version , ** db_args ) #NEWLINE# toinstall = ( postgres . _EXTENSION_NOT_INSTALLED in mtdata ) #NEWLINE# if toinstall : #NEWLINE# #INDENT# mode = 'install' #NEWLINE# #UNINDENT# toupgrade = False #NEWLINE# if ( postgres . _EXTENSION_INSTALLED in mtdata ) : #NEWLINE# #INDENT# for flag in [ postgres . _EXTENSION_TO_MOVE , postgres . _EXTENSION_TO_UPGRADE ] : #NEWLINE# #INDENT# if ( flag in mtdata ) : #NEWLINE# #INDENT# toupgrade = True #NEWLINE# mode = 'upgrade' #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if __opts__ [ 'test' ] : #NEWLINE# #INDENT# ret [ 'result' ] = None #NEWLINE# if mode : #NEWLINE# #INDENT# ret [ 'comment' ] = 'Extension {0} is set to be {1}ed' . format ( name , mode ) . replace ( 'eed' , 'ed' ) #NEWLINE# #UNINDENT# return ret #NEWLINE# #UNINDENT# cret = None #NEWLINE# if ( toinstall or toupgrade ) : #NEWLINE# #INDENT# cret = __salt__ [ 'postgres.create_extension' ] ( name = name , if_not_exists = if_not_exists , schema = schema , ext_version = ext_version , from_version = from_version , ** db_args ) #NEWLINE# #UNINDENT# if cret : #NEWLINE# #INDENT# if mode . endswith ( 'e' ) : #NEWLINE# #INDENT# suffix = 'd' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# suffix = 'ed' #NEWLINE# #UNINDENT# ret [ 'comment' ] = 'The extension {0} has been {1}{2}' . format ( name , mode , suffix ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( cret is not None ) : #NEWLINE# #INDENT# ret [ 'comment' ] = 'Failed to {1} extension {0}' . format ( name , mode ) #NEWLINE# ret [ 'result' ] = False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ret [ 'result' ] = True #NEWLINE# #UNINDENT# #UNINDENT# return ret