diff --git a/bin/swift-get-nodes b/bin/swift-get-nodes index 166a64e7e7..db7d078841 100755 --- a/bin/swift-get-nodes +++ b/bin/swift-get-nodes @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import optparse import sys import urllib @@ -21,8 +22,13 @@ from swift.common.ring import Ring from swift.common.utils import hash_path -if len(sys.argv) < 3 or len(sys.argv) > 5: - print 'Usage: %s [] []' \ +parser = optparse.OptionParser() +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] [] []' \ % sys.argv[0] print 'Shows the nodes responsible for the item specified.' print 'Example:' @@ -40,25 +46,25 @@ account = None container = None obj = None -if len(sys.argv) > 4: - # Acount, Container and Object - ring_file, account, container, obj = sys.argv[1:5] +if len(args) == 4: + # Account, Container and Object + ring_file, account, container, obj = args ring = Ring(ring_file) hash_str = hash_path(account, container, obj) part, nodes = ring.get_nodes(account, container, obj) target = "%s/%s/%s" % (account, container, obj) loc = 'objects' -elif len(sys.argv) > 3: +elif len(args) == 3: # Account, Container - ring_file, account, container = sys.argv[1:4] + ring_file, account, container = args ring = Ring(ring_file) hash_str = hash_path(account, container) part, nodes = ring.get_nodes(account, container) target = "%s/%s" % (account, container) loc = 'containers' -elif len(sys.argv) > 2: +elif len(args) == 2: # Account - ring_file, account = sys.argv[1:3] + ring_file, account = args ring = Ring(ring_file) hash_str = hash_path(account) part, nodes = ring.get_nodes(account) @@ -68,7 +74,7 @@ elif len(sys.argv) > 2: more_nodes = [] for more_node in ring.get_more_nodes(part): more_nodes.append(more_node) - if len(more_nodes) >= ring.replica_count: + if not options.all and len(more_nodes) >= ring.replica_count: break print '\nAccount \t%s' % account