<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import json <EOL> import logging <EOL> import salt . utils <EOL> import salt . utils . http <EOL> LOG = logging . getLogger ( __name__ ) <EOL> def __virtual__ ( ) : <EOL> return '<STR_LIT>' if salt . utils . which ( '<STR_LIT>' ) else False <EOL> def get_task ( name ) : <EOL> '''<STR_LIT>''' <EOL> host = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' , '<STR_LIT:localhost>' ) <EOL> port = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' , <NUM_LIT> ) <EOL> url = '<STR_LIT>' . format ( host , port , name ) <EOL> response = salt . utils . http . query ( url , status = True ) <EOL> if response [ '<STR_LIT:status>' ] == <NUM_LIT> : <EOL> return None <EOL> data = json . loads ( response [ '<STR_LIT:body>' ] ) <EOL> return data <EOL> def _run_cmd ( cmd ) : <EOL> '''<STR_LIT>''' <EOL> ret = { } <EOL> result = __salt__ [ '<STR_LIT>' ] ( cmd ) <EOL> if result . get ( '<STR_LIT>' ) : <EOL> ret [ '<STR_LIT>' ] = result [ '<STR_LIT>' ] <EOL> if result . get ( '<STR_LIT>' ) : <EOL> ret [ '<STR_LIT>' ] = result [ '<STR_LIT>' ] <EOL> ret [ '<STR_LIT:success>' ] = result [ '<STR_LIT>' ] == <NUM_LIT:0> <EOL> return ret <EOL> def define_task ( name , <EOL> tick_script , <EOL> task_type = '<STR_LIT>' , <EOL> database = None , <EOL> retention_policy = '<STR_LIT:default>' ) : <EOL> '''<STR_LIT>''' <EOL> cmd = '<STR_LIT>' . format ( name , tick_script ) <EOL> if tick_script . startswith ( '<STR_LIT>' ) : <EOL> tick_script = __salt__ [ '<STR_LIT>' ] ( tick_script , __env__ ) <EOL> if task_type : <EOL> cmd += '<STR_LIT>' . format ( task_type ) <EOL> if database and retention_policy : <EOL> cmd += '<STR_LIT>' . format ( database , retention_policy ) <EOL> return _run_cmd ( cmd ) <EOL> def delete_task ( name ) : <EOL> '''<STR_LIT>''' <EOL> return _run_cmd ( '<STR_LIT>' . format ( name ) ) <EOL> def enable_task ( name ) : <EOL> '''<STR_LIT>''' <EOL> return _run_cmd ( '<STR_LIT>' . format ( name ) ) <EOL> def disable_task ( name ) : <EOL> '''<STR_LIT>''' <EOL> return _run_cmd ( '<STR_LIT>' . format ( name ) ) </s>
