simplified instructions
This commit is contained in:
@@ -1,19 +1,36 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Exercise 4: Resource Discovery
|
||||
Exercise 4: Resource Discovery - Beginner-Friendly Instructions
|
||||
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
|
||||
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
|
||||
|
||||
Your task:
|
||||
1. Discover local site resources (VMs)
|
||||
2. Work with peer site resources (datastores, hosts, folders, networks)
|
||||
WHAT YOU NEED TO DO:
|
||||
In this exercise, you will:
|
||||
1. Create a ZVMLClient to connect to your ZVM (same as previous exercises)
|
||||
2. Get a list of all available sites
|
||||
3. Identify your local site and a peer site
|
||||
4. Discover different types of resources:
|
||||
- Local site: Virtual Machines (VMs)
|
||||
- Peer site: Datastores, Hosts, Folders, Networks
|
||||
|
||||
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 RESOURCES?
|
||||
- **VMs**: Virtual machines that can be protected/replicated
|
||||
- **Datastores**: Storage locations where VMs are stored
|
||||
- **Hosts**: Physical servers that run the VMs
|
||||
- **Folders**: Organizational containers for VMs
|
||||
- **Networks**: Network connections for VMs
|
||||
- **Local Site**: Your current ZVM location
|
||||
- **Peer Site**: Another location you can replicate to/from
|
||||
"""
|
||||
|
||||
import sys
|
||||
@@ -22,104 +39,173 @@ 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 resource discovery.
|
||||
Complete the following steps:
|
||||
1. Discover local site resources (VMs)
|
||||
2. Work with peer site resources (datastores, hosts, folders, networks)
|
||||
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 Resource 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 previous exercises - you need to create a client to connect to ZVM.")
|
||||
|
||||
# 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
|
||||
# TODO: Replace this line with actual ZVMLClient creation
|
||||
# HINT: Use this syntax (same as previous exercises):
|
||||
# client = ZVMLClient(
|
||||
# zvm_address=ZVM_HOST,
|
||||
# client_id=CLIENT_ID,
|
||||
# client_secret=CLIENT_SECRET,
|
||||
# verify_certificate=ZVM_SSL_VERIFY
|
||||
# )
|
||||
|
||||
# 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
|
||||
client = None # ← REPLACE THIS LINE WITH YOUR CODE
|
||||
|
||||
# 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 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 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
|
||||
# TODO: Add code to get the list of sites
|
||||
# HINT: Use this syntax:
|
||||
# sites = client.virtualization_sites.get_virtualization_sites()
|
||||
#
|
||||
# EXPLANATION:
|
||||
# This gets all sites available to your ZVM
|
||||
|
||||
# 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
|
||||
# ← ADD YOUR CODE HERE
|
||||
|
||||
# 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
|
||||
print("\n📝 STEP 2.2: Getting local site identifier...")
|
||||
print("You need to get the identifier for your local site.")
|
||||
|
||||
# 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
|
||||
# TODO: Add code to get local site identifier
|
||||
# HINT: Use this syntax:
|
||||
# local_site_identifier = client.localsite.get_local_site().get('SiteIdentifier')
|
||||
#
|
||||
# EXPLANATION:
|
||||
# - client.localsite.get_local_site() gets your local site info
|
||||
# - .get('SiteIdentifier') extracts the unique identifier
|
||||
|
||||
# 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
|
||||
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).")
|
||||
|
||||
# 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')
|
||||
#
|
||||
# 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
|
||||
|
||||
# ========================================
|
||||
# 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)
|
||||
#
|
||||
# EXPLANATION:
|
||||
# This gets all VMs that can be protected/replicated from your local site
|
||||
|
||||
# ← ADD YOUR CODE HERE
|
||||
|
||||
# ========================================
|
||||
# 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.")
|
||||
|
||||
# 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)
|
||||
#
|
||||
# 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.")
|
||||
|
||||
# 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)
|
||||
#
|
||||
# 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.")
|
||||
|
||||
# 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)
|
||||
#
|
||||
# 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.")
|
||||
|
||||
# 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)
|
||||
#
|
||||
# EXPLANATION:
|
||||
# Networks are network connections that VMs can use on the peer site
|
||||
|
||||
# ← ADD YOUR CODE HERE
|
||||
|
||||
except Exception as e:
|
||||
# TODO: Handle any resource 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"Resource discovery failed: {str(e)}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user