@@ -446,6 +446,64 @@ 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.
452+ """
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' , '' )} )" )
459+ machines_response : Response = self .api .api_call (
460+ f"projects/{ self .project_id } /machines"
461+ )
462+ if not machines_response .ok :
463+ print (f"ERROR: API response did not return a 2XX status; Returned { machines_response .status_code } ..." )
464+ return {}
465+ for _query_value in self .target_machines .split ("," ):
466+ response_dict [_query_value ] = {
467+ "in_inventory" : "false" ,
468+ "replication_status" : "" ,
469+ "last_seen_utc" : "" ,
470+ "total_storage_bytes" : "" ,
471+ "replicated_storage_bytes" : "" ,
472+ "rescanned_storage_bytes" : "" ,
473+ "backlogged_storage_bytes" : ""
474+ }
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
506+
449507 def update_blueprint (self ) -> bool :
450508 """Update the blueprint associated with the specified machines."""
451509 print (f"Updating CloudEndure Blueprints - Name: ({ self .project_name } ) - Dry Run: ({ self .dry_run } )" )
0 commit comments