initial commit

This commit is contained in:
Kosta Mushkin
2025-05-22 10:10:15 -04:00
commit 3a075e5ecf
28 changed files with 1729 additions and 0 deletions
+57
View File
@@ -0,0 +1,57 @@
# Exercise 4: Resource Discovery
## Overview
This exercise focuses on discovering and working with resources in your Zerto environment. You'll learn how to find VMs in your local site and discover various resources (datastores, hosts, folders, networks) in peer sites.
## Objectives
- Discover local site VMs
- Work with peer site resources:
- Datastores
- Hosts
- Folders
- Networks
- Handle site identifiers properly
- Use JSON for data display
## Time
15 minutes
## Prerequisites
- Completed Exercise 3 (Site Discovery)
- Working site discovery
- Access to site resources
## Exercise Steps
1. Connect to ZVM
2. Identify local and peer sites
3. Discover local site VMs
4. Get peer site resources:
- Datastores
- Hosts
- Folders
- Networks
## Working Directory
The `working` directory contains:
- `resources.py` - Template to complete
## Solution
The `solution` directory contains:
- `resources.py` - Complete working example
## Key Concepts
- Site resource discovery
- Local vs peer site resources
- Resource types (VMs, datastores, hosts, folders, networks)
- JSON data handling
- Error handling
## Common Issues
- No sites found
- Invalid site identifiers
- Authentication issues
- Connection problems
- Resource access issues
## Next Steps
Proceed to Exercise 5: VPG Management to learn about protecting VMs.
@@ -0,0 +1,125 @@
#!/usr/bin/env python3
"""
Exercise 4: Resource Discovery - Solution
This script demonstrates how to discover and work with resources in your Zerto environment.
Prerequisites:
1. Install the zvml package in development mode:
cd /path/to/zvml-python-sdk
pip install -e .
2. Update prerequisites/config.py with your ZVM details
This solution demonstrates:
- Discovering local site resources (clusters, hosts, datastores)
- Working with peer site resources
- Proper error handling and logging
"""
import sys
import os
import logging
import json
from pathlib import Path
# Add prerequisites to Python path
prerequisites_path = Path(__file__).parent.parent.parent.parent / "prerequisites"
sys.path.append(str(prerequisites_path))
# Import the SDK modules
from zvml import ZVMLClient
# Import configuration
try:
from config import (
ZVM_HOST,
ZVM_PORT,
ZVM_SSL_VERIFY,
CLIENT_ID,
CLIENT_SECRET
)
except ImportError:
print("Error: Please copy config.example.py to config.py and update with your values")
print("Expected path:", prerequisites_path / "config.py")
sys.exit(1)
def main():
"""
Main function to demonstrate resource discovery.
Shows how to:
1. Discover local site resources
2. Work with peer site resources
"""
# Set up logging with timestamp
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)
try:
# Step 1: Create a ZVMLClient instance
logging.info(f"Initializing ZVMLClient for ZVM at {ZVM_HOST}")
client = ZVMLClient(
zvm_address=ZVM_HOST,
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
verify_certificate=ZVM_SSL_VERIFY
)
# Step 2: Identify local and peer sites
# Step 2.1: List all available sites
logging.info("Retrieving list of available sites...")
sites = client.virtualization_sites.get_virtualization_sites()
if not sites:
logging.warning("No sites found!")
else:
logging.info(f"Found {len(sites)} site(s):")
logging.info(f'Sites Info: {json.dumps(sites, indent=4)}')
# Step 2.2: Get local and peer site Identifiers
local_site_identifier = client.localsite.get_local_site().get('SiteIdentifier')
logging.info(f"Local site identifier: {local_site_identifier}")
# Get peer site identifier (first non-local site)
peer_site = next((site for site in sites if site.get('SiteIdentifier') != local_site_identifier), None)
if not peer_site:
logging.warning("No peer site found!")
sys.exit(1)
peer_site_identifier = peer_site.get('SiteIdentifier')
logging.info(f"Peer site identifier: {peer_site_identifier}")
# Step 3: Get local site resources
# Step 3.1: Get local site vms
logging.info("\nRetrieving local site vms...")
local_vms = client.virtualization_sites.get_virtualization_site_vms(site_identifier=local_site_identifier)
logging.info(f"Local Vms Info: {json.dumps(local_vms, indent=4)}")
# in order to create a DR solution, we need to get information about the local site vms and peer site datastores, hosts, folders and networks
# Step 3.2: Get peer site datastores
logging.info("\nRetrieving peer site datastores...")
peer_datastores = client.virtualization_sites.get_virtualization_site_datastores(site_identifier=peer_site_identifier)
logging.info(f"Peer Datastores Info: {json.dumps(peer_datastores, indent=4)}")
# Step 3.3: Get peer site hosts
logging.info("\nRetrieving peer site hosts...")
peer_hosts = client.virtualization_sites.get_virtualization_site_hosts(site_identifier=peer_site_identifier)
logging.info(f"Peer Hosts Info: {json.dumps(peer_hosts, indent=4)}")
# Step 3.4: Get peer site folders
logging.info("\nRetrieving peer site folders...")
peer_folders = client.virtualization_sites.get_virtualization_site_folders(site_identifier=peer_site_identifier)
logging.info(f"Peer Folders Info: {json.dumps(peer_folders, indent=4)}")
# Step 3.5: Get peer site networks
logging.info("\nRetrieving peer site networks...")
peer_networks = client.virtualization_sites.get_virtualization_site_networks(site_identifier=peer_site_identifier)
logging.info(f"Peer Networks Info: {json.dumps(peer_networks, indent=4)}")
except Exception as e:
logging.error(f"Resource discovery failed: {str(e)}")
sys.exit(1)
if __name__ == "__main__":
main()
@@ -0,0 +1,127 @@
#!/usr/bin/env python3
"""
Exercise 4: Resource Discovery
This script demonstrates how to discover and work with resources in your Zerto environment.
Prerequisites:
1. Install the zvml package in development mode:
cd /path/to/zvml-python-sdk
pip install -e .
2. Update prerequisites/config.py with your ZVM details
Your task:
1. Discover local site resources (VMs)
2. Work with peer site resources (datastores, hosts, folders, networks)
If you need help, check the solution in the solution directory.
"""
import sys
import os
import logging
import json
from pathlib import Path
# Add prerequisites to Python path
prerequisites_path = Path(__file__).parent.parent.parent.parent / "prerequisites"
sys.path.append(str(prerequisites_path))
# Import the SDK modules
from zvml import ZVMLClient
# Import configuration
try:
from config import (
ZVM_HOST,
ZVM_PORT,
ZVM_SSL_VERIFY,
CLIENT_ID,
CLIENT_SECRET
)
except ImportError:
print("Error: Please copy config.example.py to config.py and update with your values")
print("Expected path:", prerequisites_path / "config.py")
sys.exit(1)
def main():
"""
Main function to demonstrate resource discovery.
Complete the following steps:
1. Discover local site resources (VMs)
2. Work with peer site resources (datastores, hosts, folders, networks)
"""
# Set up logging with timestamp
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)
try:
# Step 1: Create a ZVMLClient instance
# TODO: Initialize the ZVMLClient with your ZVM host and credentials
# Hint: Use ZVMLClient(zvm_address=ZVM_HOST, client_id=CLIENT_ID,
# client_secret=CLIENT_SECRET, verify_certificate=ZVM_SSL_VERIFY)
client = None # Replace with actual client initialization
# Step 2: Identify local and peer sites
# Step 2.1: List all available sites
# TODO: Get the list of available sites
# Hint: Use client.virtualization_sites.get_virtualization_sites()
# Hint: Log the number of sites found and their details using json.dumps()
pass # Replace with actual site listing
# Step 2.2: Get local and peer site identifiers
# TODO: Get local site identifier
# Hint: Use client.localsite.get_local_site()
# Hint: Extract the SiteIdentifier from the response
local_site_identifier = None # Replace with actual local site identifier
# TODO: Get peer site identifier
# Hint: Find the first site that is not the local site
# Hint: Extract the SiteIdentifier from that site
peer_site_identifier = None # Replace with actual peer site identifier
# Step 3: Get local site resources
# Step 3.1: Get local site VMs
# TODO: Get VMs for the local site
# Hint: Use client.virtualization_sites.get_virtualization_site_vms()
# Hint: Pass the local_site_identifier as site_identifier parameter
# Hint: Log the VMs information using json.dumps()
pass # Replace with actual VM retrieval
# Step 3.2: Get peer site datastores
# TODO: Get datastores for the peer site
# Hint: Use client.virtualization_sites.get_virtualization_site_datastores()
# Hint: Pass the peer_site_identifier as site_identifier parameter
# Hint: Log the datastores information using json.dumps()
pass # Replace with actual datastore retrieval
# Step 3.3: Get peer site hosts
# TODO: Get hosts for the peer site
# Hint: Use client.virtualization_sites.get_virtualization_site_hosts()
# Hint: Pass the peer_site_identifier as site_identifier parameter
# Hint: Log the hosts information using json.dumps()
pass # Replace with actual host retrieval
# Step 3.4: Get peer site folders
# TODO: Get folders for the peer site
# Hint: Use client.virtualization_sites.get_virtualization_site_folders()
# Hint: Pass the peer_site_identifier as site_identifier parameter
# Hint: Log the folders information using json.dumps()
pass # Replace with actual folder retrieval
# Step 3.5: Get peer site networks
# TODO: Get networks for the peer site
# Hint: Use client.virtualization_sites.get_virtualization_site_networks()
# Hint: Pass the peer_site_identifier as site_identifier parameter
# Hint: Log the networks information using json.dumps()
pass # Replace with actual network retrieval
except Exception as e:
# TODO: Handle any resource discovery errors
# Hint: Use logging.error() to log the error message
logging.error(f"Resource discovery failed: {str(e)}")
sys.exit(1)
if __name__ == "__main__":
main()