handle delete, restore snapshot return values

This commit is contained in:
simon 2022-10-29 17:27:04 +07:00
parent f717c71c66
commit 24b02150a7
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4

View File

@ -45,7 +45,7 @@ class ElasticSnapshot:
is_outdated = self._needs_startup_snapshot() is_outdated = self._needs_startup_snapshot()
if is_outdated: if is_outdated:
self.take_snapshot_now() _ = self.take_snapshot_now()
def _check_repo_exists(self): def _check_repo_exists(self):
"""check if expected repo already exists""" """check if expected repo already exists"""
@ -145,6 +145,8 @@ class ElasticSnapshot:
if statuscode == 200: if statuscode == 200:
print(f"snapshot: executing now: {response}") print(f"snapshot: executing now: {response}")
return response
def get_snapshot_stats(self): def get_snapshot_stats(self):
"""get snapshot info for frontend""" """get snapshot info for frontend"""
snapshot_info = self._build_policy_details() snapshot_info = self._build_policy_details()
@ -156,9 +158,7 @@ class ElasticSnapshot:
def get_single_snapshot(self, snapshot_id): def get_single_snapshot(self, snapshot_id):
"""get single snapshot metadata""" """get single snapshot metadata"""
path = f"_snapshot/{self.REPO}/{snapshot_id}" path = f"_snapshot/{self.REPO}/{snapshot_id}"
print(path)
response, statuscode = ElasticWrap(path).get() response, statuscode = ElasticWrap(path).get()
print(response)
if statuscode == 404: if statuscode == 404:
print(f"snapshots: not found: {snapshot_id}") print(f"snapshots: not found: {snapshot_id}")
return False return False
@ -237,3 +237,18 @@ class ElasticSnapshot:
response, statuscode = ElasticWrap(path).post(data=data) response, statuscode = ElasticWrap(path).post(data=data)
if statuscode == 200: if statuscode == 200:
print(f"snapshot: executing now: {response}") print(f"snapshot: executing now: {response}")
return response
print(f"snapshot: failed to restore, {statuscode} {response}")
return False
def delete_single_snapshot(self, snapshot_id):
"""delete single snapshot from index"""
path = f"_snapshot/{self.REPO}/{snapshot_id}"
response, statuscode = ElasticWrap(path).delete()
if statuscode == 200:
print(f"snapshot: deleting {snapshot_id} {response}")
return response
print(f"snapshot: failed to delete, {statuscode} {response}")
return False