Skip to content

Commit c526112

Browse files
author
Nick Selpa
committed
Linted with black and isort
1 parent 937b13e commit c526112

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed

cloudendure/cloudendure.py

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import json
99
import os
1010
import pprint
11-
from typing import Any, Dict, List
1211
from datetime import datetime, timezone
12+
from typing import Any, Dict, List
1313

1414
import boto3
1515
import fire
@@ -453,53 +453,51 @@ def get_machine_sync_details(self) -> List[Any]:
453453
"""
454454
response_list: List[Any] = []
455455
print(f"INFO: Retreiving sync status for all machines in Project: ({self.project_name})")
456-
machines_response: Response = self.api.api_call(
457-
f"projects/{self.project_id}/machines"
458-
)
456+
machines_response: Response = self.api.api_call(f"projects/{self.project_id}/machines")
459457
if not machines_response.ok:
460458
print(f"ERROR: API response did not return a 2XX status; Returned {machines_response.status_code} ...")
461459
return {}
462460
ce_project_inventory = json.loads(machines_response.text).get("items", [])
463461
for _query_value in ce_project_inventory:
464-
machine_name: str = _query_value['sourceProperties']['name']
462+
machine_name: str = _query_value["sourceProperties"]["name"]
465463
sync_details: Dict[str, Any] = {
466464
"machine_name": machine_name,
467465
"in_inventory": "false",
468466
"replication_status": "",
469467
"last_seen_utc": "",
470468
"total_storage_bytes": "",
471469
"replicated_storage_bytes": "",
472-
"rescanned_storage_bytes" : "",
473-
"backlogged_storage_bytes": ""
470+
"rescanned_storage_bytes": "",
471+
"backlogged_storage_bytes": "",
474472
}
475-
if 'rescannedStorageBytes' in _query_value['replicationInfo']:
473+
if "rescannedStorageBytes" in _query_value["replicationInfo"]:
476474
sync_details = {
477475
"machine_name": machine_name,
478-
"in_inventory": _query_value['isAgentInstalled'],
479-
"replication_status": _query_value['replicationStatus'],
480-
"last_seen_utc": _query_value['replicationInfo']['lastSeenDateTime'],
481-
"total_storage_bytes": _query_value['replicationInfo']['totalStorageBytes'],
482-
"replicated_storage_bytes": _query_value['replicationInfo']['replicatedStorageBytes'],
483-
"rescanned_storage_bytes": _query_value['replicationInfo']['rescannedStorageBytes'],
484-
"backlogged_storage_bytes": _query_value['replicationInfo']['backloggedStorageBytes']
476+
"in_inventory": _query_value["isAgentInstalled"],
477+
"replication_status": _query_value["replicationStatus"],
478+
"last_seen_utc": _query_value["replicationInfo"]["lastSeenDateTime"],
479+
"total_storage_bytes": _query_value["replicationInfo"]["totalStorageBytes"],
480+
"replicated_storage_bytes": _query_value["replicationInfo"]["replicatedStorageBytes"],
481+
"rescanned_storage_bytes": _query_value["replicationInfo"]["rescannedStorageBytes"],
482+
"backlogged_storage_bytes": _query_value["replicationInfo"]["backloggedStorageBytes"],
485483
}
486484
response_list.append(sync_details)
487485
else:
488486
sync_details = {
489487
"machine_name": machine_name,
490-
"in_inventory": _query_value['isAgentInstalled'],
491-
"replication_status": _query_value['replicationStatus'],
492-
"last_seen_utc": _query_value['replicationInfo']['lastSeenDateTime'],
493-
"total_storage_bytes": _query_value['replicationInfo']['totalStorageBytes'],
494-
"replicated_storage_bytes": _query_value['replicationInfo']['replicatedStorageBytes'],
488+
"in_inventory": _query_value["isAgentInstalled"],
489+
"replication_status": _query_value["replicationStatus"],
490+
"last_seen_utc": _query_value["replicationInfo"]["lastSeenDateTime"],
491+
"total_storage_bytes": _query_value["replicationInfo"]["totalStorageBytes"],
492+
"replicated_storage_bytes": _query_value["replicationInfo"]["replicatedStorageBytes"],
495493
"rescanned_storage_bytes": 0,
496-
"backlogged_storage_bytes": _query_value['replicationInfo']['backloggedStorageBytes']
494+
"backlogged_storage_bytes": _query_value["replicationInfo"]["backloggedStorageBytes"],
497495
}
498496
response_list.append(sync_details)
499497
# Project is still printing to console as a convention; Emitting an
500498
# output to stdout for interactive usage
501499
return response_list
502-
500+
503501
def get_machines_not_synced(self) -> List[Any]:
504502
"""Returns machines in a CloudEndure project which are either rescanning or
505503
backlogged for replication data.
@@ -508,14 +506,14 @@ def get_machines_not_synced(self) -> List[Any]:
508506
sync_report: List[Any] = self.get_machine_sync_details()
509507
print(f"INFO: Filtering for backlogged servers in Project: ({self.project_name})")
510508
for item in sync_report:
511-
if item['backlogged_storage_bytes'] > 0 or item['rescanned_storage_bytes'] > 0:
509+
if item["backlogged_storage_bytes"] > 0 or item["rescanned_storage_bytes"] > 0:
512510
backlogged_machines.append(item)
513511
if len(backlogged_machines) > 0:
514512
print(f"INFO: {len(backlogged_machines)} machines are backlogged in Project: ({self.project_name})")
515513
return backlogged_machines
516514
else:
517515
print(f"INFO: All machines are in Continuous Data Replication in Project: ({self.project_name})")
518-
516+
519517
def get_machines_not_started(self) -> List[Any]:
520518
"""Returns machines in a CloudEndure project which are not in a STARTED
521519
state.
@@ -524,7 +522,7 @@ def get_machines_not_started(self) -> List[Any]:
524522
sync_report: List[Any] = self.get_machine_sync_details()
525523
print(f"INFO: Getting replication not STARTED for machines in Project: ({self.project_name})")
526524
for item in sync_report:
527-
if item['replication_status'] != "STARTED":
525+
if item["replication_status"] != "STARTED":
528526
not_started_machines.append(item)
529527
if len(not_started_machines) > 0:
530528
print(f"INFO: {len(not_started_machines)} machines not STARTED found in Project: ({self.project_name})")
@@ -538,20 +536,26 @@ def get_stale_machines(self, delta_seconds: int = 86400) -> List[Any]:
538536
"""
539537
stale_machines: List[Any] = []
540538
sync_report: List[Any] = self.get_machine_sync_details()
541-
print(f"INFO: Getting stale machines (not seen for {delta_seconds} seconds or later) in Project: ({self.project_name})")
539+
print(
540+
f"INFO: Getting stale machines (not seen for {delta_seconds} seconds or later) in Project: ({self.project_name})"
541+
)
542542
now: datetime = datetime.now(timezone.utc)
543543
for item in sync_report:
544-
item_last_seen: datetime = datetime.fromisoformat(item['last_seen_utc'])
544+
item_last_seen: datetime = datetime.fromisoformat(item["last_seen_utc"])
545545
last_seen_delta: datetime = now - item_last_seen
546546
# If you're exceeding the size of int, you have bigger problems
547547
if int(last_seen_delta.total_seconds()) >= delta_seconds:
548548
stale_machines.append(item)
549549
if len(stale_machines) > 0:
550-
print(f"INFO: {len(stale_machines)} machines not seen for {delta_seconds} seconds found in Project: ({self.project_name})")
550+
print(
551+
f"INFO: {len(stale_machines)} machines not seen for {delta_seconds} seconds found in Project: ({self.project_name})"
552+
)
551553
return stale_machines
552554
else:
553-
print(f"INFO: All machines have been seen at least {delta_seconds} seconds ago in Project: ({self.project_name})")
554-
555+
print(
556+
f"INFO: All machines have been seen at least {delta_seconds} seconds ago in Project: ({self.project_name})"
557+
)
558+
555559
def update_blueprint(self) -> bool:
556560
"""Update the blueprint associated with the specified machines."""
557561
print(f"Updating CloudEndure Blueprints - Name: ({self.project_name}) - Dry Run: ({self.dry_run})")

0 commit comments

Comments
 (0)