Skip to main content

Lightweight SDK to simplify interacting with the Itential automation gateway API.

Project description

itential-iag-sdk

Lightweight SDK to simplify interacting with the Itential automation gateway API.

This is an beta release. Please ensure the package works as expected in your environment before using it in production as there may still be bugs.

This package was written for Itential Automation Gateway 2023.1.

Getting Started

Make sure you have a supported version of Python installed and then create and activate a virtual environment:

python -m venv venv

source /venv/bin/activate

You can install the iag_sdk from Pypi as follows:

pip install iag_sdk

Or you can install it from source as follows:

git clone https://github.com/awetomate/itential-iag-sdk.git
cd itential-iag-sdk
python -m pip install -r requirements.txt
python -m pip install -e .

Usage

from iag_sdk import Iag

username = "admin@itential"
password = "yourpass"
host = "yourhost"

iag = Iag(host=host, username=username, password=password, verify=False)

iag.accounts.get_account(name="admin@itential")
#{'email': 'admin@itential.com', 'firstname': None, 'lastname': None, 'username': 'admin@itential'}

iag_sdk uses the following default values. You can overwrite any of them during instantiation:

class Iag:
    def __init__(
        self,
        host: str,
        username: str,
        password: str,
        base_url: str = "/api/v2.0",
        protocol: str = "http",
        port: Union[int, str] = 8083,
        verify: bool = True,
    ) -> None:

The iag_sdk methods are grouped in the same manner as in Itential's API documentation. I.e. all API calls related to collections are available under iag.collections. and all API calls related to (Ansible) devices are available under iag.devices.

Examples

# get the server status
iag.system.get_status()

# list the first 10 Ansible devices that have 'SW' in their hostname
iag.devices.get_all(limit=10, filter='contains({"name": "SW"})')

# get a specific Ansible device
iag.devices.get(name="device1")

# check the state for a specific Ansible device
iag.devices.get_state(name="device1")

Work with Ansible collections:

# get one collection
iag.collections.get(collection_name="cisco.asa")

# get modules for a specific collection
iag.collections.get_modules(collection_name="cisco.asa")

# list all collections
iag.collections.get_all()

# refresh collections / perform a collection discovery
iag.collections.refresh()

Work with Netmiko:

# IAG native
iag.netmiko.execute_send_command_native(host="device1", command_string="show version")

# legacy
iag.netmiko.execute_send_command_legacy(host="device1", commands=["show version"], device_type="cisco_ftd", username="youruser", password="yourpassword", port=22)

The all-purpose 'query' method

The iag_sdk includes a generic 'query' method that can be used for every Itential automation gateway API call. In fact, all the other methods ultimately use the generic 'query' method to send calls to AG.

The query method by default sends GET requests without any data or parameters. However, you can use the 'query' method to send get, delete, post, put, and patch requests by changing the 'method' argument. You can also send data by various means (params, data, jsonbody).

The generic 'query' method potentially could come in handy to overcome differences in the API between automation gateway versions. If any of the existing methods don't work with your AG version, try the generic 'query' method as a fallback.

Basic GET call using 'query'

# get the server status
iag.query("/status")
# or to be more explicit
iag.query("/status", method="get")

# get a specific collection
collection_name = "cisco.asa"
iag.query(f"collections/{collection_name}")
# or define the endpoint statically
iag.query("collections/cisco.asa")

# list the first 10 Ansible devices that have 'SW' in their hostname
iag.query("/devices", params={"limit": 10, "filter": 'contains({"name":"SW"})'})

Basic POST call using 'query'

iag.query("/collections/refresh", method="post")

iag.query("/netmiko/send_command/execute", method="post", jsonbody={"host": "networkdevice", "command_string": "show version"})

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iag_sdk-2023.12b1.tar.gz (18.7 kB view details)

Uploaded Source

Built Distribution

iag_sdk-2023.12b1-py3-none-any.whl (35.5 kB view details)

Uploaded Python 3

File details

Details for the file iag_sdk-2023.12b1.tar.gz.

File metadata

  • Download URL: iag_sdk-2023.12b1.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for iag_sdk-2023.12b1.tar.gz
Algorithm Hash digest
SHA256 6095960cd6ef013b51269c31b366e4d05ab6f6c4a6af179913a5a7012f9589ab
MD5 5e85153a1cc0cc10f3a54f3d6f5fc4a0
BLAKE2b-256 826b1b70401d669955227a65091dd9e8b3bff7b010f88b07786aa5f27610330c

See more details on using hashes here.

File details

Details for the file iag_sdk-2023.12b1-py3-none-any.whl.

File metadata

  • Download URL: iag_sdk-2023.12b1-py3-none-any.whl
  • Upload date:
  • Size: 35.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for iag_sdk-2023.12b1-py3-none-any.whl
Algorithm Hash digest
SHA256 fe4bcb40ead1ea66f298a9939ba9892c8fb2dd4a67fdd347a4a101e146db2971
MD5 6827a7917281acc9bd5e71c4b49f27c3
BLAKE2b-256 d53a4fd6caa8cbe4741a6a29216bb28023b0ff8c9a278afc3289dae4649bbdf0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page