# PySimpleNet
PySimpleNet is a powerful and lightweight network automation toolkit that allows you to efficiently automate complex network, IOT and other SSH operations using a simple and intuitive interface. This tool is designed with flexibility in mind, supporting various network devices and protocols.
## Key Features
- **YAML-Driven Configuration**: Easily define actions and workflows using YAML files.
- **CLI and GUI Tools**: Choose between command-line interface or graphical user interface based on your preference.
- **Device Drivers**: Support for multiple network device types (e.g., Cisco IOS).
- **Automation Actions**: Send commands, loop through commands, audit configurations, and more.
- **Extensible Schema**: Define custom actions and extend the existing schema as needed.
- **Concurrent Execution**: Run tasks across multiple devices concurrently to save time.
- **Data Persistence**: Use SQLite databases for inventory and device data management.
- **Visual YAML Editor**: Use the GUI editor to create and modify YAML configuration files easily.
- **Debugger Tool**: Visually debug and step through automation workflows.
## Screenshots
### Full Interface

### GUI Debug Mode

### TTP Parsing Example

### Inventory Management

### Linux Device Interface


---
# PySimpleNet
[](https://pypi.org/project/pysimplenet/)
[](https://www.gnu.org/licenses/gpl-3.0)
PySimpleNet is a powerful and lightweight network automation toolkit that allows you to efficiently automate complex network, IoT, REST API, and other SSH operations using a simple and intuitive interface. This tool is designed with flexibility in mind, supporting various network devices, protocols, and API interactions.
## Key Features
- **YAML-Driven Configuration**: Easily define actions and workflows using YAML files.
- **CLI and GUI Tools**: Choose between command-line interface or graphical user interface based on your preference.
- **Device Drivers**: Support for multiple network device types (e.g., Cisco IOS, Linux).
- **Automation Actions**: Send commands, loop through commands, audit configurations, make REST API calls, and more.
- **REST API Integration**: Automate interactions with RESTful APIs using `rest_api` and `rest_api_loop` actions.
- **Extensible Schema**: Define custom actions and extend the existing schema as needed.
- **Concurrent Execution**: Run tasks across multiple devices and APIs concurrently to save time.
- **Data Persistence**: Use SQLite databases for inventory and device data management.
- **Visual YAML Editor**: Use the GUI editor to create and modify YAML configuration files easily.
- **Debugger Tool**: Visually debug and step through automation workflows.
## Prerequisites
- Python 3.9 or higher
- Required Python packages (listed in `requirements.txt`)
- Access to network devices (e.g., Cisco IOS devices)
- SSH connectivity to target devices
- PyQt6 (for GUI tools)
- Access to RESTful APIs (if using REST API actions)
## Installation
You can install PySimpleNet via `pip`:
```bash
pip install pysimplenet
```
Alternatively, clone the repository and install:
```bash
git clone https://github.com/scottpeterman/pysimplenet.git
cd pysimplenet
pip install -r requirements.txt
```
## Usage
### Command-Line Interface (CLI)
#### Running Automation Tasks
Use the `simplenet-runner` command to execute automation tasks defined in your YAML driver files.
- Or runner.py if in development or running from source
```bash
simplenet-runner --inventory project/inventory/home_inventory.db --query "SELECT * FROM devices" --driver project/drivers/tests/cdp_interfaces_audit.yml
```
### Graphical User Interface (GUI)
#### Launching the Main GUI
```bash
simplenet-gui
```
#### Launching the Debugger GUI Tool
```bash
vsndebug
```
## Configuration
All configurations are done through YAML files. Below are sample configurations for both device interactions and REST API calls.
### Sample Driver Configuration for Device Interaction (`cdp_interfaces_audit.yml`)
```yaml
drivers:
cisco_ios:
error_string: "Invalid input detected"
output_path: "./output/{{ hostname }}_version_check.txt"
output_mode: "append"
prompt_count: 4
actions:
- action: "send_command"
display_name: "Set Terminal Length"
command: "term len 0"
expect: "#"
- action: "send_command"
display_name: "Show CDP Neighbors Detail"
command: "show cdp neighbors detail"
expect: "#"
output_path: "./output/{{ hostname }}_cdp_neighbors.txt"
output_mode: "overwrite"
ttp_path: "./project/templates/ios_show_cdp_neighbors.ttp"
store_query:
query: "[][]"
variable_name: "cdp_neighbors"
- action: "send_command_loop"
display_name: "Loop Through Interfaces"
variable_name: "cdp_neighbors"
key_to_loop: "interface"
command_template: "show interface [{ interface }]"
expect: "#"
output_path: "./output/{{ hostname }}_interface_details.txt"
output_mode: "append"
parse_output: true
use_named_list:
list_name: "interface_mtu"
item_key: "mtu"
ttp_path: "./project/templates/interface_mtu_switch.ttp"
store_query:
query: "[][]"
variable_name: "interface_mtu"
- action: "audit_loop"
display_name: "Check MTU for Interfaces with CDP Neighbors"
policy_name: "MTU Check for CDP Neighbors"
variable_name: "interface_mtu"
key_to_check: "interface"
target_value: "1500"
query: '"{{ hostname }}".action_variables.interface_mtu[*].mtu[*]'
pass_if:
- check_type: jmespath
key_to_check: mtu
name: Check if MTU is 1500 for CDP Neighbor Interfaces
operator:
type: is_equal
value: '1500'
query: mtu[*]
- action: "print_audit"
display_name: "CDP Neighbor MTU Audit"
output_file_path: "./output/{{ hostname }}_cdp_mtu_audit.yaml"
format: "both"
```
### Sample Driver Configuration for REST API Interaction (`rest_api_example.yml`)
```yaml
drivers:
flask_test:
error_string: "400" # Use a generic error code for failures
actions:
# 1. Action to log in and store the JWT token
- action: "rest_api"
display_name: "Login to Flask API"
method: "POST"
url: "http://127.0.0.1:5000/login"
verify: "false"
headers:
Content-Type: "application/json"
body:
username: "testuser"
password: "password123"
expect: "200"
store_query:
query: "access_token" # Retrieve the JWT token from the login response
variable_name: "jwt_token" # Store the token in the global data store
# 2. Action to retrieve all devices and store their IDs
- action: "rest_api"
display_name: "Get Device List"
method: "GET"
url: "http://127.0.0.1:5000/devices"
verify: "false"
headers:
Content-Type: "application/json"
Authorization: "Bearer action_variables.jwt_token" # Use the stored JWT token
expect: "200"
store_query:
query: "[]" # Store the list of devices
variable_name: "devices"
# 3. Loop action to retrieve each device separately
- action: "rest_api_loop"
display_name: "Retrieve Each Device"
method: "GET"
url: "http://127.0.0.1:5000/devices/[{ id }]" # The URL will dynamically use the device_id
verify: "false"
headers:
Content-Type: "application/json"
Authorization: "Bearer action_variables.jwt_token" # Use the stored JWT token
variable_name: "devices" # The global variable containing the devices
key_to_loop: "id" # Loop over the device IDs
expect: "200"
store_query:
query: "name" # Store the device name from each response
variable_name: "device_names"
output_path: "./output/device_details.json"
output_mode: "overwrite" # Overwrite the file for each new run
```
### Inventory File (`home_inventory.yaml`)
```yaml
devices:
- id: 1
hostname: "router1"
mgmt_ip: "192.168.1.1"
device_type: "cisco_ios"
credential_ids:
- 1
credentials:
- id: 1
username: "admin"
password: "password"
```
### Variables File (Optional)
Variables can be defined in YAML files located under `project/vars/`.
## Schema Explanation
The schema defines the structure of the YAML configuration files used by the automation tool.
### Actions
#### `rest_api`
Performs a REST API call.
- **Fields**:
- `display_name` (required): A friendly name for the action.
- `method` (required): HTTP method (`GET`, `POST`, `PUT`, `DELETE`, etc.).
- `url` (required): The API endpoint URL.
- `headers` (optional): HTTP headers to include in the request.
- `body` (optional): Data to send in the body of the request (for `POST`, `PUT`, etc.).
- `verify` (optional): SSL verification (`true` or `false`).
- `expect` (optional): Expected HTTP status code.
- `store_query` (optional): Stores data from the response into variables.
- **Fields**:
- `query`: The JMESPath query to extract data.
- `variable_name`: The name of the variable to store data.
#### `rest_api_loop`
Performs REST API calls in a loop based on variables.
- **Fields**:
- Same as `rest_api`, plus:
- `variable_name`: The variable to loop through.
- `key_to_loop`: The key within the variable to iterate over.
- `url` can include placeholders to be replaced with looped values.
### Existing Actions
- **`send_command`**: Sends a single command to the device.
- **`send_command_loop`**: Sends a command template in a loop based on variables.
- **`audit_loop`**: Audits configurations based on conditions.
- **`print_audit`**: Outputs the audit results.
## Components
The solution consists of several Python scripts and modules that work together to perform network automation tasks, including REST API interactions.
### 1. Runner Script (`simplenet/cli/runner.py`)
Orchestrates the overall automation process.
- **Functions**:
- `create_sqlite_db()`: Converts YAML inventory to SQLite database.
- `check_device_reachability()`: Verifies if devices are reachable.
- `run_for_device()`: Executes automation tasks for a single device.
- `main()`: Main Click command.
### 2. Simplenet Module (`simplenet/cli/simplenet.py`)
Handles the execution of automation tasks for individual devices and APIs.
- **Functions**:
- `run_automation_for_device()`: Runs automation tasks.
- `main()`: Main Click command for single-device automation.
### 3. Command Executor Library (`simplenet/cli/command_executor2.py`)
Executes individual actions defined in the driver, including REST API actions.
- **Functions**:
- `execute_commands()`: Main function to execute a list of actions.
- `handle_send_command_action()`: Handles `send_command` actions.
- `handle_send_command_loop()`: Handles `send_command_loop` actions.
- `handle_rest_api_action()`: Handles `rest_api` actions.
- `handle_rest_api_loop_action()`: Handles `rest_api_loop` actions.
- `handle_audit_action()`: Performs audit checks.
- `handle_print_audit_action()`: Outputs audit results.
### 4. GUI Editor Tool (`simplenet/gui/main_gui.py`)
A PyQt6-based application to create and modify YAML configuration files.
- **Usage**:
```bash
simplenet-gui
```
- **Features**:
- Visual YAML editing.
- Schema validation.
- Action management.
- YAML preview.
- File operations.
- Integration with the runner.
### 5. Debugger GUI Tool (`simplenet/gui/vsndebug.py`)
Visually debug and step through automation workflows.
- **Usage**:
```bash
vsndebug
```
- **Features**:
- Step-by-step execution.
- Variable inspection.
- Breakpoint setting.
- Output monitoring.
- Error handling.
## Examples
### Example: REST API Login and Data Retrieval
```yaml
- action: "rest_api"
display_name: "Login to API"
method: "POST"
url: "https://api.example.com/login"
headers:
Content-Type: "application/json"
body:
username: "user"
password: "pass"
expect: "200"
store_query:
query: "token"
variable_name: "api_token"
- action: "rest_api"
display_name: "Get Devices"
method: "GET"
url: "https://api.example.com/devices"
headers:
Authorization: "Bearer action_variables.api_token"
expect: "200"
store_query:
query: "devices"
variable_name: "devices"
- action: "rest_api_loop"
display_name: "Get Device Details"
method: "GET"
url: "https://api.example.com/devices/[{ id }]"
headers:
Authorization: "Bearer action_variables.api_token"
variable_name: "devices"
key_to_loop: "id"
expect: "200"
store_query:
query: "device_info"
variable_name: "device_details"
output_path: "./output/device_details.json"
output_mode: "append"
```
### Example: Sending a Command
```yaml
- action: "send_command"
display_name: "Check Device Version"
command: "show version"
expect: "#"
output_path: "./output/{{ hostname }}_version.txt"
output_mode: "overwrite"
```
### Example: Looping Through Interfaces
```yaml
- action: "send_command_loop"
display_name: "Collect Interface Details"
variable_name: "interfaces"
key_to_loop: "interface_name"
command_template: "show interface [{ interface_name }]"
expect: "#"
output_path: "./output/{{ hostname }}_interfaces.txt"
output_mode: "append"
parse_output: true
```
## Running the Automation Tool
1. **Prepare the YAML Configuration**
Use the GUI Editor or manually create your YAML configuration files under `project/drivers/`.
2. **Prepare the Inventory File**
Place your inventory YAML file under `project/inventory/`.
3. **Execute the Runner Script**
```bash
simplenet-runner --inventory project/inventory/home_inventory.db --query "SELECT * FROM devices" --driver project/drivers/tests/rest_api_example.yml
```
4. **View Outputs**
Check the `./output/` directory for command outputs, API responses, and audit results. Logs can be found in the `./` directory.
## License
This project is licensed under the [GNU General Public License v3.0](https://www.gnu.org/licenses/gpl-3.0.en.html).
## Additional Information
### Extending the Schema
You can add custom actions by extending the schema. For example, a `custom_action` allows you to define new behaviors.
### Code Structure and Workflow
The automation solution follows a modular approach, where each component plays a specific role in the overall workflow.
#### Workflow Overview
1. **Inventory Preparation**: Devices and credentials are defined in a YAML file.
2. **Database Creation**: The runner script converts the YAML inventory into a SQLite database.
3. **Device and API Interaction**: The runner script handles both device connections and API calls.
4. **Concurrent Execution**: The runner script executes tasks across multiple devices and APIs concurrently.
5. **Automation Execution**: For each device or API endpoint, the `simplenet` module executes the defined actions.
6. **Command and API Execution**: The `execute_commands` function processes each action.
7. **Data Storage**: Results are stored in the global data store.
8. **Reporting**: Audit results and outputs are saved to files.
9. **Debugging**: Use the Debugger GUI tool to step through workflows.
### Troubleshooting
- **Invalid Input Detected**: Ensure your commands and expectations match the device's responses.
- **Connection Timeouts**: Verify network connectivity and device/API accessibility.
- **Schema Validation Errors**: Make sure your YAML files conform to the defined schema.
- **Authentication Failures**: Confirm that credentials and tokens are correctly associated.
As of now, the tool primarily uses SSH for device communication and HTTP/S for API interactions. Support for other protocols can be added by extending the action handlers.
---
Raw data
{
"_id": null,
"home_page": "https://github.com/scottpeterman/pysimplenet",
"name": "pysimplenet",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": null,
"author": "Scott Peterman",
"author_email": "scottpeterman@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/e9/f4/d503408752a52b8c7c9064aca7d8d1e116adda6784661f02c2a50fdf4bd3/pysimplenet-0.1.4.tar.gz",
"platform": null,
"description": "# PySimpleNet\r\n\r\nPySimpleNet is a powerful and lightweight network automation toolkit that allows you to efficiently automate complex network, IOT and other SSH operations using a simple and intuitive interface. This tool is designed with flexibility in mind, supporting various network devices and protocols.\r\n\r\n## Key Features\r\n\r\n- **YAML-Driven Configuration**: Easily define actions and workflows using YAML files.\r\n- **CLI and GUI Tools**: Choose between command-line interface or graphical user interface based on your preference.\r\n- **Device Drivers**: Support for multiple network device types (e.g., Cisco IOS).\r\n- **Automation Actions**: Send commands, loop through commands, audit configurations, and more.\r\n- **Extensible Schema**: Define custom actions and extend the existing schema as needed.\r\n- **Concurrent Execution**: Run tasks across multiple devices concurrently to save time.\r\n- **Data Persistence**: Use SQLite databases for inventory and device data management.\r\n- **Visual YAML Editor**: Use the GUI editor to create and modify YAML configuration files easily.\r\n- **Debugger Tool**: Visually debug and step through automation workflows.\r\n\r\n## Screenshots\r\n\r\n### Full Interface\r\n\r\n\r\n### GUI Debug Mode\r\n\r\n\r\n### TTP Parsing Example\r\n\r\n\r\n### Inventory Management\r\n\r\n\r\n### Linux Device Interface\r\n\r\n\r\n\r\n---\r\n\r\n# PySimpleNet\r\n\r\n[](https://pypi.org/project/pysimplenet/)\r\n[](https://www.gnu.org/licenses/gpl-3.0)\r\n\r\nPySimpleNet is a powerful and lightweight network automation toolkit that allows you to efficiently automate complex network, IoT, REST API, and other SSH operations using a simple and intuitive interface. This tool is designed with flexibility in mind, supporting various network devices, protocols, and API interactions.\r\n\r\n## Key Features\r\n\r\n- **YAML-Driven Configuration**: Easily define actions and workflows using YAML files.\r\n- **CLI and GUI Tools**: Choose between command-line interface or graphical user interface based on your preference.\r\n- **Device Drivers**: Support for multiple network device types (e.g., Cisco IOS, Linux).\r\n- **Automation Actions**: Send commands, loop through commands, audit configurations, make REST API calls, and more.\r\n- **REST API Integration**: Automate interactions with RESTful APIs using `rest_api` and `rest_api_loop` actions.\r\n- **Extensible Schema**: Define custom actions and extend the existing schema as needed.\r\n- **Concurrent Execution**: Run tasks across multiple devices and APIs concurrently to save time.\r\n- **Data Persistence**: Use SQLite databases for inventory and device data management.\r\n- **Visual YAML Editor**: Use the GUI editor to create and modify YAML configuration files easily.\r\n- **Debugger Tool**: Visually debug and step through automation workflows.\r\n\r\n## Prerequisites\r\n\r\n- Python 3.9 or higher\r\n- Required Python packages (listed in `requirements.txt`)\r\n- Access to network devices (e.g., Cisco IOS devices)\r\n- SSH connectivity to target devices\r\n- PyQt6 (for GUI tools)\r\n- Access to RESTful APIs (if using REST API actions)\r\n\r\n## Installation\r\n\r\nYou can install PySimpleNet via `pip`:\r\n\r\n```bash\r\npip install pysimplenet\r\n```\r\n\r\nAlternatively, clone the repository and install:\r\n\r\n```bash\r\ngit clone https://github.com/scottpeterman/pysimplenet.git\r\ncd pysimplenet\r\npip install -r requirements.txt\r\n```\r\n\r\n## Usage\r\n\r\n### Command-Line Interface (CLI)\r\n\r\n#### Running Automation Tasks\r\n\r\nUse the `simplenet-runner` command to execute automation tasks defined in your YAML driver files.\r\n- Or runner.py if in development or running from source\r\n```bash\r\nsimplenet-runner --inventory project/inventory/home_inventory.db --query \"SELECT * FROM devices\" --driver project/drivers/tests/cdp_interfaces_audit.yml\r\n```\r\n\r\n### Graphical User Interface (GUI)\r\n\r\n#### Launching the Main GUI\r\n\r\n```bash\r\nsimplenet-gui\r\n```\r\n\r\n#### Launching the Debugger GUI Tool\r\n\r\n```bash\r\nvsndebug\r\n```\r\n\r\n## Configuration\r\n\r\nAll configurations are done through YAML files. Below are sample configurations for both device interactions and REST API calls.\r\n\r\n### Sample Driver Configuration for Device Interaction (`cdp_interfaces_audit.yml`)\r\n\r\n```yaml\r\ndrivers:\r\n cisco_ios:\r\n error_string: \"Invalid input detected\"\r\n output_path: \"./output/{{ hostname }}_version_check.txt\"\r\n output_mode: \"append\"\r\n prompt_count: 4\r\n actions:\r\n - action: \"send_command\"\r\n display_name: \"Set Terminal Length\"\r\n command: \"term len 0\"\r\n expect: \"#\"\r\n - action: \"send_command\"\r\n display_name: \"Show CDP Neighbors Detail\"\r\n command: \"show cdp neighbors detail\"\r\n expect: \"#\"\r\n output_path: \"./output/{{ hostname }}_cdp_neighbors.txt\"\r\n output_mode: \"overwrite\"\r\n ttp_path: \"./project/templates/ios_show_cdp_neighbors.ttp\"\r\n store_query:\r\n query: \"[][]\"\r\n variable_name: \"cdp_neighbors\"\r\n - action: \"send_command_loop\"\r\n display_name: \"Loop Through Interfaces\"\r\n variable_name: \"cdp_neighbors\"\r\n key_to_loop: \"interface\"\r\n command_template: \"show interface [{ interface }]\"\r\n expect: \"#\"\r\n output_path: \"./output/{{ hostname }}_interface_details.txt\"\r\n output_mode: \"append\"\r\n parse_output: true\r\n use_named_list:\r\n list_name: \"interface_mtu\"\r\n item_key: \"mtu\"\r\n ttp_path: \"./project/templates/interface_mtu_switch.ttp\"\r\n store_query:\r\n query: \"[][]\"\r\n variable_name: \"interface_mtu\"\r\n - action: \"audit_loop\"\r\n display_name: \"Check MTU for Interfaces with CDP Neighbors\"\r\n policy_name: \"MTU Check for CDP Neighbors\"\r\n variable_name: \"interface_mtu\"\r\n key_to_check: \"interface\"\r\n target_value: \"1500\"\r\n query: '\"{{ hostname }}\".action_variables.interface_mtu[*].mtu[*]'\r\n pass_if:\r\n - check_type: jmespath\r\n key_to_check: mtu\r\n name: Check if MTU is 1500 for CDP Neighbor Interfaces\r\n operator:\r\n type: is_equal\r\n value: '1500'\r\n query: mtu[*]\r\n - action: \"print_audit\"\r\n display_name: \"CDP Neighbor MTU Audit\"\r\n output_file_path: \"./output/{{ hostname }}_cdp_mtu_audit.yaml\"\r\n format: \"both\"\r\n```\r\n\r\n### Sample Driver Configuration for REST API Interaction (`rest_api_example.yml`)\r\n\r\n```yaml\r\ndrivers:\r\n flask_test:\r\n error_string: \"400\" # Use a generic error code for failures\r\n actions:\r\n # 1. Action to log in and store the JWT token\r\n - action: \"rest_api\"\r\n display_name: \"Login to Flask API\"\r\n method: \"POST\"\r\n url: \"http://127.0.0.1:5000/login\"\r\n verify: \"false\"\r\n headers:\r\n Content-Type: \"application/json\"\r\n body:\r\n username: \"testuser\"\r\n password: \"password123\"\r\n expect: \"200\"\r\n store_query:\r\n query: \"access_token\" # Retrieve the JWT token from the login response\r\n variable_name: \"jwt_token\" # Store the token in the global data store\r\n\r\n # 2. Action to retrieve all devices and store their IDs\r\n - action: \"rest_api\"\r\n display_name: \"Get Device List\"\r\n method: \"GET\"\r\n url: \"http://127.0.0.1:5000/devices\"\r\n verify: \"false\"\r\n headers:\r\n Content-Type: \"application/json\"\r\n Authorization: \"Bearer action_variables.jwt_token\" # Use the stored JWT token\r\n expect: \"200\"\r\n store_query:\r\n query: \"[]\" # Store the list of devices\r\n variable_name: \"devices\"\r\n\r\n # 3. Loop action to retrieve each device separately\r\n - action: \"rest_api_loop\"\r\n display_name: \"Retrieve Each Device\"\r\n method: \"GET\"\r\n url: \"http://127.0.0.1:5000/devices/[{ id }]\" # The URL will dynamically use the device_id\r\n verify: \"false\"\r\n headers:\r\n Content-Type: \"application/json\"\r\n Authorization: \"Bearer action_variables.jwt_token\" # Use the stored JWT token\r\n variable_name: \"devices\" # The global variable containing the devices\r\n key_to_loop: \"id\" # Loop over the device IDs\r\n expect: \"200\"\r\n store_query:\r\n query: \"name\" # Store the device name from each response\r\n variable_name: \"device_names\"\r\n output_path: \"./output/device_details.json\"\r\n output_mode: \"overwrite\" # Overwrite the file for each new run\r\n```\r\n\r\n### Inventory File (`home_inventory.yaml`)\r\n\r\n```yaml\r\ndevices:\r\n - id: 1\r\n hostname: \"router1\"\r\n mgmt_ip: \"192.168.1.1\"\r\n device_type: \"cisco_ios\"\r\n credential_ids:\r\n - 1\r\ncredentials:\r\n - id: 1\r\n username: \"admin\"\r\n password: \"password\"\r\n```\r\n\r\n### Variables File (Optional)\r\n\r\nVariables can be defined in YAML files located under `project/vars/`.\r\n\r\n## Schema Explanation\r\n\r\nThe schema defines the structure of the YAML configuration files used by the automation tool.\r\n\r\n### Actions\r\n\r\n#### `rest_api`\r\n\r\nPerforms a REST API call.\r\n\r\n- **Fields**:\r\n - `display_name` (required): A friendly name for the action.\r\n - `method` (required): HTTP method (`GET`, `POST`, `PUT`, `DELETE`, etc.).\r\n - `url` (required): The API endpoint URL.\r\n - `headers` (optional): HTTP headers to include in the request.\r\n - `body` (optional): Data to send in the body of the request (for `POST`, `PUT`, etc.).\r\n - `verify` (optional): SSL verification (`true` or `false`).\r\n - `expect` (optional): Expected HTTP status code.\r\n - `store_query` (optional): Stores data from the response into variables.\r\n - **Fields**:\r\n - `query`: The JMESPath query to extract data.\r\n - `variable_name`: The name of the variable to store data.\r\n\r\n#### `rest_api_loop`\r\n\r\nPerforms REST API calls in a loop based on variables.\r\n\r\n- **Fields**:\r\n - Same as `rest_api`, plus:\r\n - `variable_name`: The variable to loop through.\r\n - `key_to_loop`: The key within the variable to iterate over.\r\n - `url` can include placeholders to be replaced with looped values.\r\n\r\n### Existing Actions\r\n\r\n- **`send_command`**: Sends a single command to the device.\r\n- **`send_command_loop`**: Sends a command template in a loop based on variables.\r\n- **`audit_loop`**: Audits configurations based on conditions.\r\n- **`print_audit`**: Outputs the audit results.\r\n\r\n## Components\r\n\r\nThe solution consists of several Python scripts and modules that work together to perform network automation tasks, including REST API interactions.\r\n\r\n### 1. Runner Script (`simplenet/cli/runner.py`)\r\n\r\nOrchestrates the overall automation process.\r\n\r\n- **Functions**:\r\n - `create_sqlite_db()`: Converts YAML inventory to SQLite database.\r\n - `check_device_reachability()`: Verifies if devices are reachable.\r\n - `run_for_device()`: Executes automation tasks for a single device.\r\n - `main()`: Main Click command.\r\n\r\n### 2. Simplenet Module (`simplenet/cli/simplenet.py`)\r\n\r\nHandles the execution of automation tasks for individual devices and APIs.\r\n\r\n- **Functions**:\r\n - `run_automation_for_device()`: Runs automation tasks.\r\n - `main()`: Main Click command for single-device automation.\r\n\r\n### 3. Command Executor Library (`simplenet/cli/command_executor2.py`)\r\n\r\nExecutes individual actions defined in the driver, including REST API actions.\r\n\r\n- **Functions**:\r\n - `execute_commands()`: Main function to execute a list of actions.\r\n - `handle_send_command_action()`: Handles `send_command` actions.\r\n - `handle_send_command_loop()`: Handles `send_command_loop` actions.\r\n - `handle_rest_api_action()`: Handles `rest_api` actions.\r\n - `handle_rest_api_loop_action()`: Handles `rest_api_loop` actions.\r\n - `handle_audit_action()`: Performs audit checks.\r\n - `handle_print_audit_action()`: Outputs audit results.\r\n\r\n### 4. GUI Editor Tool (`simplenet/gui/main_gui.py`)\r\n\r\nA PyQt6-based application to create and modify YAML configuration files.\r\n\r\n- **Usage**:\r\n\r\n ```bash\r\n simplenet-gui\r\n ```\r\n\r\n- **Features**:\r\n - Visual YAML editing.\r\n - Schema validation.\r\n - Action management.\r\n - YAML preview.\r\n - File operations.\r\n - Integration with the runner.\r\n\r\n### 5. Debugger GUI Tool (`simplenet/gui/vsndebug.py`)\r\n\r\nVisually debug and step through automation workflows.\r\n\r\n- **Usage**:\r\n\r\n ```bash\r\n vsndebug\r\n ```\r\n\r\n- **Features**:\r\n - Step-by-step execution.\r\n - Variable inspection.\r\n - Breakpoint setting.\r\n - Output monitoring.\r\n - Error handling.\r\n\r\n## Examples\r\n\r\n### Example: REST API Login and Data Retrieval\r\n\r\n```yaml\r\n- action: \"rest_api\"\r\n display_name: \"Login to API\"\r\n method: \"POST\"\r\n url: \"https://api.example.com/login\"\r\n headers:\r\n Content-Type: \"application/json\"\r\n body:\r\n username: \"user\"\r\n password: \"pass\"\r\n expect: \"200\"\r\n store_query:\r\n query: \"token\"\r\n variable_name: \"api_token\"\r\n\r\n- action: \"rest_api\"\r\n display_name: \"Get Devices\"\r\n method: \"GET\"\r\n url: \"https://api.example.com/devices\"\r\n headers:\r\n Authorization: \"Bearer action_variables.api_token\"\r\n expect: \"200\"\r\n store_query:\r\n query: \"devices\"\r\n variable_name: \"devices\"\r\n\r\n- action: \"rest_api_loop\"\r\n display_name: \"Get Device Details\"\r\n method: \"GET\"\r\n url: \"https://api.example.com/devices/[{ id }]\"\r\n headers:\r\n Authorization: \"Bearer action_variables.api_token\"\r\n variable_name: \"devices\"\r\n key_to_loop: \"id\"\r\n expect: \"200\"\r\n store_query:\r\n query: \"device_info\"\r\n variable_name: \"device_details\"\r\n output_path: \"./output/device_details.json\"\r\n output_mode: \"append\"\r\n```\r\n\r\n### Example: Sending a Command\r\n\r\n```yaml\r\n- action: \"send_command\"\r\n display_name: \"Check Device Version\"\r\n command: \"show version\"\r\n expect: \"#\"\r\n output_path: \"./output/{{ hostname }}_version.txt\"\r\n output_mode: \"overwrite\"\r\n```\r\n\r\n### Example: Looping Through Interfaces\r\n\r\n```yaml\r\n- action: \"send_command_loop\"\r\n display_name: \"Collect Interface Details\"\r\n variable_name: \"interfaces\"\r\n key_to_loop: \"interface_name\"\r\n command_template: \"show interface [{ interface_name }]\"\r\n expect: \"#\"\r\n output_path: \"./output/{{ hostname }}_interfaces.txt\"\r\n output_mode: \"append\"\r\n parse_output: true\r\n```\r\n\r\n## Running the Automation Tool\r\n\r\n1. **Prepare the YAML Configuration**\r\n\r\n Use the GUI Editor or manually create your YAML configuration files under `project/drivers/`.\r\n\r\n2. **Prepare the Inventory File**\r\n\r\n Place your inventory YAML file under `project/inventory/`.\r\n\r\n3. **Execute the Runner Script**\r\n\r\n ```bash\r\n simplenet-runner --inventory project/inventory/home_inventory.db --query \"SELECT * FROM devices\" --driver project/drivers/tests/rest_api_example.yml\r\n ```\r\n\r\n4. **View Outputs**\r\n\r\n Check the `./output/` directory for command outputs, API responses, and audit results. Logs can be found in the `./` directory.\r\n\r\n## License\r\n\r\nThis project is licensed under the [GNU General Public License v3.0](https://www.gnu.org/licenses/gpl-3.0.en.html).\r\n\r\n## Additional Information\r\n\r\n### Extending the Schema\r\n\r\nYou can add custom actions by extending the schema. For example, a `custom_action` allows you to define new behaviors.\r\n\r\n### Code Structure and Workflow\r\n\r\nThe automation solution follows a modular approach, where each component plays a specific role in the overall workflow.\r\n\r\n#### Workflow Overview\r\n\r\n1. **Inventory Preparation**: Devices and credentials are defined in a YAML file.\r\n2. **Database Creation**: The runner script converts the YAML inventory into a SQLite database.\r\n3. **Device and API Interaction**: The runner script handles both device connections and API calls.\r\n4. **Concurrent Execution**: The runner script executes tasks across multiple devices and APIs concurrently.\r\n5. **Automation Execution**: For each device or API endpoint, the `simplenet` module executes the defined actions.\r\n6. **Command and API Execution**: The `execute_commands` function processes each action.\r\n7. **Data Storage**: Results are stored in the global data store.\r\n8. **Reporting**: Audit results and outputs are saved to files.\r\n9. **Debugging**: Use the Debugger GUI tool to step through workflows.\r\n\r\n\r\n### Troubleshooting\r\n\r\n- **Invalid Input Detected**: Ensure your commands and expectations match the device's responses.\r\n- **Connection Timeouts**: Verify network connectivity and device/API accessibility.\r\n- **Schema Validation Errors**: Make sure your YAML files conform to the defined schema.\r\n- **Authentication Failures**: Confirm that credentials and tokens are correctly associated.\r\n\r\nAs of now, the tool primarily uses SSH for device communication and HTTP/S for API interactions. Support for other protocols can be added by extending the action handlers.\r\n\r\n---\r\n\r\n",
"bugtrack_url": null,
"license": "GPLv3",
"summary": "Pysimplenet, automation tools for network engineers",
"version": "0.1.4",
"project_urls": {
"Homepage": "https://github.com/scottpeterman/pysimplenet"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "806dd63f03aadd4dde0128ccaa1f1537739282edc20ba61ada04bb6c403d7cf6",
"md5": "217896e88aebbffa4f21396e8c45b0fb",
"sha256": "a5b9fd8a448c5fff4bec618b32830b6f02ae63f61b11779fd3478fc12307d7eb"
},
"downloads": -1,
"filename": "pysimplenet-0.1.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "217896e88aebbffa4f21396e8c45b0fb",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 3150462,
"upload_time": "2024-09-24T04:47:41",
"upload_time_iso_8601": "2024-09-24T04:47:41.559967Z",
"url": "https://files.pythonhosted.org/packages/80/6d/d63f03aadd4dde0128ccaa1f1537739282edc20ba61ada04bb6c403d7cf6/pysimplenet-0.1.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e9f4d503408752a52b8c7c9064aca7d8d1e116adda6784661f02c2a50fdf4bd3",
"md5": "0f4debd010ccf0d433584cc1d37029a6",
"sha256": "095b85cee9c73d7d98400cde56eef699a865ccc1de8715136de070b94320a433"
},
"downloads": -1,
"filename": "pysimplenet-0.1.4.tar.gz",
"has_sig": false,
"md5_digest": "0f4debd010ccf0d433584cc1d37029a6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 3111999,
"upload_time": "2024-09-24T04:47:45",
"upload_time_iso_8601": "2024-09-24T04:47:45.698408Z",
"url": "https://files.pythonhosted.org/packages/e9/f4/d503408752a52b8c7c9064aca7d8d1e116adda6784661f02c2a50fdf4bd3/pysimplenet-0.1.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-24 04:47:45",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "scottpeterman",
"github_project": "pysimplenet",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "pysimplenet"
}