From e415e4d23572ba6cedf4d2303a7a1a069eb92b36 Mon Sep 17 00:00:00 2001 From: gholt Date: Thu, 25 Oct 2012 17:47:01 +0000 Subject: [PATCH] Added partition option to swift-get-nodes Sometimes you just want to know what machines a given partition should be on, or what handoffs that partition would use if needed. We've been meaning to add this option to swift-get-nodes for quite some time, but I just finally got to it. Example: swift-get-nodes /etc/swift/object.ring.gz -p 123 I tried to leave as much of the existing swift-get-nodes unaltered, so the output isn't exactly distilled to just what you'd need for getting a partition's nodes. But it should suffice for what it is, an admin tool. Change-Id: I438400ddc0eecbf9c48266e7f38a2e4f0765f374 --- bin/swift-get-nodes | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/bin/swift-get-nodes b/bin/swift-get-nodes index db7d078841..129562518a 100755 --- a/bin/swift-get-nodes +++ b/bin/swift-get-nodes @@ -25,11 +25,15 @@ from swift.common.utils import hash_path parser = optparse.OptionParser() parser.add_option('-a', '--all', action='store_true', help='Show all handoff nodes') +parser.add_option('-p', '--partition', metavar='PARTITION', + help='Show nodes for a given partition') (options, args) = parser.parse_args() -if len(args) < 2 or len(args) > 4: +if (len(args) < 2 or len(args) > 4) and \ + (options.partition is None or not args): print 'Usage: %s [-a] [] []' \ % sys.argv[0] + print ' Or: %s [-a] -p partition' % sys.argv[0] print 'Shows the nodes responsible for the item specified.' print 'Example:' print ' $ %s /etc/swift/account.ring.gz MyAccount' % sys.argv[0] @@ -70,6 +74,19 @@ elif len(args) == 2: part, nodes = ring.get_nodes(account) target = "%s" % (account) loc = 'accounts' +elif len(args) == 1: + # Partition + ring_file = args[0] + ring = Ring(ring_file) + hash_str = None + part = int(options.partition) + nodes = ring.get_part_nodes(part) + target = '' + loc = ring_file.rsplit('/', 1)[-1].split('.', 1)[0] + if loc in ('account', 'container', 'object'): + loc += 's' + else: + loc = '' more_nodes = [] for more_node in ring.get_more_nodes(part): @@ -100,8 +117,16 @@ for mnode in more_nodes: urllib.quote(target)) print "\n" for node in nodes: - print 'ssh %s "ls -lah /srv/node/%s/%s/%s/%s/%s/"' \ - % (node['ip'], node['device'], loc, part, hash_str[-3:], hash_str) + if hash_str: + print 'ssh %s "ls -lah /srv/node/%s/%s/%s/%s/%s/"' % ( + node['ip'], node['device'], loc, part, hash_str[-3:], hash_str) + else: + print 'ssh %s "ls -lah /srv/node/%s/%s/%s/"' % ( + node['ip'], node['device'], loc, part) for mnode in more_nodes: - print 'ssh %s "ls -lah /srv/node/%s/%s/%s/%s/%s/" # [Handoff]' \ - % (mnode['ip'], mnode['device'], loc, part, hash_str[-3:], hash_str) + if hash_str: + print 'ssh %s "ls -lah /srv/node/%s/%s/%s/%s/%s/" # [Handoff]' % ( + mnode['ip'], mnode['device'], loc, part, hash_str[-3:], hash_str) + else: + print 'ssh %s "ls -lah /srv/node/%s/%s/%s/" # [Handoff]' % ( + mnode['ip'], mnode['device'], loc, part)