summaryrefslogtreecommitdiff
path: root/swiftclient/command_helpers.py
diff options
context:
space:
mode:
authorYuan Zhou <yuan.zhou@intel.com>2014-07-31 19:51:50 +0800
committerYuan Zhou <yuan.zhou@intel.com>2014-08-06 16:07:17 +0800
commit776133bd299adfb644f2274143b9fba72672428d (patch)
tree2d76f05f20192657353e2445fe1f082aedcb4d6c /swiftclient/command_helpers.py
parentfd1594937d777c0047051ae470e2de5523522171 (diff)
downloadpython-swiftclient-776133bd299adfb644f2274143b9fba72672428d.tar.gz
Clean up raw policy stats in account stat
Storage policy stats was not well parsed in account stat. This patch parses the stats and print out the stats in a format like below: $swift -A http://swift_cluster/auth/v1.0 -U test:tester -K testing stat Account: AUTH_test Containers: 5 Objects: 1 Bytes: 2097152 Objects in policy "golden": 1 Bytess in policy "golden": 2097152 Objects in policy "silver": 0 Bytes in policy "silver": 0 X-Timestamp: 1404697760.88809 X-Trans-Id: txec519e24b44a413abb705-0053da2dcb Content-Type: text/plain; charset=utf-8 Accept-Ranges: bytes Change-Id: I7ad0ee6d88f8393e3a93e90cd52b9b592da7072d
Diffstat (limited to 'swiftclient/command_helpers.py')
-rw-r--r--swiftclient/command_helpers.py41
1 files changed, 32 insertions, 9 deletions
diff --git a/swiftclient/command_helpers.py b/swiftclient/command_helpers.py
index 0c81cb6..ef18636 100644
--- a/swiftclient/command_helpers.py
+++ b/swiftclient/command_helpers.py
@@ -15,9 +15,11 @@ from swiftclient.utils import prt_bytes
def stat_account(conn, options, thread_manager):
+ items_to_print = []
+
headers = conn.head_account()
if options.verbose > 1:
- thread_manager.print_items((
+ items_to_print.extend((
('StorageURL', conn.url),
('Auth Token', conn.token),
))
@@ -26,19 +28,40 @@ def stat_account(conn, options, thread_manager):
options.human).lstrip()
bytes_used = prt_bytes(headers.get('x-account-bytes-used', 0),
options.human).lstrip()
- thread_manager.print_items((
+ items_to_print.extend((
('Account', conn.url.rsplit('/', 1)[-1]),
('Containers', container_count),
('Objects', object_count),
('Bytes', bytes_used),
))
- thread_manager.print_headers(headers,
- meta_prefix='x-account-meta-',
- exclude_headers=(
- 'content-length', 'date',
- 'x-account-container-count',
- 'x-account-object-count',
- 'x-account-bytes-used'))
+ policies = set()
+ exclude_policy_headers = []
+ ps_header_prefix = 'x-account-storage-policy-'
+ for header_key, header_value in headers.items():
+ if header_key.lower().startswith(ps_header_prefix):
+ policy_name = header_key.rsplit('-', 2)[0].split('-', 4)[-1]
+ policies.add(policy_name)
+ exclude_policy_headers.append(header_key)
+ for policy in policies:
+ items_to_print.extend((
+ ('Objects in policy "' + policy + '"',
+ prt_bytes(headers.get(ps_header_prefix + policy + '-object-count',
+ 0), options.human).lstrip()),
+ ('Bytes in policy "' + policy + '"',
+ prt_bytes(headers.get(ps_header_prefix + policy + '-bytes-used',
+ 0), options.human).lstrip()),
+ ))
+
+ items_to_print.extend(thread_manager.headers_to_items(
+ headers, meta_prefix='x-account-meta-',
+ exclude_headers=([
+ 'content-length', 'date',
+ 'x-account-container-count',
+ 'x-account-object-count',
+ 'x-account-bytes-used'] + exclude_policy_headers)))
+ # line up the items nicely
+ offset = max(len(item) for item, value in items_to_print)
+ thread_manager.print_items(items_to_print, offset=offset)
def stat_container(conn, options, args, thread_manager):