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.

Use đź”— Github Discussions to ask your questions.

Create python action calling RISSservice

Hello, I am totally new in ST2.

I have python code getting data from RISSservice (see below). I want create action in ST2, which will do the same as this code. So I need this code in action and run it from ST2.
How can I do it?

Code:

from suds.client import Client
import ssl 

ssl._create_default_https_context = ssl._create_unverified_context

url = 'file:///home/ukfadmin/RISSservice.wsdl'  
client = Client(url,  
                location='myLocation',  
                username='username',  
                password='password')  
  
stateInfo = None  
  
criteria = client.factory.create('CmSelectionCriteria')  
item = client.factory.create('SelectItem')  

criteria.MaxReturnedDevices = 500  
criteria.DeviceClass = 'Phone'  
criteria.Status = 'Registered'  
criteria.SelectBy = 'Name'  

result = client.service.selectCmDevice(stateInfo, criteria)  
print result

Right, wrap that python code as StackStom Action inside a custom-made StackStorm Pack.

See: Packs — StackStorm 2.9.1 documentation
Packs — StackStorm 2.9.1 documentation
Actions — StackStorm 2.9.1 documentation

which has enough examples to get started and how to write custom Python Action.

1 Like

Thank you @armab for your comment.

But I have problem. When I create based action my_echo_action how it is describe in Actions — StackStorm 3.0.0 documentation

I use action create my_action_metadata.yaml and st2ctl reload --register-actions for creating action. It is created in my WEB UI but always when I run this action it have the same result: Failed with this error (see in picture)

I suspect that you created the pack directly in /opt/stackstorm/packs, which is not quite the correct way to do that. If that’s what you did, we can correct that by following these steps:

  1. Move your existing pack directory from /opt/stackstorm/packs/ to a different directory, such as your home directory.
  2. cd into the new pack directory.
  3. Make sure your pack is in git:
    git init
    git add pack.yaml actions/
    git commit -m "Initial commit".
  4. From within the new pack directory, run st2 pack install file://$(pwd). Note that if you have your pack on a separate version control server, you can also give the st2 pack install command the URL to that repository. You may need to run st2 login <username> if you get authentication errors when you run st2 pack install.

The st2 pack install command will handle copying your pack to the StackStorm server, creating all of the required virtualenvs, and registering all of the actions, rules, sensors, etc.

You should not ever have to manually create packs in /opt/stackstorm/packs.

1 Like

Thank you for your comment @blag

I had to use command st2 run packs.setup_virtualenv packs=“default”

and recreate my action and reload st2 actions. Now it is working.