From 73a7359551123dd8a39aaeff38822c576964a158 Mon Sep 17 00:00:00 2001 From: Nick Selpa Date: Tue, 26 May 2020 15:47:57 -0400 Subject: [PATCH] Updated valid_check_types and changed inspect_ce_project to return a dict --- cloudendure/cloudendure.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/cloudendure/cloudendure.py b/cloudendure/cloudendure.py index 7ecf37dd8..77c32c7e4 100644 --- a/cloudendure/cloudendure.py +++ b/cloudendure/cloudendure.py @@ -475,20 +475,21 @@ def get_machine_sync_details(self) -> Dict[Any]: # output to stdout for interactive usage return response_dict - def inspect_ce_project(self, check_type: str) -> List[Any]: - if not check_type: + def inspect_ce_project(self, check_type: str) -> Dict[str, Any]: + valid_check_types: List[str] = ['not_synced', 'not_started', 'not_current'] + if check_type not in valid_check_types: print( - f"ERROR: Unknown check_type of '{check_type}'; Please use 'not_synced', 'not_started', or 'not_current' ..." + f'ERROR: Unknown check_type of "{check_type}"; Please use a valid check_type: [ {", ".join(valid_check_types)} ] ...' ) return - result: List[Any] = [] - sync_report: List[Any] = self.get_machine_sync_details() + result: Dict[str, Any] = {} + sync_report: Dict[str, Any] = self.get_machine_sync_details() print(f"INFO: Using check '{check_type}' on Project: ({self.project_name})") inspector = getattr(self, check_type) - for item in sync_report: - mcheck = inspector(machine=item) + for item in sync_report.keys(): + mcheck = inspector(machine=sync_report[item]) if mcheck: - result.append(item) + result[item] = sync_report[item] print(f"INFO: Check '{check_type}' completed; {len(result)} machines matched in Project: ({self.project_name})") return result @@ -506,7 +507,7 @@ def not_started(self, machine) -> bool: def not_current(self, machine, delta_seconds: int = 86400) -> bool: if machine.get("last_seen_utc"): - now: datetime = datetime.now(datetime.timezone.utc) + now: datetime = datetime.datetime.now(datetime.timezone.utc) machine_last_seen: datetime = datetime.datetime.fromisoformat(machine["last_seen_utc"]) last_seen_delta: datetime = now - machine_last_seen if int(last_seen_delta.total_seconds()) >= delta_seconds: