Skip to content

Commit 1ebb1e0

Browse files
author
Nick Selpa
committed
Completed reporting for backlogged syncing of servers in CE for a given project
1 parent c55f842 commit 1ebb1e0

File tree

1 file changed

+52
-42
lines changed

1 file changed

+52
-42
lines changed

cloudendure/cloudendure.py

Lines changed: 52 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -446,24 +446,23 @@ def check_licenses(self) -> Dict[str, Any]:
446446

447447
return response_dict
448448

449-
def get_machine_sync_details(self) -> Dict[str, Any]:
450-
"""Checks if machine name is in CloudEndure inventory and returns
451-
machine's replication state.
449+
def get_machine_sync_details(self) -> List[Any]:
450+
"""Checks CloudEndure Project inventory and returns register machine's
451+
replication state.
452452
"""
453-
response_dict: Dict[str, Any] = {}
454-
# **NOTE**: Still up in the air about implementing this to accept a
455-
# list of values to query. Assuming a single query per run.
456-
457-
print(f"Auditing CloudEndure Project: ({self.project_name})")
458-
print(f"Checking CloudEndure Machine Status - Query: ({self.config.active_config.get('machines', '')})")
453+
response_list: List[Any] = []
454+
print(f"INFO: Retreiving sync status for all machines in Project: ({self.project_name})")
459455
machines_response: Response = self.api.api_call(
460456
f"projects/{self.project_id}/machines"
461457
)
462458
if not machines_response.ok:
463459
print(f"ERROR: API response did not return a 2XX status; Returned {machines_response.status_code} ...")
464460
return {}
465-
for _query_value in self.target_machines.split(","):
466-
response_dict[_query_value] = {
461+
ce_project_inventory = json.loads(machines_response.text).get("items", [])
462+
for _query_value in ce_project_inventory:
463+
machine_name: str = _query_value['sourceProperties']['name']
464+
sync_details: Dict[str, Any] = {
465+
"machine_name": machine_name,
467466
"in_inventory": "false",
468467
"replication_status": "",
469468
"last_seen_utc": "",
@@ -472,37 +471,48 @@ def get_machine_sync_details(self) -> Dict[str, Any]:
472471
"rescanned_storage_bytes" : "",
473472
"backlogged_storage_bytes": ""
474473
}
475-
machine_inventory = json.loads(machines_response.text).get("items", [])
476-
for machine in machine_inventory:
477-
# forcing evaluation to be case-insensitive
478-
if _query_value.lower() in machine['sourceProperties']['name'].lower():
479-
if 'rescannedStorageBytes' in machine['replicationInfo']:
480-
response_dict[_query_value] = {
481-
"in_inventory": machine['isAgentInstalled'],
482-
"replication_status": machine['replicationStatus'],
483-
"last_seen_utc": machine['replicationInfo']['lastSeenDateTime'],
484-
"total_storage_bytes": machine['replicationInfo']['totalStorageBytes'],
485-
"replicated_storage_bytes": machine['replicationInfo']['replicatedStorageBytes'],
486-
"rescanned_storage_bytes": machine['replicationInfo']['rescannedStorageBytes'],
487-
"backlogged_storage_bytes": machine['replicationInfo']['backloggedStorageBytes']
488-
}
489-
break
490-
else:
491-
response_dict[_query_value] = {
492-
"in_inventory": machine['isAgentInstalled'],
493-
"replication_status": machine['replicationStatus'],
494-
"last_seen_utc": machine['replicationInfo']['lastSeenDateTime'],
495-
"total_storage_bytes": machine['replicationInfo']['totalStorageBytes'],
496-
"replicated_storage_bytes": machine['replicationInfo']['replicatedStorageBytes'],
497-
"rescanned_storage_bytes": 0,
498-
"backlogged_storage_bytes": machine['replicationInfo']['backloggedStorageBytes']
499-
}
500-
break
501-
# It's assumed a projected does not have duplicate machine names
502-
# for source systems
503-
# Project is still printing to console as a convention; Emitting an
504-
# output to stdout for interactive usage
505-
return response_dict
474+
if 'rescannedStorageBytes' in _query_value['replicationInfo']:
475+
sync_details = {
476+
"machine_name": machine_name,
477+
"in_inventory": _query_value['isAgentInstalled'],
478+
"replication_status": _query_value['replicationStatus'],
479+
"last_seen_utc": _query_value['replicationInfo']['lastSeenDateTime'],
480+
"total_storage_bytes": _query_value['replicationInfo']['totalStorageBytes'],
481+
"replicated_storage_bytes": _query_value['replicationInfo']['replicatedStorageBytes'],
482+
"rescanned_storage_bytes": _query_value['replicationInfo']['rescannedStorageBytes'],
483+
"backlogged_storage_bytes": _query_value['replicationInfo']['backloggedStorageBytes']
484+
}
485+
response_list.append(sync_details)
486+
else:
487+
sync_details = {
488+
"machine_name": machine_name,
489+
"in_inventory": _query_value['isAgentInstalled'],
490+
"replication_status": _query_value['replicationStatus'],
491+
"last_seen_utc": _query_value['replicationInfo']['lastSeenDateTime'],
492+
"total_storage_bytes": _query_value['replicationInfo']['totalStorageBytes'],
493+
"replicated_storage_bytes": _query_value['replicationInfo']['replicatedStorageBytes'],
494+
"rescanned_storage_bytes": 0,
495+
"backlogged_storage_bytes": _query_value['replicationInfo']['backloggedStorageBytes']
496+
}
497+
response_list.append(sync_details)
498+
# Project is still printing to console as a convention; Emitting an
499+
# output to stdout for interactive usage
500+
return response_list
501+
502+
def get_backlogged_synced_machines(self) -> List[Any]:
503+
backlogged_machines: List[Any] = []
504+
sync_report: List[Any] = self.get_machine_sync_details()
505+
print(f"INFO: Filtering for backlogged servers in Project: ({self.project_name})")
506+
for item in sync_report:
507+
if item['backlogged_storage_bytes'] > 0:
508+
backlogged_machines.append(item)
509+
if len(backlogged_machines) > 0:
510+
print(f"INFO: The following machines are backlogged in Project: ({self.project_name})")
511+
return backlogged_machines
512+
else:
513+
print(f"INFO: All machines are in Continuous Data Replication in Project: ({self.project_name})")
514+
515+
506516

507517
def update_blueprint(self) -> bool:
508518
"""Update the blueprint associated with the specified machines."""

0 commit comments

Comments
 (0)