Skip to content

Commit c4906f8

Browse files
author
Nick Selpa
committed
Update license window and bug fix
The module has been updated to reflect the increase in license days from 90 to 135 for expiration. Reworked `inspect-ce-project` to be more Pythonic
1 parent 5ce585d commit c4906f8

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

cloudendure/cloudendure.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,8 @@ def check_licenses(self) -> Dict[str, Any]:
419419
print(f"Checking CloudEndure Licenses - Name: ({self.project_name})")
420420

421421
now: datetime = datetime.datetime.now(datetime.timezone.utc)
422-
expirationday: timedelta = datetime.timedelta(days=90)
423-
expirationwarn: timedelta = datetime.timedelta(days=60)
422+
expirationday: timedelta = datetime.timedelta(days=135)
423+
expirationwarn: timedelta = datetime.timedelta(days=90)
424424
machine_data_dict: Dict[str, Any] = {}
425425
machines_response: Response = self.api.api_call(f"projects/{self.project_id}/machines")
426426
for machine in json.loads(machines_response.text).get("items", []):
@@ -477,10 +477,10 @@ def get_machine_sync_details(self) -> Dict[Any]:
477477
# output to stdout for interactive usage
478478
return response_dict
479479

480+
481+
480482
def inspect_ce_project(self, check_type: str) -> Dict[str, Any]:
481-
state_check_types: List[str] = ["not_synced", "not_started"]
482-
time_check_types: List[str] = ["not_current", "is_lagged"]
483-
valid_check_types: List[str] = state_check_types + time_check_types
483+
valid_check_types: List[str] = ["not_synced", "not_started", "not_current", "is_lagged"]
484484
if check_type not in valid_check_types:
485485
print(
486486
f'ERROR: Unknown check_type of "{check_type}"; Please use a valid check_type: [ {", ".join(valid_check_types)} ] ...'
@@ -489,33 +489,37 @@ def inspect_ce_project(self, check_type: str) -> Dict[str, Any]:
489489
result: Dict[str, Any] = {}
490490
sync_report: Dict[str, Any] = self.get_machine_sync_details()
491491
print(f"INFO: Using check '{check_type}' on Project: ({self.project_name})")
492-
if check_type in state_check_types:
493-
inspector1 = getattr(self, check_type)
494-
else:
495-
inspector2 = getattr(self, "time_delta_context")
496-
for item in sync_report.keys():
497-
if inspector2:
498-
mcheck = inspector2(machine=sync_report[item], check_type=check_type)
499-
else:
500-
mcheck = inspector1(machine=sync_report[item])
501-
if mcheck:
502-
result[item] = sync_report[item]
492+
if check_type in valid_check_types:
493+
for item in sync_report.keys():
494+
mcheck = self._inspector(machine=sync_report[item], check_type=check_type)
495+
if mcheck:
496+
result[item] = sync_report[item]
503497
print(f"INFO: Check '{check_type}' completed; {len(result)} machines matched in Project: ({self.project_name})")
504498
return result
505499

506-
def not_synced(self, machine) -> bool:
500+
def _inspector(self, **kwargs):
501+
# this could probably be a switch but I'll just elif this
502+
if "machine" in kwargs.keys():
503+
if "not_synced" in kwargs.values():
504+
return self._not_synced(machine=kwargs.get("machine"))
505+
elif "not_started" in kwargs.values():
506+
return self._not_started(machine=kwargs.get("machine"))
507+
else:
508+
return self._time_delta_context(machine=kwargs.get("machine", {}), check_type=kwargs.get("check_type", ""))
509+
510+
def _not_synced(self, machine) -> bool:
507511
if machine["backlogged_storage_bytes"] > 0 or machine["rescanned_storage_bytes"] > 0:
508512
return True
509513
else:
510514
return False
511515

512-
def not_started(self, machine) -> bool:
516+
def _not_started(self, machine) -> bool:
513517
if machine["replication_status"] == "STARTED":
514518
return False
515519
else:
516520
return True
517521

518-
def time_delta_context(self, machine: Dict[str, Any], check_type: str) -> bool:
522+
def _time_delta_context(self, machine: Dict[str, Any], check_type: str) -> bool:
519523
time_contexts: Dict[str, dict] = {
520524
"not_current": {"delta_seconds": 86400, "property": "last_seen_utc"},
521525
"is_lagged": {"delta_seconds": 120, "property": "last_consistency_utc"},

0 commit comments

Comments
 (0)