This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.
⚠️ We've moved!
Hi there!
To reduce project dependency on 3rd party paid services the StackStorm TSC has decided to move the Q/A from this forum to Github Discussions. This will make user experience better integrated with the native Github flow, as well as the questions closer to the community where they can provide answers.
Is there any way to invoke execution of an action from the python client? I would like to execute an
action from an action without using action chain or mistral. I ended up using my one ActionManager but I
wonder if there is a better API supported by the python client.
@nmaludy
Thank you for your reply! I guess your script is more generic for usage outside the stackstorm
server.
What I want to achieve is invoking an action from an action without using action chain or a mistral
flow.For my case, my script is more a fit as you can import ActionManager in every action you want.
What I was looking for is an API direct from the client. Something like —>
@n_kos this is using an api “directly
from the client” by calling execution = client.liveactions.create(execution_instance)
However, this function does not take arbitrary parameters like you want, instead it requires a LiveAction
object to be passed in.
About the shortest i could condense it down into is the following. This assumes that you’re running
inside a StackStorm action because it relies on the ST2_AUTH_TOKEN environment variable
being set.
from st2common.runners.base_action import Action
from st2client.client import Client
from st2client.models import LiveAction
class ActionManager(object):
def execute(self, server, action, params):
client = Client(base_url="https://{}/".format(server))
client.liveactions.create(LiveAction(action=action, parameters=params))
class ActionRunner(Action):
def run(self):
am = ActionManager()
am.execute("127.0.0.1",
"core.local",
{"cmd": "ls"})
@nmaludy This is working as expected
but action is getting triggered Asynchronously.
Is it possible to retrieve the result of action triggered in python script ?
@sakshi95gupta Yes, please see
the first code snipped in my original post. Hint, it’s the code snipped with the while loop: while
execution.status in PENDING_STATUSES: