simplified version

This commit is contained in:
Kosta Mushkin
2025-06-22 17:43:43 -07:00
parent 3eee7d623b
commit 3cfde61792
23 changed files with 425 additions and 778 deletions
@@ -20,6 +20,10 @@ import os
import logging
import json
from pathlib import Path
import urllib3
# Suppress SSL warnings
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# Add prerequisites to Python path
prerequisites_path = Path(__file__).parent.parent.parent.parent / "prerequisites"
@@ -69,12 +73,7 @@ def main():
# 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)}')
logging.info(f"Sites: {json.dumps(sites, indent=4)}")
# Step 2.2: Get local and peer site Identifiers
local_site_identifier = client.localsite.get_local_site().get('SiteIdentifier')
@@ -82,38 +81,28 @@ def main():
# 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...")
# Step 3: Get 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)}")
@@ -3,10 +3,11 @@
Exercise 4: Resource Discovery - Beginner-Friendly Instructions
This script demonstrates how to discover and work with resources in your Zerto environment.
PREREQUISITES (Complete these first):
1. ✅ Completed Exercise 3 (Site Discovery)
2. ✅ Make sure you have the zvml package installed
3. ✅ Updated prerequisites/config.py with your ZVM details
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
WHAT YOU NEED TO DO:
In this exercise, you will:
@@ -38,15 +39,19 @@ import os
import logging
import json
from pathlib import Path
import urllib3
# Add prerequisites to Python path (this helps Python find your config file)
# Suppress SSL warnings
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# Add prerequisites to Python path
prerequisites_path = Path(__file__).parent.parent.parent.parent / "prerequisites"
sys.path.append(str(prerequisites_path))
# Import the Zerto SDK - this gives us the ZVMLClient class
# Import the SDK modules
from zvml import ZVMLClient
# Import your configuration settings
# Import configuration
try:
from config import (
ZVM_HOST, # Your ZVM IP address (e.g., "192.168.1.100")
@@ -56,32 +61,27 @@ try:
CLIENT_SECRET # Your Keycloak client secret
)
except ImportError:
print("❌ ERROR: Configuration file not found!")
print("Please copy config.example.py to config.py and update with your values")
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 - this is where your code goes!
Follow the step-by-step instructions below.
Main function to demonstrate resource discovery.
Shows how to:
1. Discover local site resources
2. Work with peer site resources
"""
# Set up logging so you can see what's happening
# Set up logging with timestamp
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)
print("🚀 Starting Zerto Resource Discovery Exercise")
print("=" * 50)
try:
# ========================================
# STEP 1: Create a ZVMLClient instance
# ========================================
print("\n📝 STEP 1: Creating ZVMLClient...")
print("This is the same as previous exercises - you need to create a client to connect to ZVM.")
# ========================================
# TODO: Replace this line with actual ZVMLClient creation
# HINT: Use this syntax (same as previous exercises):
# client = ZVMLClient(
@@ -90,61 +90,65 @@ def main():
# client_secret=CLIENT_SECRET,
# verify_certificate=ZVM_SSL_VERIFY
# )
# EXPLANATION:
# connection to ZVM is established using the ZVMLClient class
# ← ADD YOUR CODE HERE
client = None # ← REPLACE THIS LINE WITH YOUR CODE
# ========================================
# STEP 2: Identify local and peer sites
# ========================================
print("\n📝 STEP 2.1: Getting list of sites...")
print("You need to get a list of all available sites (same as Exercise 3).")
# ========================================
# STEP 2.1: Get virtualization sites
# ========================================
# TODO: Add code to get the list of sites
# HINT: Use this syntax:
# sites = client.virtualization_sites.get_virtualization_sites()
#
# logging.info(f"Sites: {json.dumps(sites, indent=4)}")
# EXPLANATION:
# This gets all sites available to your ZVM
# ← ADD YOUR CODE HERE
print("\n📝 STEP 2.2: Getting local site identifier...")
print("You need to get the identifier for your local site.")
# ========================================
# STEP 2.2: Get local site identifier
# TODO: Add code to get local site identifier
# HINT: Use this syntax:
# local_site_identifier = client.localsite.get_local_site().get('SiteIdentifier')
# logging.info(f"Local site identifier: {local_site_identifier}")
#
# EXPLANATION:
# - client.localsite.get_local_site() gets your local site info
# - .get('SiteIdentifier') extracts the unique identifier
local_site_identifier = None # ← REPLACE THIS LINE WITH YOUR CODE
print("\n📝 STEP 2.3: Getting peer site identifier...")
print("You need to find a peer site (any site that's not your local site).")
# ← ADD YOUR CODE HERE
# ========================================
# STEP 2.3: Get peer site identifier
# TODO: Add code to get peer site identifier
# HINT: Use this syntax:
# peer_site = next((site for site in sites if site.get('SiteIdentifier') != local_site_identifier), None)
# peer_site_identifier = peer_site.get('SiteIdentifier')
#
# logging.info(f"Peer site identifier: {peer_site_identifier}")
# EXPLANATION:
# - This finds the first site that's not your local site
# - next() gets the first matching site from the list
# - .get('SiteIdentifier') extracts the unique identifier
peer_site_identifier = None # ← REPLACE THIS LINE WITH YOUR CODE
# ← ADD YOUR CODE HERE
# ========================================
# STEP 3: Get local site resources
# ========================================
print("\n📝 STEP 3.1: Getting local site VMs...")
print("You need to get all virtual machines from your local site.")
# TODO: Add code to get local site VMs
# HINT: Use this syntax:
# local_vms = client.virtualization_sites.get_virtualization_site_vms(site_identifier=local_site_identifier)
# logging.info(f"Local VMs: {json.dumps(local_vms, indent=4)}")
#
# EXPLANATION:
# This gets all VMs that can be protected/replicated from your local site
@@ -154,48 +158,50 @@ def main():
# ========================================
# STEP 4: Get peer site resources
# ========================================
print("\n📝 STEP 4.1: Getting peer site datastores...")
print("You need to get datastores from the peer site.")
# ========================================
# STEP 4.1: Get peer site datastores
# ========================================
# TODO: Add code to get peer site datastores
# HINT: Use this syntax:
# peer_datastores = client.virtualization_sites.get_virtualization_site_datastores(site_identifier=peer_site_identifier)
# logging.info(f"Peer datastores: {json.dumps(peer_datastores, indent=4)}")
#
# EXPLANATION:
# Datastores are storage locations where VMs can be stored on the peer site
# ← ADD YOUR CODE HERE
print("\n📝 STEP 4.2: Getting peer site hosts...")
print("You need to get hosts from the peer site.")
# ========================================
# STEP 4.2: Get peer site hosts
# TODO: Add code to get peer site hosts
# HINT: Use this syntax:
# peer_hosts = client.virtualization_sites.get_virtualization_site_hosts(site_identifier=peer_site_identifier)
# logging.info(f"Peer hosts: {json.dumps(peer_hosts, indent=4)}")
#
# EXPLANATION:
# Hosts are physical servers that can run VMs on the peer site
# ← ADD YOUR CODE HERE
print("\n📝 STEP 4.3: Getting peer site folders...")
print("You need to get folders from the peer site.")
# ========================================
# STEP 4.3: Get peer site folders
# TODO: Add code to get peer site folders
# HINT: Use this syntax:
# peer_folders = client.virtualization_sites.get_virtualization_site_folders(site_identifier=peer_site_identifier)
# logging.info(f"Peer folders: {json.dumps(peer_folders, indent=4)}")
#
# EXPLANATION:
# Folders are organizational containers for VMs on the peer site
# ← ADD YOUR CODE HERE
print("\n📝 STEP 4.4: Getting peer site networks...")
print("You need to get networks from the peer site.")
# ========================================
# STEP 4.4: Get peer site networks
# TODO: Add code to get peer site networks
# HINT: Use this syntax:
# peer_networks = client.virtualization_sites.get_virtualization_site_networks(site_identifier=peer_site_identifier)
# logging.info(f"Peer networks: {json.dumps(peer_networks, indent=4)}")
#
# EXPLANATION:
# Networks are network connections that VMs can use on the peer site
@@ -203,9 +209,6 @@ def main():
# ← ADD YOUR CODE HERE
except Exception as e:
# This catches any errors that might occur
print(f"\n❌ ERROR: Something went wrong!")
print(f"Error details: {str(e)}")
logging.error(f"Resource discovery failed: {str(e)}")
sys.exit(1)