diff --git a/lib/smart_proxy_salt/cli.rb b/lib/smart_proxy_salt/cli.rb index bd2f3fb..54895f2 100644 --- a/lib/smart_proxy_salt/cli.rb +++ b/lib/smart_proxy_salt/cli.rb @@ -69,6 +69,13 @@ def highstate(host) shell_command(cmd) end + def refresh_pillar(host) + find_salt_binaries + cmd = [@sudo, '-u', Proxy::Salt::Plugin.settings.salt_command_user, @salt, '--async', escape_for_shell(host), 'saltutil.refresh_pillar'] + logger.info "Will run saltutil.refresh_pillar for #{host}. Full command: #{cmd.join(' ')}" + shell_command(cmd) + end + def key_delete(host) find_salt_binaries cmd = [@sudo, '-u', Proxy::Salt::Plugin.settings.salt_command_user, @salt_key, '--yes', '-d', escape_for_shell(host)] diff --git a/lib/smart_proxy_salt/salt_api.rb b/lib/smart_proxy_salt/salt_api.rb index abfbf56..3660a0e 100644 --- a/lib/smart_proxy_salt/salt_api.rb +++ b/lib/smart_proxy_salt/salt_api.rb @@ -70,6 +70,16 @@ class Api < ::Sinatra::Base end end + post '/refresh_pillar/:host' do + content_type :json + begin + log_halt 500, "Failed pillar refresh for #{params[:host]}: Check Log files" unless (result = Proxy::Salt.refresh_pillar(params[:host])) + result + rescue Exception => e + log_halt 406, "Failed pillar refresh for #{params[:host]}: #{e}" + end + end + delete '/key/:host' do content_type :json begin