|
9 | 9 | import os |
10 | 10 | import pprint |
11 | 11 | from typing import Any, Dict, List |
| 12 | +from datetime import datetime, timezone |
12 | 13 |
|
13 | 14 | import boto3 |
14 | 15 | import fire |
@@ -524,9 +525,24 @@ def get_machines_not_started(self) -> List[Any]: |
524 | 525 | return not_started_machines |
525 | 526 | else: |
526 | 527 | print(f"INFO: All machines are STARTED in Project: ({self.project_name})") |
527 | | - |
528 | | - |
529 | 528 |
|
| 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 | + |
530 | 546 | def update_blueprint(self) -> bool: |
531 | 547 | """Update the blueprint associated with the specified machines.""" |
532 | 548 | print(f"Updating CloudEndure Blueprints - Name: ({self.project_name}) - Dry Run: ({self.dry_run})") |
|
0 commit comments