Last active
July 31, 2020 08:07
-
-
Save cschwede/9b109daee93de777e4cc222f2c022833 to your computer and use it in GitHub Desktop.
A small tool to fix quarantined objects in OpenStack Swift because of changed hash_path_* and/or rings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
from swift.common.ring import Ring | |
from swift.common.utils import hash_path | |
from swift.obj.diskfile import read_metadata | |
datafile = sys.argv[1] | |
with open(datafile, 'rb') as fp: | |
try: | |
metadata = read_metadata(fp) | |
except EOFError: | |
print("Invalid metadata") | |
sys.exit(1) | |
name = metadata.get('name') | |
account, container, obj = name.split('/', 3)[1:] | |
ring = Ring('/etc/swift/', ring_name='object') | |
part = ring.get_part(account, container, obj) | |
path_hash = hash_path(account, container, obj) | |
dir_parts = datafile.split('/') | |
dir_parts.remove('quarantined') | |
fname = dir_parts[-1] | |
base_dir = '/'.join(dir_parts[:-2]) | |
new_dir = "%s/%d/%s/%s" % (base_dir, part, path_hash[-3:], path_hash) | |
mkdir_command = "mkdir -p %s" % new_dir | |
new_name = "%s/%s" % (new_dir, fname) | |
mv_command = "mv %s %s" % (datafile, new_name) | |
print(mkdir_command) | |
print(mv_command) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment