Last active
May 10, 2018 03:56
-
-
Save clayg/a6a8fb6cadb4e642fb47e623b6bf1cac to your computer and use it in GitHub Desktop.
skip some parts
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 | |
from swift.container.replicator import ContainerReplicator | |
from swift.common.utils import parse_options | |
from swift.common.daemon import run_daemon | |
from optparse import OptionParser | |
from swift.common import db_replicator | |
from swift.common.utils import list_from_csv | |
orig_roundrobin = db_replicator.roundrobin_datadirs | |
def make_priority_roundrobin(options): | |
devices = list_from_csv(options['devices']) | |
parts = list_from_csv(options['partitions']) | |
def priority_round_robin(datadirs, *args, **kwargs): | |
if devices: | |
datadirs = [(d, n) for (d, n) in datadirs | |
if d.strip('/').rsplit('/', 2)[-2] in devices] | |
for item in orig_roundrobin(datadirs, *args, **kwargs): | |
part = item[0] | |
if parts and part not in parts: | |
continue | |
yield item | |
return priority_round_robin | |
if __name__ == '__main__': | |
parser = OptionParser("%prog CONFIG [options]") | |
parser.add_option('-d', '--devices', | |
help='Replicate only given devices. ' | |
'Comma-separated list') | |
parser.add_option('-p', '--partitions', | |
help='Replicate only given partitions. ' | |
'Comma-separated list') | |
conf_file, options = parse_options(parser=parser, once=True) | |
priority_round_robin = make_priority_roundrobin(options) | |
db_replicator.roundrobin_datadirs = priority_round_robin | |
run_daemon(ContainerReplicator, conf_file, **options) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment