Package: iag-sdk
itential-iag-sdkLightweight SDK to simplify the process of 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 uses Pydantic models to validate the input parameters for each API call.This package was written for Itential Automation Gateway 2023.1.Getting StartedMake sure you have a supported version of Python installed and then create and activate a virtual environment:python-mvenvvenvsource/venv/bin/activateYou can install the iag_sdk from Pypi as follows:pipinstalliag-sdkOr you can install it from source as follows:gitclonehttps://github.com/awetomate/itential-iag-sdk.gitcditential-iag-sdk
python-mpipinstall-rrequirements.txt
python-mpipinstall-e.Usagefromiag_sdkimportIagusername="admin@itential"password="your_password"host="your_server"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:classIag(ClientBase):def__init__(self,host:str,username:str,password:str,base_url:Optional[str]="/api/v2.0",protocol:Optional[str]="http",port:Optional[Union[int,str]]=8083,verify:Optional[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 statusiag.system.get_status()# list the first 10 Ansible devices that have 'SW' in their hostnameiag.devices.get_devices(limit=10,filter='contains({"name": "SW"})')# get a specific Ansible deviceiag.devices.get_device(name="device1")# check the state for a specific Ansible deviceiag.devices.get_device_state(name="device1")Work with Ansible collections:# list all collectionsiag.collections.get_collections()# get one collectioniag.collections.get_collection(collection_name="cisco.asa")# get modules for a specific collectioniag.collections.get_modules(collection_name="cisco.asa")# refresh collections / perform a collection discoveryiag.collections.refresh()Work with Netmiko:# IAG nativeiag.netmiko.execute_send_command_native(host="device1",command_string="show version")# legacyiag.netmiko.execute_send_command_legacy(host="device1",commands=["show version"],device_type="cisco_ftd",username="your_username",password="your_password",port=22)The all-purpose 'query' methodThe 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.The 'query' method takes the following arguments:argumentdescriptionendpointItential IAG API endpoint. E.g. /devices.methodOptional. API method: get (default),post,put,patch,delete.dataOptional. A dictionary to send as the body.jsonbodyOptional. A JSON object to send as the body.paramsOptional. A dictionary to send as URL parameters.Basic GET call using 'query'# get the server statusiag.query("/status")# or to be more explicitiag.query("/status",method="get")# get a specific collectioncollection_name="cisco.asa"iag.query(f"collections/{collection_name}")# or define the endpoint staticallyiag.query("collections/cisco.asa")# list the first 10 Ansible devices that have 'SW' in their hostnameiag.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"})List of all modules and methodsaccountsmethodsdescriptionadd_accountAdd a new user account.confirm_eulaConfirm EULA for account.delete_accountDelete a user account.get_accountGet information for a user account.get_accountsGet a list of user accounts.update_accountUpdate details of a user account.update_passwordUpdate user login credentials.collectionsmethodsdescriptionadd_collectionInstall an Ansible collection from a Galaxy server or from a tarball.delete_module_schemaRemove a schema for a module in the Ansible collection.delete_role_schemaRemove a schema for a role in the Ansible collection.execute_moduleExecute a module contained within the Ansible collection.execute_roleExecute a role which is contained within the Ansible collection.get_collectionGet details for an Ansible collection.get_collectionsGet list of installed Ansible collections.get_moduleGet details for a module in the Ansible collection.get_module_historyGet execution log events for an Ansible collection module.get_module_schemaGet the schema for a module in the Ansible collection.get_modulesGet module list for an Ansible collection.get_roleGet details for a role in the Ansible collection.get_role_historyGet execution log events for an Ansible collection role.get_role_schemaGet the schema for a role in the Ansible collection.get_rolesGet role list for an Ansible collection.refreshPerform Ansible collection discovery and update internal cache.update_module_schemaUpdate/Insert a schema document for module in the Ansible collection.update_role_schemaUpdate/Insert a schema document for role in the Ansible collection.configmethodsdescriptionget_configFetch config value from AG server database.update_configUpdate config to AG server database.devicesmethodsdescriptionadd_deviceAdd a new device to Ansible inventory.delete_deviceDelete a device from Ansible inventory.get_deviceGet information for an Ansible device.get_device_stateGet the connectivity state for an Ansible device.get_device_variableGet the value of a connection variable for an Ansible device.get_device_variablesGet the connection variables for an Ansible device.get_devicesGet a list of Ansible devices.update_deviceMerge or replace the variables for a device in the Ansible inventory.groupsmethodsdescriptionadd_groupAdd a new Ansible device group.add_group_childrenAdd new child groups to an Ansible device group.add_group_devicesAdd new devices to an Ansible device group.delete_groupDelete an Ansible device group.delete_group_childDelete a child group from an Ansible device group.delete_group_deviceDelete a device from an Ansible device group.get_groupGet information for an Ansible device group.get_group_childrenGet a list of child groups for an Ansible device group.get_group_devicesGet the devices for an Ansible device group.get_group_variableGet the contents of a variable for an Ansible device group.get_group_variablesGet the variables for an Ansible device group.get_groupsGet a list of Ansible device groups.update_groupUpdate the variables in an Ansbile device group.http_requestsmethodsdescriptionexecute_requestSend an HTTP/1.1 request to an inventory device.get_request_historyGet execution log events for an HTTP request.get_request_schemaGet the json schema for http_requests' request endpoint.inventorymethodsdescriptionadd_http_requests_deviceCreate a device in the http_requests inventory.add_netconf_deviceCreate a device in the netconf inventory.add_netmiko_deviceCreate a device in the netmiko inventorydelete_http_requests_deviceDelete a device from the http_requests inventory.delete_netconf_deviceDelete a device from the netconf inventory.delete_netmiko_deviceDelete a device from the netmiko inventory.get_http_requests_deviceGet information for a device in the http_requests inventory.get_http_requests_device_groupGet information for a device group in the http_requests inventory.get_http_requests_device_group_childrenGet a list of child groups in the http_requests inventory device group.get_http_requests_device_group_devicesGet a list of devices in the http_requests inventory device group.get_http_requests_device_groupsGet a list of device groups in http_requests inventory.get_http_requests_devicesGet a list of devices in the http_requests inventory.get_netconf_deviceGet information for a device in the netconf inventory.get_netconf_device_groupGet information for a device group in the netconf inventory.get_netconf_device_group_childrenGet a list of child groups in the netconf inventory device group.get_netconf_device_group_devicesGet a list of devices in the netconf inventory device group.get_netconf_device_groupsGet a list of device groups in netconf inventory.get_netconf_devicesGet a list of devices in the netconf inventory.get_netmiko_deviceGet information for a device in the netmiko inventory.get_netmiko_device_groupGet information for a device group in the netmiko inventory.get_netmiko_device_group_childrenGet a list of child groups in the netmiko inventory device group.get_netmiko_device_group_devicesGet a list of devices in the netmiko inventory device group.get_netmiko_device_groupsGet a list of device groups in netmiko inventory.get_netmiko_devicesGet a list of devices in the netmiko inventory.refreshPerform external inventory discovery and update internal cache.update_http_requests_deviceUpdate a device in the http_requests inventory.update_netconf_deviceUpdate variables for a device in the netconf inventory.update_netmiko_deviceUpdate a device in the netmiko inventory.ldapmethodsdescriptiontest_bindtest LDAP connectionmodulesmethodsdescriptiondelete_module_schemaRemove an Ansible module schema.execute_moduleExecute an Ansible module.get_moduleGet information for an Ansible module.get_module_historyGet execution log events for an Ansible module.get_module_schemaGet the schema for an Ansible module.get_modulesGet a list of Ansible modules.refreshPerform Ansible module discovery and update internal cache.update_module_schemaUpdate/Insert an Ansible module schema document.netconfnetconfexecute_get_configRetrieve configuration from a device using the NETCONF protocolexecute_rpcExecute proprietary operations on a device using the NETCONF protocol.execute_set_configConfigure a device using the NETCONF protocolget_historyGet execution log events for Netconf command.netmikomethodsdescriptionexecute_send_command_legacyWrapper of netmiko send_commandexecute_send_command_nativeIAG Native Netmiko send_command.execute_send_config_set_legacyWrapper of netmiko send_config_setexecute_send_config_set_nativeIAG Native Netmiko send_config_set.get_command_schemaGet IAG Native Netmiko command schema.get_send_command_historyGet execution log events for the Netmiko send_command.get_send_config_set_historyGet execution log events for Netmiko send_config_set.nornirmethodsdescriptiondelete_module_schemaRemove a Nornir module schema.execute_moduleExecute a Nornir module.get_moduleGet Nornir module information.get_module_historyGet execution log events for a Nornir module.get_module_schemaGet the schema for a Nornir module.get_modulesGet a list of Nornir modules.refreshPerform Nornir module discovery and update internal cache.update_module_schemaUpdate/Insert a Nornir module schema document.password_resetmethodsdescriptionreset_passwordReset password for user on the AG server.update_change_flagUpdate the password change flag to false on the AG server.update_passwordUpdate password for user on the AG server.update_security_questionsUpdate security questions and answers for user on the AG server.validate_password_changeValidate if password is changed in the AG server.playbooksmethodsdescriptiondelete_playbook_schemaRemove an Ansible playbook schema.execute_playbookExecute an Ansible playbook.get_playbookGet information for an Ansible playbook.get_playbook_schemaGet the schema for an Ansible playbook.get_playbooksGet a list of Ansible playbooks.get_playook_historyGet execution log events for an Ansible playbook.refreshPerform Ansible playbook discovery and update internal cache.update_playbook_schemaUpdate/Insert an Ansible playbook schema document.pronghornmethodsdescriptionget_pronghornGet pronghorn.json for the AG server.rbacmethodsdescriptionadd_groupAdd a new RBAC groupadd_group_rolesAdd new roles to the RBAC group.add_group_usersAdd new users to the RBAC group.delete_groupDelete an RBAC group.delete_group_roleDelete a role from the RBAC group.delete_group_userDelete a user from the RBAC group.get_groupGet information for an RBAC group.get_group_rolesGet roles for an RBAC group.get_group_usersGet users for an RBAC group.get_groupsGet a list of RBAC groups.get_roleGet information for an RBAC role.get_rolesGet a list of RBAC roles.get_user_groupsGet RBAC group information for a user.get_user_rolesGet RBAC role information for a user.update_groupUpdate an RBAC group.rolesmethodsdescriptiondelete_role_schemaRemove an Ansible role schema.execute_roleExecute an Ansible role.get_roleGet information for an Ansible role.get_role_historyGet execution log events for an Ansible role.get_role_schemaGet the schema for an Ansible role.get_rolesGet a list of Ansible roles.refreshPerform Ansible role discovery and update internal cache.update_role_schemaUpdate/Insert an Ansible role schema document.scriptsmethodsdescriptiondelete_script_schemaRemove a script schema.execute_scriptExecute a script.get_scriptGet script information.get_script_historyGet execution log events for a script.get_script_schemaGet the schema for a script.get_scriptsGet a list of scripts.refreshPerform script discovery and update internal cache.update_script_schemaUpdate/Insert a script schema document.secretsmethodsdescriptionadd_secretAdd a new Hashicorp Vault secret.delete_secretDelete a Hashicorp Vault secret.get_secretGet a list of Hashicorp Vault secrets.update_secretUpdate a Hashicorpy Vault secret.security_questionsmethodsdescriptionget_security_questionsGet security questions for the AG server.get_security_questions_userGet security questions for email id on the AG server.validate_security_answers_userValidate security answers for email id on the AG server.systemmethodsdescriptionget_audit_logGet execution history payload.get_audit_logsRetrieve execution audit log persisted in the database.get_healthDetermine if AG server is up and running (/poll).get_openapi_specGet the current OpenAPI spec from the running instance of IAGget_statusGet the AG server status (version, ansible version, etc).terraformsmethodsdescriptiondelete_module_schemaRemove a Terraform module schema.execute_terraform_applyApply the configuration of a Terraform moduleexecute_terraform_destroyDestroy the resources of a Terraform module.execute_terraform_initInitialize the providers of a Terraform module.execute_terraform_planPlan the execution of a Terraform module.execute_terraform_validateValidate the configuration of a Terraform module.get_moduleGet information on a Terraform module.get_module_historyGet execution log events for a Terraform module.get_module_schemaGet the schema for a Terraform module.get_modulesGet list of Terraform modules.refreshPerform Terraform discovery and update internal cache.update_module_schemaUpdate/Insert a Terraform schema document.user_schemamethodsdescriptiondelete_schemaRemove a user schema.update_schemaUpdate/Insert a user schema document.