#NEWLINE# def install_agent( agent_key , agent_version = 1 ) : #NEWLINE# #INDENT# "\n    Function downloads Server Density installation agent, and installs sd-agent\n    with agent_key. Optionally the agent_version would select the series to\n    use (defaults on the v1 one).\n\n    CLI Example:\n\n    .. code-block:: bash\n\n        salt '*' serverdensity_device.install_agent c2bbdd6689ff46282bdaa07555641498\n        salt '*' serverdensity_device.install_agent c2bbdd6689ff46282bdaa07555641498 2\n    " #NEWLINE# work_dir = os . path . join ( __opts__ [ 'cachedir' ] , 'tmp' ) #NEWLINE# if ( not os . path . isdir ( work_dir ) ) : #NEWLINE# #INDENT# os . mkdir ( work_dir ) #NEWLINE# #UNINDENT# install_file = tempfile . NamedTemporaryFile ( dir = work_dir , suffix = '.sh' , delete = False ) #NEWLINE# install_filename = install_file . name #NEWLINE# install_file . close ( ) #NEWLINE# account_field = 'account_url' #NEWLINE# url = 'https://www.serverdensity.com/downloads/agent-install.sh' #NEWLINE# if ( work_dir == 2 ) : #NEWLINE# #INDENT# account_field = 'account_name' #NEWLINE# url = 'https://archive.serverdensity.com/agent-install.sh' #NEWLINE# #UNINDENT# account = get_sd_auth ( account_field ) #NEWLINE# __salt__ [ 'cmd.run' ] ( cmd = 'curl -L {0} -o {1}' . format ( url , install_filename ) , cwd = work_dir ) #NEWLINE# __salt__ [ 'cmd.run' ] ( cmd = 'chmod +x {0}' . format ( install_filename ) , cwd = work_dir ) #NEWLINE# return __salt__ [ 'cmd.run' ] ( cmd = '{filename} -a {account} -k {agent_key}' . format ( filename = install_filename , account = account , agent_key = agent_key ) , cwd = work_dir )