EXOS Pack

# contents of a pack folder
actions/                 #
rules/                   #
sensors/                 #
aliases/                 #
policies/                #
tests/                   #
etc/                     # any additional things (e.g code generators, scripts…)
config.schema.yaml       # configuration schema
packname.yaml.example    # example of config, used in CI
pack.yaml                # pack definition file
requirements.txt         # requirements for Python packs
requirements-tests.txt   # requirements for python tests
icon.png                 # 64×64 .png icon

At the topmost level are the main folders actions, rules, sensors, aliases and policies, as well as some shared files:

  • pack.yaml – Metadata file that describes and identifies the folder as a pack.
  • config.schema.yaml – Schema that defines configuration elements used by a pack.
  • requirements.txt – File containing a list of Python dependencies. If your pack uses Python actions and/or sensors, you can specify any Python libraries you need here. They will automatically be installed in a pack-specific virtualenv when you install the pack.

Configuration Schema

The configuration schema is a YAML formatted file which defines the schema for that pack’s configuration file. This schema is written by the pack author and contains information about every available configuration item (name, type, is value a secret, etc). The file is named config.schema.yaml and is located in the root of the pack directory (/opt/stackstorm/packs/<mypack>/).

/opt/stackstorm/packs/exos

config.schema.yaml


username:
description: “Login username”
type: “string”
required: true
default: “admin”
password:
description: “Login password”
type: “string”
required: true
default: “”

pack.yaml


ref: exos
name: EXOS
description: Actions for managing Extreme Networks EXOS devices
keywords:
– exos
– extreme
– networking
version: 0.0.2
author: Extreme Networks
email: support@extremenetworks.com

Configuration File

The configuration file is a YAML formatted file which contains site-specific configuration values. This file can contain ‘static’ or ‘dynamic’ values. The configuration file is named <pack name>.yaml and located in the /opt/stackstorm/configs/ directory. File ownership should be st2:st2.

For example, for a pack named libcloud, the configuration file is located at /opt/stackstorm/configs/libcloud.yaml.

/opt/stackstorm/packs/exos

exos.yaml.example


username: “admin”
password: “SuperSecret”

/opt/stackstorm/configs

exos.yaml

username: admin

Note : When modifying the configuration in /opt/stackstorm/configs/ please remember to tell StackStorm to load these new values by running st2ctl reload --register-configs

Actions

# contents of actions/
actions/
lib/
action1.yaml
action1.py
action2.yaml
action1.sh
workflow1.yaml
workflow2.yaml
workflows/
workflow1.yaml
workflow2.yaml

cmd.yaml


name: “cmd”
runner_type: “python-script”
description: “run list of EXOS commands on a remote switch.”
enabled: true
entry_point: “cmd.py”
parameters:
ipaddress:
type: “string”
description: “IP address of the EXOS switch.”
required: true
position: 0
cmd:
type: “string”
description: “List of EXOS CLI commands.”
required: true
position: 1

cmd.py

import sys
from lib.jsonrpc import JsonRPC
from st2common.runners.base_action import Action

class ExosCmd(Action):

def run(self, ipaddress=’10.68.65.81′, cmd=”):
“””
Run an EXOS command on the remote switch

Args:
– ip_address: The IP address of the switch
– username: login user name
– password: login password
– cmd: either a single EXOS command or list of EXOS commands

Raises:
– ValueError: On switch reponse being invalid
– RuntimeError: if switch cannot process the command

Returns:
dict: with EXOS CLI results
“””

jsonrpc = JsonRPC(ipaddress, self.config[‘username’], self.config[‘password’])
jsonrpc.cookie = self.action_service.get_value(‘cookie’)

try:
response = jsonrpc.send(cmd)
self.action_service.set_value(name=’cookie’, value=jsonrpc.cookie)
return response
except Exception:
sys.exit(1)

The actions folder contains action script files and action metadata files. See Actions and Workflows for specifics on writing actions. Since metadata files and workflow definitions can both be written as YAML, it’s good practice to put the workflow definitions in a separate directory. Note that the lib sub-folder is often used for storing common Python code used by pack actions.

ls lib
__init__.py  __init__.pyc  jsonrpc.py  jsonrpc.pyc

https://docs.stackstorm.com/reference/packs.html

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s