Plugins Function in InfraSet
Welcome to the Plugins Function user guide. This guide provides a comprehensive overview of how to validate, store, install, and execute plugins under the InfraSet functionality. The plugin feature enables extending the capabilities of your InfraSet setup through user-defined or prebuilt plugins.
Key Features of the Plugins Function
- Validation of Plugin Structure: Ensures plugins follow a required structure (e.g., main.py, requirements.txt).
- Storage of Plugins: Stores plugins securely in a designated plugin directory.
- Plugin Installation: Installs dependencies, validates plugins, and compiles them into executables.
- Dynamic Execution: Executes plugins with dynamic parameters and cloud credentials.
- Cloud Provider Integration: Supports AWS, GCP, and Azure cloud environments with seamless credential handling.
Plugin Workflow
- Validate Plugin: Ensure the plugin zip file includes the required files.
- Store Plugin: Place the plugin in the designated plugin directory for future use.
- Install Plugin: Extract and compile the plugin into a standalone executable using PyInstaller.
- Execute Plugin: Dynamically run the plugin with parameters and cloud credentials.
Declarative YAML Configuration for Plugins
Example: Declaring a Plugin in YAML
plugin_management:
enabled: true
plugins:
- name: "example-plugin"
path: "/path/to/example-plugin.zip"
Execution
dob infraset screenplay /path/to/infraset.yaml
Imperative CLI Commands for Plugins
Validate Plugin Structure
Command:
validate_plugin_structure(plugin_zip_path)
Description: Ensures that the plugin zip file contains the required files, such as main.py.
Output: Returns True if valid; otherwise, prints the missing files and returns False.
Store Plugin
Command:
store_plugin(plugin_name, plugin_path)
Description: Validates and stores a plugin in the plugin directory.
Arguments:
plugin_name
: The name of the plugin.plugin_path
: Path to the plugin zip file.
Example:
store_plugin("example-plugin", "/path/to/example-plugin.zip")
Install Plugin
Command:
install_plugin(plugin_name, plugin_zip_path)
Description: Extracts the plugin, installs dependencies, and compiles it into an executable.
Arguments:
plugin_name
: Name of the plugin.plugin_zip_path
: Path to the plugin zip file.
Example:
install_plugin("example-plugin", "/path/to/example-plugin.zip")
Execute Plugin
Command:
execute_plugin(plugin_path, parameters, provider)
Description: Executes the plugin binary or script with dynamic parameters and credentials.
Arguments:
plugin_path
: Path to the plugin executable or script.parameters
: Dictionary of parameters to pass to the plugin.provider
: Cloud provider (aws, gcp, or azure).
Example:
execute_plugin(
plugin_path="/path/to/example-plugin",
parameters={"action": "create", "resource_type": "vm"},
provider="gcp"
)
Best Practices
- Validate Plugin Structure: Use
validate_plugin_structure
to ensure plugins adhere to the required structure before storage or execution. - Secure Plugin Directory: Protect the
PLUGIN_DIRECTORY
to avoid unauthorized modifications. - Handle Credentials Carefully: Use encrypted credentials where possible and avoid hardcoding sensitive information.
- Test Plugins: Test plugins locally before deploying them in a production environment.
- Monitor Plugin Output: Review plugin logs and outputs for errors or unexpected behaviors.
Error Handling and Debugging
- Invalid Zip File:
- Error: "Invalid zip file."
- Solution: Ensure the plugin zip file is valid and contains all required files.
- Missing Required Files:
- Error: "Missing required file: main.py."
- Solution: Add the required files to the plugin zip.
- PyInstaller Compilation Errors:
- Error: "PyInstaller failed."
- Solution: Check the requirements.txt for any missing dependencies and ensure all imports are handled.
- Execution Errors:
- Error: "Plugin execution failed with exit code X."
- Solution: Review the plugin code and ensure the provided parameters are valid.
- Credentials Issues:
- Error: "Failed to load credentials for provider."
- Solution: Verify cloud credentials and ensure they are correctly set in the environment.
Conclusion
The Plugins Function in InfraSet is a powerful feature for extending the capabilities of your infrastructure setup. By supporting validation, installation, and execution, it provides a structured approach to managing plugins. Whether you’re creating custom plugins or integrating third-party solutions, this guide ensures a seamless experience.