Make swift-get-nodes -a
show all handoffs.
Commit 95786e5 made swift-get-nodes only output N handoff nodes, where N is the ring's replica count. This change leaves that behavior in place as the default, but adds the option -a/--all to print all the handoff nodes. This is handy if you're consuming the output with a script, e.g. if you're doing some analysis of the distribution of primary+handoff nodes for a particular set of things. Change-Id: Ie0253575bb21ccf25559a1c5fd20570a58a2d9fa
This commit is contained in:
parent
cc73f5cbe0
commit
67af56b156
@ -14,6 +14,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import optparse
|
||||||
import sys
|
import sys
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
@ -21,8 +22,13 @@ from swift.common.ring import Ring
|
|||||||
from swift.common.utils import hash_path
|
from swift.common.utils import hash_path
|
||||||
|
|
||||||
|
|
||||||
if len(sys.argv) < 3 or len(sys.argv) > 5:
|
parser = optparse.OptionParser()
|
||||||
print 'Usage: %s <ring.gz> <account> [<container>] [<object>]' \
|
parser.add_option('-a', '--all', action='store_true',
|
||||||
|
help='Show all handoff nodes')
|
||||||
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
|
if len(args) < 2 or len(args) > 4:
|
||||||
|
print 'Usage: %s [-a] <ring.gz> <account> [<container>] [<object>]' \
|
||||||
% sys.argv[0]
|
% sys.argv[0]
|
||||||
print 'Shows the nodes responsible for the item specified.'
|
print 'Shows the nodes responsible for the item specified.'
|
||||||
print 'Example:'
|
print 'Example:'
|
||||||
@ -40,25 +46,25 @@ account = None
|
|||||||
container = None
|
container = None
|
||||||
obj = None
|
obj = None
|
||||||
|
|
||||||
if len(sys.argv) > 4:
|
if len(args) == 4:
|
||||||
# Acount, Container and Object
|
# Account, Container and Object
|
||||||
ring_file, account, container, obj = sys.argv[1:5]
|
ring_file, account, container, obj = args
|
||||||
ring = Ring(ring_file)
|
ring = Ring(ring_file)
|
||||||
hash_str = hash_path(account, container, obj)
|
hash_str = hash_path(account, container, obj)
|
||||||
part, nodes = ring.get_nodes(account, container, obj)
|
part, nodes = ring.get_nodes(account, container, obj)
|
||||||
target = "%s/%s/%s" % (account, container, obj)
|
target = "%s/%s/%s" % (account, container, obj)
|
||||||
loc = 'objects'
|
loc = 'objects'
|
||||||
elif len(sys.argv) > 3:
|
elif len(args) == 3:
|
||||||
# Account, Container
|
# Account, Container
|
||||||
ring_file, account, container = sys.argv[1:4]
|
ring_file, account, container = args
|
||||||
ring = Ring(ring_file)
|
ring = Ring(ring_file)
|
||||||
hash_str = hash_path(account, container)
|
hash_str = hash_path(account, container)
|
||||||
part, nodes = ring.get_nodes(account, container)
|
part, nodes = ring.get_nodes(account, container)
|
||||||
target = "%s/%s" % (account, container)
|
target = "%s/%s" % (account, container)
|
||||||
loc = 'containers'
|
loc = 'containers'
|
||||||
elif len(sys.argv) > 2:
|
elif len(args) == 2:
|
||||||
# Account
|
# Account
|
||||||
ring_file, account = sys.argv[1:3]
|
ring_file, account = args
|
||||||
ring = Ring(ring_file)
|
ring = Ring(ring_file)
|
||||||
hash_str = hash_path(account)
|
hash_str = hash_path(account)
|
||||||
part, nodes = ring.get_nodes(account)
|
part, nodes = ring.get_nodes(account)
|
||||||
@ -68,7 +74,7 @@ elif len(sys.argv) > 2:
|
|||||||
more_nodes = []
|
more_nodes = []
|
||||||
for more_node in ring.get_more_nodes(part):
|
for more_node in ring.get_more_nodes(part):
|
||||||
more_nodes.append(more_node)
|
more_nodes.append(more_node)
|
||||||
if len(more_nodes) >= ring.replica_count:
|
if not options.all and len(more_nodes) >= ring.replica_count:
|
||||||
break
|
break
|
||||||
|
|
||||||
print '\nAccount \t%s' % account
|
print '\nAccount \t%s' % account
|
||||||
|
Loading…
x
Reference in New Issue
Block a user