-
Notifications
You must be signed in to change notification settings - Fork 12
TVAULT-4840 Delete snapshot physically from database #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| b1ce2f2b-ed68-40ec-b737-2719bfe51f36 | ||
| fb79b4f8-2ba0-442c-8100-fb47c6d401b2 | ||
| 2514cb28-88f0-4a48-9a09-34aeb44ff543 | ||
| c5ab19af-1d1a-4a4d-a717-99c5aed70b6b |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import os | ||
| import datetime | ||
| from lib.utility import (setup_logger, | ||
| file_manager, | ||
| connect_db | ||
| ) | ||
|
|
||
|
|
||
| def delete_snapshots(curr, conn, snapshots_ids): | ||
| for snapshot_id in snapshot_ids: | ||
| try: | ||
| snapshot_exists = "SELECT EXISTS(SELECT * FROM snapshots WHERE id = %s AND deleted = 1 AND status = \"deleted\")" | ||
| curr.execute(snapshot_exists, (snapshot_id,)) | ||
| temp = curr.fetchall()[0][0] | ||
| if temp == 1: | ||
| Log_wlm_delete.info("snapshot_id: %s Exists" % snapshot_id) | ||
| query = "DELETE FROM snapshots WHERE id = %s" | ||
| curr.execute(query, (snapshot_id,)) | ||
| Log_wlm_delete.info("snapshot_id: %s removed \n" % snapshot_id) | ||
| else: | ||
| Log_wlm.info("snapshot_id: %s doesn't Exist \n" % snapshot_id) | ||
| conn.commit() | ||
|
|
||
| except Exception as err: | ||
| Log_wlm.exception(err) | ||
| raise err | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
|
|
||
| conn = None | ||
| cursor = None | ||
|
|
||
| dir_name = 'log/snapshotmgr-' + datetime.datetime.now().strftime('%b-%d-%Y-%H:%M:%S') | ||
| log_dir = os.path.join(os.getcwd(), dir_name) | ||
| os.makedirs(log_dir) | ||
| snapshot_gen = log_dir + '/snapshotmgr-snapshot.log' | ||
| snapshot_del = log_dir + '/snapshotmgr-snapshot-delete.log' | ||
| Log_wlm = setup_logger('snapshotmgr', snapshot_gen) | ||
| Log_wlm_delete = setup_logger('snapshotmgr_del', snapshot_del) | ||
| try: | ||
| conn, cursor = connect_db(Log_wlm) | ||
| if cursor: | ||
| snapshot_ids = file_manager('config/snapshot_ids.txt', Log_wlm, file_type='text', mode='r') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it could have been better to use argparser and take this config file from user as an argument instead of hard coding it. |
||
| delete_snapshots(cursor, conn, snapshot_ids) | ||
|
|
||
| except Exception as err: | ||
| Log_wlm.exception(err) | ||
|
|
||
| finally: | ||
| if conn and conn.is_connected(): | ||
| cursor.close() | ||
| conn.close() | ||
| Log_wlm.info("connection closed \n") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ | |
| def delete_workload(curr, conn, workload_ids): | ||
| for workload_id in workload_ids: | ||
| try: | ||
| workload_exists = "SELECT EXISTS(SELECT * FROM workloads WHERE id = %s)" | ||
| workload_exists = "SELECT EXISTS(SELECT * FROM workloads WHERE id = %s AND deleted = 1 AND status = \"deleted\")" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we fetch all the workloads at once ? and process further ? |
||
| curr.execute(workload_exists, (workload_id,)) | ||
| temp = curr.fetchall()[0][0] | ||
| if temp == 1: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't we fetch all the given snaps at once, something like SELECT * FROM snapshots WHERE id in (<list_of_snap_ids>) AND deleted = 1 AND status = "deleted"