Recreating Openstack Swift Builder files
August 08, 2016
Having lost the original Openstack Swift builder files but still having the ring.gz files it is possible to recreate the builder files.
Samuel Merritt gives the answer here, however, the code has a few bugs.
So using correcting these the following should do the job.
After generating the new builder file using the following (which you can just run using Pythons REPL), you can compare it with the original ring.gz with
zcat. Just write the new ring
swift-ring-builder account.builder write_ring.
from swift.common.ring import RingData, RingBuilder ring = RingData.load('/etc/swift/account.ring.gz') import math partitions = len(ring._replica2part2dev_id) replicas = len(ring._replica2part2dev_id) from array import array builder = RingBuilder(int(math.log(partitions, 2)), replicas, 1) builder.devs = ring.devs builder._replica2part2dev = ring._replica2part2dev_id builder._last_part_moves_epoch = 0 builder._last_part_moves = array('B', (0 for _ in xrange(builder.parts))) for d in builder._iter_devs(): d['parts'] = 0 builder._set_parts_wanted() for p2d in builder._replica2part2dev: for dev_id in p2d: builder.devs[dev_id]['parts'] += 1 builder.change_min_part_hours(24) # or whatever you want it to be builder.validate() import pickle pickle.dump(builder.to_dict(), open('account.builder', 'wb'), protocol=2)