#NEWLINE# def set_policy( vhost , name , pattern , definition , priority = None , runas = None ) : #NEWLINE# #INDENT# '\n    Set a policy based on rabbitmqctl set_policy.\n\n    Reference: http://www.rabbitmq.com/ha.html\n\n    CLI Example:\n\n    .. code-block:: bash\n\n        salt \'*\' rabbitmq.set_policy / HA \'.*\' \'{"ha-mode":"all"}\'\n    ' #NEWLINE# if ( runas is None ) : #NEWLINE# #INDENT# runas = salt . utils . get_user ( ) #NEWLINE# #UNINDENT# if isinstance ( definition , dict ) : #NEWLINE# #INDENT# definition = json . dumps ( definition ) #NEWLINE# #UNINDENT# if ( not isinstance ( definition , six . string_types ) ) : #NEWLINE# #INDENT# raise SaltInvocationError ( "The 'definition' argument must be a dictionary or JSON string" ) #NEWLINE# #UNINDENT# cmd = [ 'rabbitmqctl' , 'set_policy' , '-p' , vhost ] #NEWLINE# if priority : #NEWLINE# #INDENT# cmd . extend ( [ '--priority' , priority ] ) #NEWLINE# #UNINDENT# cmd . extend ( [ name , pattern , definition ] ) #NEWLINE# res = __salt__ [ 'cmd.run' ] ( cmd , runas = runas , python_shell = False ) #NEWLINE# log . debug ( 'Set policy: {0}' . format ( res ) ) #NEWLINE# return _format_response ( res , 'Set' )