How do I invoke the salt call state.highstate from a Python script?
You can use the salt client API to achieve this goal .
When starting without skill, you should use a class Caller
that provides the same interface as the command line tool salt-call
on Minion.
import salt caller = salt.client.Caller() output = caller.function('state.highstate')
The result here is the full result of the high state - there is no current way to run asynchronously.
To run highstate on a minion, use the interface LocalClient
on the salt server:
import salt client = salt.client.LocalClient() jid = client.cmd_async('minion-name', 'state.highstate')
The variable here jid
is the Salt job ID for the highstate job. Then you can ask Salt to do the jobs with:
client.cmd('minion-name', 'saltutil.running')
Which, when run in a loop, will allow you to check if the highstate has completed.
source to share
it looks like you might need to write a returner that stores the result in a file or something
and call the command with
subprocess.check_output("salt-call state.highstate --returner=myReturner",shell=True)
#if the command blocks and does not return immediatly at this point it is finished
#if the command does not block you will have to check for the file that your returner creates until it exists
while not os.path.exists("my_returner_output.txt"):
time.sleep(1)
print "OK COMMAND COMPLETE"
source to share