Added swift-container-info tool.
This is a very simple swift tool to retrieve information of a container that is located on the storage node. One can call the tool with a given container db file as it is stored on the storage node system. It will then return several information about that container. Change-Id: Ifebaed6c51a9ed5fbc0e7572bb43ef05d7dd254b
This commit is contained in:
parent
d4a1d75bfc
commit
6b441fabd9
101
bin/swift-container-info
Executable file
101
bin/swift-container-info
Executable file
@ -0,0 +1,101 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
# implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from datetime import datetime
|
||||||
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
from swift.common.ring import Ring
|
||||||
|
from swift.common.utils import hash_path, storage_directory
|
||||||
|
from swift.container.backend import ContainerBroker
|
||||||
|
|
||||||
|
|
||||||
|
def print_container_info(db_file, swift_dir='/etc/swift'):
|
||||||
|
if not os.path.exists(db_file) or not db_file.endswith('.db'):
|
||||||
|
print "DB file doesn't exist"
|
||||||
|
sys.exit(1)
|
||||||
|
try:
|
||||||
|
ring = Ring(swift_dir, ring_name='container')
|
||||||
|
except Exception:
|
||||||
|
ring = None
|
||||||
|
metadata = {}
|
||||||
|
broker = ContainerBroker(db_file)
|
||||||
|
for key, (value, timestamp) in broker.metadata.iteritems():
|
||||||
|
metadata[key] = value
|
||||||
|
info = broker.get_info()
|
||||||
|
account = info['account']
|
||||||
|
container = info['container']
|
||||||
|
container_hash = hash_path(account, container)
|
||||||
|
print ' Account: %s' % info['account']
|
||||||
|
print ' Container: %s' % info['container']
|
||||||
|
print ' Container_hash: %s' % container_hash
|
||||||
|
print (' Created at: %s (%s)' %
|
||||||
|
(datetime.fromtimestamp(float(info['created_at'])),
|
||||||
|
info['created_at']))
|
||||||
|
print (' Put Timestamp: %s (%s)' %
|
||||||
|
(datetime.fromtimestamp(float(info['put_timestamp'])),
|
||||||
|
info['put_timestamp']))
|
||||||
|
print (' Delete Timestamp: %s (%s)' %
|
||||||
|
(datetime.fromtimestamp(float(info['delete_timestamp'])),
|
||||||
|
info['delete_timestamp']))
|
||||||
|
print ' Object Count: %s' % info['object_count']
|
||||||
|
print ' Bytes Used: %s' % info['bytes_used']
|
||||||
|
print (' Reported Put Timestamp: %s (%s)' %
|
||||||
|
(datetime.fromtimestamp(float(info['reported_put_timestamp'])),
|
||||||
|
info['reported_put_timestamp']))
|
||||||
|
print (' Reported Delete Timestamp: %s (%s)' %
|
||||||
|
(datetime.fromtimestamp(float(info['reported_delete_timestamp'])),
|
||||||
|
info['reported_delete_timestamp']))
|
||||||
|
print ' Reported Object Count: %s' % info['reported_object_count']
|
||||||
|
print ' Reported Bytes Used: %s' % info['reported_bytes_used']
|
||||||
|
print ' Chexor: %s' % info['hash']
|
||||||
|
print ' ID: %s' % info['id']
|
||||||
|
|
||||||
|
for key, value in info.iteritems():
|
||||||
|
if key.lower().startswith('x_container_'):
|
||||||
|
key = "-".join(key.split('_')).title()
|
||||||
|
print ' %s: %s' % (key, value)
|
||||||
|
if metadata:
|
||||||
|
print ' User Metadata: %s' % metadata
|
||||||
|
print
|
||||||
|
else:
|
||||||
|
print 'No user metadata found in db file'
|
||||||
|
print
|
||||||
|
|
||||||
|
if ring is not None:
|
||||||
|
print 'Ring locations:'
|
||||||
|
part, nodes = ring.get_nodes(account, container)
|
||||||
|
for node in nodes:
|
||||||
|
print (' %s:%s - /srv/node/%s/%s/%s.db' %
|
||||||
|
(node['ip'], node['port'], node['device'],
|
||||||
|
storage_directory('containers', part, container_hash),
|
||||||
|
container_hash))
|
||||||
|
print
|
||||||
|
print 'note: /srv/node is used as default value of `devices`, the real '\
|
||||||
|
'value is set in container-server.conf on each storage node.'
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
parser = OptionParser()
|
||||||
|
parser.set_defaults(swift_dir='/etc/swift')
|
||||||
|
parser.add_option(
|
||||||
|
'-d', '--swift-dir',
|
||||||
|
help="Pass location of swift directory")
|
||||||
|
|
||||||
|
options, args = parser.parse_args()
|
||||||
|
|
||||||
|
if len(sys.argv) <= 1:
|
||||||
|
print "Usage: %s [--swift-dir] CONTAINER_DB_FILE" % sys.argv[0]
|
||||||
|
sys.exit(1)
|
||||||
|
print_container_info(args[0], swift_dir=options.swift_dir)
|
65
doc/manpages/swift-container-info.1
Normal file
65
doc/manpages/swift-container-info.1
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
.\"
|
||||||
|
.\" Author: Madhuri Kumari <madhuri.rai07@gmail.com>
|
||||||
|
.\" Copyright (c) 2010-2011 OpenStack Foundation.
|
||||||
|
.\"
|
||||||
|
.\" Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
.\" you may not use this file except in compliance with the License.
|
||||||
|
.\" You may obtain a copy of the License at
|
||||||
|
.\"
|
||||||
|
.\" http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
.\"
|
||||||
|
.\" Unless required by applicable law or agreed to in writing, software
|
||||||
|
.\" distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
.\" WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
.\" implied.
|
||||||
|
.\" See the License for the specific language governing permissions and
|
||||||
|
.\" limitations under the License.
|
||||||
|
.\"
|
||||||
|
.TH swift-container-info 1 "3/20/2013" "Linux" "OpenStack Swift"
|
||||||
|
|
||||||
|
.SH NAME
|
||||||
|
.LP
|
||||||
|
.B swift-container-info
|
||||||
|
\- Openstack-swift container-info tool
|
||||||
|
|
||||||
|
.SH SYNOPSIS
|
||||||
|
.LP
|
||||||
|
.B swift-container-info
|
||||||
|
[CONTAINER_DB_FILE] [SWIFT_DIR]
|
||||||
|
|
||||||
|
.SH DESCRIPTION
|
||||||
|
.PP
|
||||||
|
This is a very simple swift tool that allows a swiftop engineer to retrieve
|
||||||
|
information about a container that is located on the storage node.
|
||||||
|
One calls the tool with a given container db file as
|
||||||
|
it is stored on the storage node system.
|
||||||
|
It will then return several information about that container such as;
|
||||||
|
|
||||||
|
.PD 0
|
||||||
|
.IP "- Account it belongs to"
|
||||||
|
.IP "- Container "
|
||||||
|
.IP "- Created timestamp "
|
||||||
|
.IP "- Put timestamp "
|
||||||
|
.IP "- Delete timestamp "
|
||||||
|
.IP "- Object count "
|
||||||
|
.IP "- Bytes used "
|
||||||
|
.IP "- Reported put timestamp "
|
||||||
|
.IP "- Reported delete timestamp "
|
||||||
|
.IP "- Reported object count "
|
||||||
|
.IP "- Reported bytes used "
|
||||||
|
.IP "- Hash "
|
||||||
|
.IP "- ID "
|
||||||
|
.IP "- User metadata "
|
||||||
|
.IP "- X-Container-Sync-Point 1 "
|
||||||
|
.IP "- X-Container-Sync-Point 2 "
|
||||||
|
.IP "- Location on the ring "
|
||||||
|
.PD
|
||||||
|
|
||||||
|
.SH DOCUMENTATION
|
||||||
|
.LP
|
||||||
|
More documentation about Openstack-Swift can be found at
|
||||||
|
.BI http://swift.openstack.org/index.html
|
||||||
|
|
||||||
|
.SH "SEE ALSO"
|
||||||
|
.BR swift-get-nodes(1),
|
||||||
|
.BR swift-object-info(1)
|
@ -78,5 +78,6 @@ More documentation about Openstack-Swift can be found at
|
|||||||
|
|
||||||
|
|
||||||
.SH "SEE ALSO"
|
.SH "SEE ALSO"
|
||||||
|
.BR swift-container-info(1),
|
||||||
.BR swift-object-info(1),
|
.BR swift-object-info(1),
|
||||||
.BR swift-ring-builder(1)
|
.BR swift-ring-builder(1)
|
||||||
|
@ -52,4 +52,5 @@ More documentation about Openstack-Swift can be found at
|
|||||||
.BI http://swift.openstack.org/index.html
|
.BI http://swift.openstack.org/index.html
|
||||||
|
|
||||||
.SH "SEE ALSO"
|
.SH "SEE ALSO"
|
||||||
.BR swift-get-nodes(1),
|
.BR swift-container-info(1),
|
||||||
|
.BR swift-get-nodes(1)
|
||||||
|
@ -1029,6 +1029,10 @@ If you are looking at an object on the server and need more info,
|
|||||||
`swift-object-info` will display the account, container, replica locations
|
`swift-object-info` will display the account, container, replica locations
|
||||||
and metadata of the object.
|
and metadata of the object.
|
||||||
|
|
||||||
|
If you are looking at a container on the server and need more info,
|
||||||
|
`swift-container-info` will display all the information like the account,
|
||||||
|
container, replica locations and metadata of the container.
|
||||||
|
|
||||||
If you want to audit the data for an account, `swift-account-audit` can be
|
If you want to audit the data for an account, `swift-account-audit` can be
|
||||||
used to crawl the account, checking that all containers and objects can be
|
used to crawl the account, checking that all containers and objects can be
|
||||||
found.
|
found.
|
||||||
|
@ -33,6 +33,7 @@ scripts =
|
|||||||
bin/swift-account-server
|
bin/swift-account-server
|
||||||
bin/swift-config
|
bin/swift-config
|
||||||
bin/swift-container-auditor
|
bin/swift-container-auditor
|
||||||
|
bin/swift-container-info
|
||||||
bin/swift-container-replicator
|
bin/swift-container-replicator
|
||||||
bin/swift-container-server
|
bin/swift-container-server
|
||||||
bin/swift-container-sync
|
bin/swift-container-sync
|
||||||
|
Loading…
Reference in New Issue
Block a user