Removed hard coded location of ring

In bin/swift-object-info, removed the hard coded location of ring.

Change-Id: Ie328633f5f4de755c9dcc4bb52341bb97087419d
This commit is contained in:
Madhuri Kumari 2014-03-25 14:09:56 +05:30
parent d4a1d75bfc
commit a37f90b3f1
2 changed files with 26 additions and 18 deletions

View File

@ -22,12 +22,15 @@ from optparse import OptionParser
from swift.common.ring import Ring from swift.common.ring import Ring
from swift.obj.diskfile import read_metadata from swift.obj.diskfile import read_metadata
from swift.common.utils import hash_path from swift.common.utils import hash_path, storage_directory
def print_object_info(datafile, check_etag=True): def print_object_info(datafile, check_etag=True, swift_dir='/etc/swift'):
if not os.path.exists(datafile) or not datafile.endswith('.data'):
print "Data file doesn't exist"
sys.exit(1)
try: try:
ring = Ring('/etc/swift/', ring_name='object') ring = Ring(swift_dir, ring_name='object')
except Exception: except Exception:
ring = None ring = None
fp = open(datafile, 'rb') fp = open(datafile, 'rb')
@ -45,13 +48,6 @@ def print_object_info(datafile, check_etag=True):
print ' Object: %s' % obj print ' Object: %s' % obj
obj_hash = hash_path(account, container, obj) obj_hash = hash_path(account, container, obj)
print ' Object hash: %s' % obj_hash print ' Object hash: %s' % obj_hash
if ring is not None:
print 'Ring locations:'
part, nodes = ring.get_nodes(account, container, obj)
for node in nodes:
print (' %s:%s - /srv/node/%s/objects/%s/%s/%s/%s.data' %
(node['ip'], node['port'], node['device'], part,
obj_hash[-3:], obj_hash, ts))
else: else:
print 'Path: Not found in metadata' print 'Path: Not found in metadata'
if content_type: if content_type:
@ -94,24 +90,36 @@ def print_object_info(datafile, check_etag=True):
else: else:
print 'Content-Length: Not found in metadata' print 'Content-Length: Not found in metadata'
print 'User Metadata: %s' % metadata print 'User Metadata: %s' % metadata
print if ring is not None:
print 'note: /srv/node is used as default value of `devices`, the real '\ print 'Ring locations:'
'value is set in object-server.conf on each storage node.' part, nodes = ring.get_nodes(account, container, obj)
for node in nodes:
print (' %s:%s - /srv/node/%s/%s/%s.data' %
(node['ip'], node['port'], node['device'],
storage_directory('objects', part, obj_hash), ts))
print
print 'note: /srv/node is used as default value of `devices`, '\
'the real value is set in object-server.conf '\
'on each storage node.'
fp.close() fp.close()
if __name__ == '__main__': if __name__ == '__main__':
parser = OptionParser() parser = OptionParser()
parser.set_defaults(check_etag=True) parser.set_defaults(check_etag=True, swift_dir='/etc/swift')
parser.add_option( parser.add_option(
'-n', '--no-check-etag', '-n', '--no-check-etag',
action="store_false", dest="check_etag", action="store_false", dest="check_etag",
help="Don't verify file contents against stored etag") help="Don't verify file contents against stored etag")
parser.add_option(
'-d', '--swift-dir',
help="Pass location of swift directory")
options, args = parser.parse_args() options, args = parser.parse_args()
if len(args) < 1: if len(args) < 1:
print "Usage: %s [-n] OBJECT_FILE" % sys.argv[0] print "Usage: %s [-n] [-d] OBJECT_FILE" % sys.argv[0]
sys.exit(1) sys.exit(1)
print_object_info(args[0], check_etag=options.check_etag) print_object_info(args[0], check_etag=options.check_etag,
swift_dir=options.swift_dir)

View File

@ -25,7 +25,7 @@
.SH SYNOPSIS .SH SYNOPSIS
.LP .LP
.B swift-object-info .B swift-object-info
[OBJECT_FILE] [OBJECT_FILE] [SWIFT_DIR]
.SH DESCRIPTION .SH DESCRIPTION
.PP .PP
@ -38,12 +38,12 @@ It will then return several information about that object such as;
.IP "- Account it belongs to" .IP "- Account it belongs to"
.IP "- Container " .IP "- Container "
.IP "- Object hash " .IP "- Object hash "
.IP "- Location on the ring "
.IP "- Content Type " .IP "- Content Type "
.IP "- timestamp " .IP "- timestamp "
.IP "- Etag " .IP "- Etag "
.IP "- Content Length " .IP "- Content Length "
.IP "- User Metadata " .IP "- User Metadata "
.IP "- Location on the ring "
.PD .PD
.SH DOCUMENTATION .SH DOCUMENTATION