Merge "Adjust swift_rings.py to work on specified regions"
This commit is contained in:
commit
8a4fa2a080
@ -24,7 +24,7 @@ import sys
|
|||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
|
||||||
USAGE = "usage: %prog -f <swift_ring.contents>"
|
USAGE = "usage: %prog -f <swift_ring.contents> -r <managed_region>"
|
||||||
|
|
||||||
DEVICE_KEY = "%(ip)s:%(port)d/%(device)s"
|
DEVICE_KEY = "%(ip)s:%(port)d/%(device)s"
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ def get_build_file_data(build_file):
|
|||||||
|
|
||||||
|
|
||||||
def build_ring(build_name, repl, min_part_hours, part_power, hosts,
|
def build_ring(build_name, repl, min_part_hours, part_power, hosts,
|
||||||
validate=False):
|
region=None, validate=False):
|
||||||
# Create the build file
|
# Create the build file
|
||||||
build_file = "%s.builder" % build_name
|
build_file = "%s.builder" % build_name
|
||||||
build_file_data = get_build_file_data(build_file)
|
build_file_data = get_build_file_data(build_file)
|
||||||
@ -169,16 +169,18 @@ def build_ring(build_name, repl, min_part_hours, part_power, hosts,
|
|||||||
if update:
|
if update:
|
||||||
for i, dev in enumerate(build_file_data['devs']):
|
for i, dev in enumerate(build_file_data['devs']):
|
||||||
if dev is not None:
|
if dev is not None:
|
||||||
old_hosts[DEVICE_KEY % dev] = i
|
if region is None or int(region) == int(dev['region']):
|
||||||
|
old_hosts[DEVICE_KEY % dev] = i
|
||||||
for host in hosts:
|
for host in hosts:
|
||||||
host_key = DEVICE_KEY % host
|
host_key = DEVICE_KEY % host
|
||||||
if host_key in old_hosts:
|
if region is None or int(region) == int(host['region']):
|
||||||
old_host = build_file_data['devs'][old_hosts[host_key]]
|
if host_key in old_hosts:
|
||||||
update_host_in_ring(build_file, host, old_host,
|
old_host = build_file_data['devs'][old_hosts[host_key]]
|
||||||
validate=validate)
|
update_host_in_ring(build_file, host, old_host,
|
||||||
old_hosts.pop(host_key)
|
validate=validate)
|
||||||
else:
|
old_hosts.pop(host_key)
|
||||||
add_host_to_ring(build_file, host, validate=validate)
|
else:
|
||||||
|
add_host_to_ring(build_file, host, validate=validate)
|
||||||
|
|
||||||
if old_hosts and not validate:
|
if old_hosts and not validate:
|
||||||
# There are still old hosts, these hosts must've been removed
|
# There are still old hosts, these hosts must've been removed
|
||||||
@ -197,7 +199,7 @@ def build_ring(build_name, repl, min_part_hours, part_power, hosts,
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def main(setup):
|
def main(setup, region):
|
||||||
# load the json file
|
# load the json file
|
||||||
try:
|
try:
|
||||||
with open(setup) as json_stream:
|
with open(setup) as json_stream:
|
||||||
@ -207,7 +209,7 @@ def main(setup):
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
hosts = _contents_file['drives']
|
hosts = _contents_file['drives']
|
||||||
kargs = {'validate': True, 'hosts': hosts}
|
kargs = {'validate': True, 'hosts': hosts, 'region': region}
|
||||||
ring_call = [
|
ring_call = [
|
||||||
_contents_file['builder_file'],
|
_contents_file['builder_file'],
|
||||||
_contents_file['repl_number'],
|
_contents_file['repl_number'],
|
||||||
@ -235,6 +237,14 @@ if __name__ == "__main__":
|
|||||||
help="Specify the swift ring contents file.",
|
help="Specify the swift ring contents file.",
|
||||||
metavar="FILE"
|
metavar="FILE"
|
||||||
)
|
)
|
||||||
|
parser.add_option(
|
||||||
|
"-r",
|
||||||
|
"--region",
|
||||||
|
help="Specify the region to manage for the ring file.",
|
||||||
|
dest="region",
|
||||||
|
type='int',
|
||||||
|
metavar="REGION"
|
||||||
|
)
|
||||||
|
|
||||||
options, _args = parser.parse_args(sys.argv[1:])
|
options, _args = parser.parse_args(sys.argv[1:])
|
||||||
if options.setup and not exists(options.setup):
|
if options.setup and not exists(options.setup):
|
||||||
@ -242,4 +252,4 @@ if __name__ == "__main__":
|
|||||||
parser.print_help()
|
parser.print_help()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
sys.exit(main(options.setup))
|
sys.exit(main(options.setup, options.region))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user