zerto-python-library
A Python library for interacting with the Zerto Virtual Manager (ZVM) API.
Overview
This library provides a comprehensive Python interface to manage and automate Zerto Virtual Replication operations. It includes functionality for:
- Managing Virtual Protection Groups (VPGs)
- Handling VM protection and recovery
- Managing checkpoints and recovery points
- Monitoring alerts and events
- Managing licenses
- Configuring service profiles
- Handling encryption detection
- Managing datastores and VRAs
- Working with server date/time settings
- Managing ZORGs (Zerto Organizations)
Installation
git clone https://github.com/your-repo/zerto-python-sdk.git
cd zerto-python-sdk
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
Dependencies
- requests
- urllib3
- logging
- json
- typing
Library Structure
The library is organized into several modules:
zvml/- Core library componentsalerts.py- Alert management and monitoringcheckpoints.py- Checkpoint operations and managementcommon.py- Common enums and utilitiesencryptiondetection.py- Encryption detection functionalitylicense.py- License managementlocalsite.py- Local site operationsrecovery_reports.py- Recovery reporting functionalityserver_date_time.py- Server time operationsservice_profiles.py- Service profile configurationtasks.py- Task management and monitoringvirtualization_sites.py- Site management operationsvpgs.py- VPG operations and managementvras.py- VRA deployment and managementzorgs.py- ZORG operations
Requirements
- Python 3.6+
- Zerto Virtual Replication environment
- Network access to ZVM server
- Keycloak authentication credentials
Getting Started
- Clone the repository
- Install required dependencies
- Configure your Zerto environment credentials
- Run the example scripts to understand basic operations
- Integrate the library into your automation workflows
Authentication
The library uses Keycloak authentication. You'll need:
- ZVM server address
- Client ID
- Client Secret (* KeyCloak)
- Optional: SSL verification settings
KeyCloak
In order to use api client you'll need:
- Login into ZVML keycloak UI. https://///auth
- Select zerto realm (Switch from Master to Zerto using left menu drop box)
- Click on "Clients" using the left menu
- Click on CreateClient button
- Fill in client id (will be used for authentication) and client name (logical), click next
- Enable the following options: "Client authentication", "Authorization", "Standard flow", "Direct access grants", "Implicit flow", "OAuth 2.0 Device Authorization Grant", click next, click save.
- Select "Service account roles" tab, click on "Assign Role" button, check mark "admin" (or another role), click on "Assign" button
- Select "Credentials" tab, copy "Client Secret"
- Use the combination of the created client id and the client secret for authntication in your code
Error Handling
The library includes comprehensive error handling and logging:
- Input validation
- Error status checking
- Detailed error messages
- Operation status logging
Examples
Each example script demonstrates specific functionality:
Alert Management
alerts_example.py - Simple alert monitoring and management (list, dismiss, undismiss):
python examples/alerts_example.py \
--zvm_address "192.168.111.20" \
--client_id "zerto-api" \
--client_secret "your-secret-here" \
--ignore_ssl
VPG Management with VMs
vpg_vms_example.py - VPG creation and VM management between VPGs:
python examples/vpg_vms_example.py \
--zvm_address "192.168.111.20" \
--client_id "zerto-api" \
--client_secret "your-secret-here" \
--ignore_ssl \
--vm1 "vm-name-1" \
--vm2 "vm-name-2"
VPG Failover Testing
vpg_failover_example.py - Complete VPG lifecycle including failover testing:
python examples/vpg_failover_example.py \
--zvm_address "192.168.111.20" \
--client_id "zerto-api" \
--client_secret "your-secret-here" \
--ignore_ssl
VRA Management
vras_example.py - Interactive VRA deployment and management:
python examples/vras_example.py \
--zvm_address "192.168.111.20" \
--client_id "zerto-api" \
--client_secret "your-secret-here" \
--ignore_ssl
ZORG Management
zorgs_example.py - ZORG information retrieval and management:
python examples/zorgs_example.py \
--zvm_address "192.168.111.20" \
--client_id "zerto-api" \
--client_secret "your-secret-here" \
--ignore_ssl
License Management
license_example.py - License information and management:
python examples/license_example.py \
--zvm_address "192.168.111.20" \
--client_id "zerto-api" \
--client_secret "your-secret-here" \
--ignore_ssl
Events Monitoring
events_example.py - Monitor and retrieve Zerto events:
python examples/events_example.py \
--zvm_address "192.168.111.20" \
--client_id "zerto-api" \
--client_secret "your-secret-here" \
--ignore_ssl
Encryption Detection (not operationa yet)
encryption_detection_example.py - Manage encryption detection settings:
python examples/encryption_detection_example.py \
--zvm_address "192.168.111.20" \
--client_id "zerto-api" \
--client_secret "your-secret-here" \
--ignore_ssl
Service Profiles
service_profiles_example.py - Manage service profiles:
python examples/service_profiles_example.py \
--zvm_address "192.168.111.20" \
--client_id "zerto-api" \
--client_secret "your-secret-here" \
--ignore_ssl
Volumes Management
volumes_example.py - Manage protected volumes:
python examples/volumes_example.py \
--zvm_address "192.168.111.20" \
--client_id "zerto-api" \
--client_secret "your-secret-here" \
--ignore_ssl
Server Date and Time example
server_date_time_example.py - Manage protected volumes:
python examples/server_date_time_example.py \
--zvm_address "192.168.111.20" \
--client_id "zerto-api" \
--client_secret "your-secret-here" \
--ignore_ssl
Datastore management example
datastore_example.py - Manage protected volumes:
python examples/datastore_example.py \
--zvm_address "192.168.111.20" \
--client_id "zerto-api" \
--client_secret "your-secret-here" \
--ignore_ssl
Localsite management
localsite_example.py - Manage protected volumes:
python examples/localsite_example.py \
--zvm_address "192.168.111.20" \
--client_id "zerto-api" \
--client_secret "your-secret-here" \
--ignore_ssl
python examples/peersites_example.py \
--site1_zvm_address <zvm1_address> \
--site1_client_id <client_id1> \
--site1_client_secret <secret1> \
--site2_zvm_address <zvm2_address> \
--site2_client_id <client_id2> \
--site2_client_secret <secret2> \
--ignore_ssl
python examples/tweaks_example.py \
--zvm_address <zvm_address> \
--client_id <client_id> \
--client_secret <client_secret> \
--ignore_ssl
Each example includes detailed comments explaining the functionality and demonstrates proper error handling and best practices for using the ZVML SDK.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project includes a legal disclaimer. See the header of each file for details.
For detailed API documentation and examples, please refer to the individual module files and example scripts.