simplified instructions

This commit is contained in:
Kosta Mushkin
2025-06-12 20:09:35 -04:00
parent 4690e82e58
commit bd951d0811
7 changed files with 916 additions and 396 deletions
+106 -41
View File
@@ -1,19 +1,30 @@
#!/usr/bin/env python3
"""
Exercise 3: Site Discovery
Exercise 3: Site Discovery - Beginner-Friendly Instructions
This script demonstrates how to discover and work with Zerto virtualization sites.
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
PREREQUISITES (Complete these first):
1. ✅ Completed Exercise 2 (Authentication)
2. ✅ Make sure you have the zvml package installed
3. ✅ Updated prerequisites/config.py with your ZVM details
Your task:
1. List all available virtualization sites
2. Get and display local site information
WHAT YOU NEED TO DO:
In this exercise, you will:
1. Create a ZVMLClient to connect to your ZVM (same as Exercise 2)
2. Get a list of all available virtualization sites
3. Get detailed information about your local site
If you need help, check the solution in the solution directory.
STEP-BY-STEP INSTRUCTIONS:
1. Look at the TODO comments below - they tell you exactly what to do
2. Replace the placeholder code with the actual code
3. Each step has hints and examples to help you
4. If you get stuck, check the solution file in the solution/ directory
WHAT ARE VIRTUALIZATION SITES?
- A "site" in Zerto is a location where you have virtual machines
- Your "local site" is where your ZVM is running
- "Peer sites" are other locations you can replicate to/from
- Each site has information like name, type, version, etc.
"""
import sys
@@ -22,62 +33,116 @@ import logging
import json
from pathlib import Path
# Add prerequisites to Python path
# Add prerequisites to Python path (this helps Python find your config file)
prerequisites_path = Path(__file__).parent.parent.parent.parent / "prerequisites"
sys.path.append(str(prerequisites_path))
# Import the SDK modules
# Import the Zerto SDK - this gives us the ZVMLClient class
from zvml import ZVMLClient
# Import configuration
# Import your configuration settings
try:
from config import (
ZVM_HOST,
ZVM_PORT,
ZVM_SSL_VERIFY,
CLIENT_ID,
CLIENT_SECRET
ZVM_HOST, # Your ZVM IP address (e.g., "192.168.1.100")
ZVM_PORT, # Usually 443 for HTTPS
ZVM_SSL_VERIFY, # True/False for SSL certificate verification
CLIENT_ID, # Your Keycloak client ID (e.g., "my-api-client")
CLIENT_SECRET # Your Keycloak client secret
)
except ImportError:
print("Error: Please copy config.example.py to config.py and update with your values")
print("❌ ERROR: Configuration file not found!")
print("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 site discovery.
Complete the following steps:
1. List all available virtualization sites
2. Get and display local site information
Main function - this is where your code goes!
Follow the step-by-step instructions below.
"""
# Set up logging with timestamp
# Set up logging so you can see what's happening
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)
print("🚀 Starting Zerto Site Discovery Exercise")
print("=" * 50)
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 1: Create a ZVMLClient instance
# ========================================
print("\n📝 STEP 1: Creating ZVMLClient...")
print("This is the same as Exercise 2 - you need to create a client to connect to ZVM.")
# Step 2: List all available sites
# TODO: Get the list of virtualization 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
# TODO: Replace this line with actual ZVMLClient creation
# HINT: Use this syntax (same as Exercise 2):
# client = ZVMLClient(
# zvm_address=ZVM_HOST,
# client_id=CLIENT_ID,
# client_secret=CLIENT_SECRET,
# verify_certificate=ZVM_SSL_VERIFY
# )
#
# EXPLANATION:
# This creates a connection to your ZVM (same as Exercise 2)
# Step 3: Get and display local site information
# TODO: Get and display local site information
# Hint: Use client.localsite.get_local_site()
# Hint: Log the local site details using json.dumps()
pass # Replace with actual local site retrieval
client = None # ← REPLACE THIS LINE WITH YOUR CODE
# ========================================
# STEP 2: List all available sites
# ========================================
print("\n📝 STEP 2: Getting list of sites...")
print("You need to get a list of all virtualization sites available to your ZVM.")
# TODO: Add code to get the list of sites
# HINT: Use this syntax:
# sites = client.virtualization_sites.get_virtualization_sites()
#
# EXPLANATION:
# - client.virtualization_sites.get_virtualization_sites() gets all sites
# - This returns a list of site information
# ← ADD YOUR CODE HERE
# TODO: Add code to display the sites
# HINT: Use this syntax:
# 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)}')
#
# EXPLANATION:
# - len(sites) counts how many sites were found
# - json.dumps(sites, indent=4) formats the site data nicely
# - logging.info() displays the information
# ← ADD YOUR CODE HERE
# ========================================
# STEP 3: Get local site information
# ========================================
print("\n📝 STEP 3: Getting local site details...")
print("You need to get detailed information about your local site.")
# TODO: Add code to get local site information
# HINT: Use this syntax:
# local_site = client.localsite.get_local_site()
# logging.info(f"Local site details: {json.dumps(local_site, indent=4)}")
#
# EXPLANATION:
# - client.localsite.get_local_site() gets info about your local ZVM
# - This includes version, name, type, and other details
# - json.dumps(local_site, indent=4) formats it nicely
# ← ADD YOUR CODE HERE
except Exception as e:
# TODO: Handle any site discovery errors
# Hint: Use logging.error() to log the error message
# This catches any errors that might occur
print(f"\n❌ ERROR: Something went wrong!")
print(f"Error details: {str(e)}")
logging.error(f"Site discovery failed: {str(e)}")
sys.exit(1)