Skip to content

Commit

Permalink
Merge pull request #121 from 2ndWatch/change/fn_output_type
Browse files Browse the repository at this point in the history
Change output from function and bugfix
  • Loading branch information
twarnock authored May 26, 2020
2 parents 4d561a9 + fcff0b8 commit 134a42e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SHA1 := $$(git log -1 --pretty=%h)
CURRENT_BRANCH := $$(git symbolic-ref -q --short HEAD)
LATEST_TAG := ${REPO_NAME}:latest
GIT_TAG := ${REPO_NAME}:${SHA1}
VERSION := v0.3.1
VERSION := v0.3.2

info: ## Show information about the current git state.
@echo "Github Project: https://github.com/${REPO_NAME}\nCurrent Branch: ${CURRENT_BRANCH}\nSHA1: ${SHA1}\n"
Expand Down
2 changes: 1 addition & 1 deletion cloudendure/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.3.1"
__version__ = "0.3.2"
56 changes: 28 additions & 28 deletions cloudendure/cloudendure.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,49 +447,49 @@ def check_licenses(self) -> Dict[str, Any]:

return response_dict

def get_machine_sync_details(self) -> List[Any]:
def get_machine_sync_details(self) -> Dict[Any]:
"""Checks CloudEndure Project inventory and returns register machine replication state.
"""
response_list: List[Any] = []
print(f"INFO: Retreiving sync status for all machines in Project: ({self.project_name})")
machines_response: Response = self.api.api_call(f"projects/{self.project_id}/machines")
if not machines_response.ok:
print(f"ERROR: API response did not return a 2XX status; Returned {machines_response.status_code} ...")
return {}
response_dict: Dict[str, Any] = {}
ce_project_inventory = json.loads(machines_response.text).get("items", [])
for _query_value in ce_project_inventory:
machine_name: str = _query_value["sourceProperties"]["name"]
sync_details: Dict[str, Any] = {
"machine_name": machine_name,
machine_id: str = _query_value["id"]
replication_info: Dict[str, Any] = _query_value.get("replicationInfo", {})
response_dict[machine_id] = {
"machine_name": _query_value.get("sourceProperties", {}).get("name", ""),
"in_inventory": _query_value["isAgentInstalled"],
"replication_status": _query_value["replicationStatus"],
"last_seen_utc": _query_value["replicationInfo"]["lastSeenDateTime"],
"total_storage_bytes": _query_value["replicationInfo"]["totalStorageBytes"],
"replicated_storage_bytes": _query_value["replicationInfo"]["replicatedStorageBytes"],
"rescanned_storage_bytes": 0,
"backlogged_storage_bytes": _query_value["replicationInfo"]["backloggedStorageBytes"],
"total_storage_bytes": replication_info.get("totalStorageBytes", -1),
"replicated_storage_bytes": replication_info.get("replicatedStorageBytes", -1),
"rescanned_storage_bytes": replication_info.get("rescannedStorageBytes", 0),
"backlogged_storage_bytes": replication_info.get("backloggedStorageBytes", -1),
}
if "rescannedStorageBytes" in _query_value["replicationInfo"]:
sync_details["recanned_storage_bytes"] = _query_value["replicationInfo"]["rescannedStorageBytes"]
response_list.append(sync_details)
if replication_info.get("lastSeenDateTime"):
response_dict[machine_id]["last_seen_utc"] = replication_info.get("lastSeenDateTime")
# Project is still printing to console as a convention; Emitting an
# output to stdout for interactive usage
return response_list
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

Expand All @@ -506,12 +506,12 @@ def not_started(self, machine) -> bool:
return True

def not_current(self, machine, delta_seconds: int = 86400) -> bool:
now: datetime = datetime.now(timezone.utc)
machine_last_seen: datetime = datetime.fromisoformat(machine["last_seen_utc"])
last_seen_delta: datetime = now - machine_last_seen
# If you're exceeding the size of int, you have bigger problems
if int(last_seen_delta.total_seconds()) >= delta_seconds:
return True
if machine.get("last_seen_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:
return True
else:
return False

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cloudendure"
version = "0.3.1"
version = "0.3.2"
description = "Python wrapper and CLI for CloudEndure"
authors = ["Mark Beacom <[email protected]>", "Tom Warnock <[email protected]>"]
maintainers = ["Evan Lucchesi <[email protected]>", "Nick Selpa <[email protected]>"]
Expand Down

0 comments on commit 134a42e

Please sign in to comment.