From 6b441fabd971a39f86223770faed74bc1bdb0bf1 Mon Sep 17 00:00:00 2001 From: Madhuri Kumari Date: Fri, 21 Mar 2014 07:47:21 +0530 Subject: [PATCH] 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 --- bin/swift-container-info | 101 ++++++++++++++++++++++++++++ doc/manpages/swift-container-info.1 | 65 ++++++++++++++++++ doc/manpages/swift-get-nodes.1 | 1 + doc/manpages/swift-object-info.1 | 3 +- doc/source/admin_guide.rst | 4 ++ setup.cfg | 1 + 6 files changed, 174 insertions(+), 1 deletion(-) create mode 100755 bin/swift-container-info create mode 100644 doc/manpages/swift-container-info.1 diff --git a/bin/swift-container-info b/bin/swift-container-info new file mode 100755 index 0000000000..4effb7953e --- /dev/null +++ b/bin/swift-container-info @@ -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) diff --git a/doc/manpages/swift-container-info.1 b/doc/manpages/swift-container-info.1 new file mode 100644 index 0000000000..8872a63ab4 --- /dev/null +++ b/doc/manpages/swift-container-info.1 @@ -0,0 +1,65 @@ +.\" +.\" Author: Madhuri Kumari +.\" 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) diff --git a/doc/manpages/swift-get-nodes.1 b/doc/manpages/swift-get-nodes.1 index cf1f3c2f5d..2055db5d95 100644 --- a/doc/manpages/swift-get-nodes.1 +++ b/doc/manpages/swift-get-nodes.1 @@ -78,5 +78,6 @@ More documentation about Openstack-Swift can be found at .SH "SEE ALSO" +.BR swift-container-info(1), .BR swift-object-info(1), .BR swift-ring-builder(1) diff --git a/doc/manpages/swift-object-info.1 b/doc/manpages/swift-object-info.1 index c89ec7cb98..d9f4131cc7 100644 --- a/doc/manpages/swift-object-info.1 +++ b/doc/manpages/swift-object-info.1 @@ -52,4 +52,5 @@ 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-container-info(1), +.BR swift-get-nodes(1) diff --git a/doc/source/admin_guide.rst b/doc/source/admin_guide.rst index 5ea49f2180..b11a978fa3 100644 --- a/doc/source/admin_guide.rst +++ b/doc/source/admin_guide.rst @@ -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 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 used to crawl the account, checking that all containers and objects can be found. diff --git a/setup.cfg b/setup.cfg index 4fc28dc838..7e1774ba6e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -33,6 +33,7 @@ scripts = bin/swift-account-server bin/swift-config bin/swift-container-auditor + bin/swift-container-info bin/swift-container-replicator bin/swift-container-server bin/swift-container-sync