Skip to content

Commit 84a14bb

Browse files
author
Nick Selpa
committed
Added stale machines check; Has default value of 1 day
1 parent 4851462 commit 84a14bb

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

cloudendure/cloudendure.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import os
1010
import pprint
1111
from typing import Any, Dict, List
12+
from datetime import datetime, timezone
1213

1314
import boto3
1415
import fire
@@ -524,9 +525,24 @@ def get_machines_not_started(self) -> List[Any]:
524525
return not_started_machines
525526
else:
526527
print(f"INFO: All machines are STARTED in Project: ({self.project_name})")
527-
528-
529528

529+
def get_stale_machines(self, delta_seconds: int = 86400) -> List[Any]:
530+
stale_machines: List[Any] = []
531+
sync_report: List[Any] = self.get_machine_sync_details()
532+
print(f"INFO: Getting stale machines (not seen for {delta_seconds} seconds or later) in Project: ({self.project_name})")
533+
now: datetime = datetime.now(timezone.utc)
534+
for item in sync_report:
535+
item_last_seen: datetime = datetime.fromisoformat(item['last_seen_utc'])
536+
last_seen_delta: datetime = now - item_last_seen
537+
# If you're exceeding the size of int, you have bigger problems
538+
if int(last_seen_delta.total_seconds()) >= delta_seconds:
539+
stale_machines.append(item)
540+
if len(stale_machines) > 0:
541+
print(f"INFO: Machines not seen for {delta_seconds} seconds found in Project: ({self.project_name})")
542+
return stale_machines
543+
else:
544+
print(f"INFO: No machines in Project: ({self.project_name})")
545+
530546
def update_blueprint(self) -> bool:
531547
"""Update the blueprint associated with the specified machines."""
532548
print(f"Updating CloudEndure Blueprints - Name: ({self.project_name}) - Dry Run: ({self.dry_run})")

0 commit comments

Comments
 (0)