added additional paramters to methods in peersites.py and vpgs.py

This commit is contained in:
Kosta Mushkin
2025-05-27 19:49:57 -04:00
parent fa82ed2221
commit 8f3d400205
2 changed files with 36 additions and 38 deletions
+19 -33
View File
@@ -19,23 +19,37 @@ class PeerSites:
self.client = client
self.tasks = Tasks(client)
def get_peer_sites(self):
def get_peer_sites(self, site_identifier=None):
"""
Get details of all peer sites paired with this site. (Auth)
Get details of peer sites. (Auth)
Args:
site_identifier (str, optional): The identifier of a specific peer site to retrieve.
If not provided, returns all peer sites.
Returns:
list: List of peer sites
dict/list: If site_identifier is provided, returns details of the specific peer site.
Otherwise, returns a list of all peer sites.
"""
url = f"https://{self.client.zvm_address}/v1/peersites"
if site_identifier:
url = f"https://{self.client.zvm_address}/v1/peersites/{site_identifier}"
logging.info(f"PeerSites.get_peer_sites: Fetching peer site with identifier: {site_identifier}...")
else:
url = f"https://{self.client.zvm_address}/v1/peersites"
logging.info("PeerSites.get_peer_sites: Fetching all peer sites...")
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {self.client.token}'
}
logging.info("PeerSites.get_peer_sites: Fetching all peer sites...")
try:
response = requests.get(url, headers=headers, verify=self.client.verify_certificate)
response.raise_for_status()
if site_identifier:
logging.info(f"PeerSites.get_peer_sites: Successfully retrieved peer site information for site identifier: {site_identifier}.")
else:
logging.info("PeerSites.get_peer_sites: Successfully retrieved all peer sites.")
return response.json()
except requests.exceptions.RequestException as e:
if e.response is not None:
@@ -218,34 +232,6 @@ class PeerSites:
logging.error(f"Unexpected error: {e}")
raise
def get_peer_site(self, site_identifier):
logging.info(f"PeerSites.get_peer_site: Fetching peer site information for site identifier: {site_identifier}...")
url = f"https://{self.client.zvm_address}/v1/peersites/{site_identifier}"
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {self.client.token}'
}
try:
response = requests.get(url, headers=headers, verify=self.client.verify_certificate)
response.raise_for_status()
logging.info(f"PeerSites.get_peer_site: Successfully retrieved peer site information for site identifier: {site_identifier}.")
return response.json()
except requests.exceptions.RequestException as e:
if e.response is not None:
logging.error(f"HTTPError: {e.response.status_code} - {e.response.reason}")
try:
error_details = e.response.json()
logging.error(f"Error Message: {error_details.get('Message', 'No detailed error message available')}")
except ValueError:
logging.error(f"Response content: {e.response.text}")
else:
logging.error("HTTPError occurred with no response attached.")
raise
except Exception as e:
logging.error(f"Unexpected error: {e}")
raise
def get_peer_site_types(self):
logging.info("PeerSites.get_peer_site_types: Fetching peer site information for site types...")
url = f"https://{self.client.zvm_address}/v1/peersites/types"
+17 -5
View File
@@ -231,18 +231,30 @@ class VPGs:
except requests.exceptions.RequestException as e:
if e.response is not None:
logging.error(f"HTTPError: {e.response.status_code} - {e.response.reason}")
try:
error_details = e.response.json()
logging.error(f"Error Message: {error_details.get('Message', 'No detailed error message available')}")
error_message = error_details.get('Message', '')
# Extract the actual error message after "Exception occurred in API:"
if 'Exception occurred in API:' in error_message:
detailed_error = error_message.split('Exception occurred in API:', 1)[1].strip()
# Remove trailing semicolon if present
detailed_error = detailed_error.rstrip(';')
# Log only the detailed error message
logging.error(f"Failed to add VM to VPG: {detailed_error}")
else:
logging.error(f"Failed to add VM to VPG: {error_message}")
# Log the full error details at debug level for troubleshooting
logging.debug(f"Full error response: {json.dumps(error_details, indent=2)}")
except ValueError:
logging.error(f"Response content: {e.response.text}")
logging.error(f"Failed to add VM to VPG: {e.response.text}")
else:
logging.error("HTTPError occurred with no response attached.")
logging.error(f"Failed to add VM to VPG: {str(e)}")
raise
except Exception as e:
logging.error(f"Unexpected error: {e}")
logging.error(f"Failed to add VM to VPG: {str(e)}")
raise
def remove_vm_from_vpg(self, vpg_name, vm_identifier):