def stat_container(conn, options, container): req_headers = split_request_headers(options.get('header', [])) headers = conn.head_container(container, headers=req_headers) items = [] if options['verbose'] > 1: path = '%s/%s' % (conn.url, container) items.extend([ ('URL', path), ('Auth Token', conn.token) ]) object_count = prt_bytes( headers.get('x-container-object-count', 0), options['human']).lstrip() bytes_used = prt_bytes(headers.get('x-container-bytes-used', 0), options['human']).lstrip() items.extend([ ('Account', conn.url.rsplit('/', 1)[-1]), ('Container', container), ('Objects', object_count), ('Bytes', bytes_used), ('Read ACL', headers.get('x-container-read', '')), ('Write ACL', headers.get('x-container-write', '')), ('Sync To', headers.get('x-container-sync-to', '')), ('Sync Key', headers.get('x-container-sync-key', '')) ]) return items, headers
def stat_account(conn, options): items = [] req_headers = split_request_headers(options.get('header', [])) headers = conn.head_account(headers=req_headers) if options['verbose'] > 1: items.extend([ ('StorageURL', conn.url), ('Auth Token', conn.token), ]) container_count = int(headers.get('x-account-container-count', 0)) object_count = prt_bytes(headers.get('x-account-object-count', 0), options['human']).lstrip() bytes_used = prt_bytes(headers.get('x-account-bytes-used', 0), options['human']).lstrip() items.extend([ ('Account', conn.url.rsplit('/', 1)[-1]), ('Containers', container_count), ('Objects', object_count), ('Bytes', bytes_used), ]) policies = set() for header_key, header_value in headers.items(): if header_key.lower().startswith(POLICY_HEADER_PREFIX): policy_name = header_key.rsplit('-', 2)[0].split('-', 4)[-1] policies.add(policy_name) for policy in policies: container_count_header = (POLICY_HEADER_PREFIX + policy + '-container-count') if container_count_header in headers: items.append( ('Containers in policy "' + policy + '"', prt_bytes(headers[container_count_header], options['human']).lstrip()) ) items.extend(( ('Objects in policy "' + policy + '"', prt_bytes( headers.get( POLICY_HEADER_PREFIX + policy + '-object-count', 0), options['human'] ).lstrip()), ('Bytes in policy "' + policy + '"', prt_bytes( headers.get( POLICY_HEADER_PREFIX + policy + '-bytes-used', 0), options['human'] ).lstrip()), )) return items, headers
def stat_account(conn, options): items = [] req_headers = split_request_headers(options.get('header', [])) headers = conn.head_account(headers=req_headers) if options['verbose'] > 1: items.extend([ ('StorageURL', conn.url), ('Auth Token', conn.token), ]) container_count = int(headers.get('x-account-container-count', 0)) object_count = prt_bytes(headers.get('x-account-object-count', 0), options['human']).lstrip() bytes_used = prt_bytes(headers.get('x-account-bytes-used', 0), options['human']).lstrip() items.extend([ ('Account', conn.url.rsplit('/', 1)[-1]), ('Containers', container_count), ('Objects', object_count), ('Bytes', bytes_used), ]) policies = set() for header_key, header_value in headers.items(): if header_key.lower().startswith(POLICY_HEADER_PREFIX): policy_name = header_key.rsplit('-', 2)[0].split('-', 4)[-1] policies.add(policy_name) for policy in policies: container_count_header = (POLICY_HEADER_PREFIX + policy + '-container-count') if container_count_header in headers: items.append(('Containers in policy "' + policy + '"', prt_bytes(headers[container_count_header], options['human']).lstrip())) items.extend(( ('Objects in policy "' + policy + '"', prt_bytes( headers.get(POLICY_HEADER_PREFIX + policy + '-object-count', 0), options['human']).lstrip()), ('Bytes in policy "' + policy + '"', prt_bytes( headers.get(POLICY_HEADER_PREFIX + policy + '-bytes-used', 0), options['human']).lstrip()), )) return items, headers
def stat_object(conn, options, container, obj): req_headers = split_request_headers(options.get('header', [])) headers = conn.head_object(container, obj, headers=req_headers) items = [] if options['verbose'] > 1: path = '%s/%s/%s' % (conn.url, container, obj) items.extend([('URL', path), ('Auth Token', conn.token)]) content_length = prt_bytes(headers.get('content-length', 0), options['human']).lstrip() items.extend([('Account', conn.url.rsplit('/', 1)[-1]), ('Container', container), ('Object', obj), ('Content Type', headers.get('content-type')), ('Content Length', content_length), ('Last Modified', headers.get('last-modified')), ('ETag', headers.get('etag')), ('Manifest', headers.get('x-object-manifest'))]) return items, headers
def stat_container(conn, options, container): req_headers = split_request_headers(options.get('header', [])) headers = conn.head_container(container, headers=req_headers) items = [] if options['verbose'] > 1: path = '%s/%s' % (conn.url, container) items.extend([('URL', path), ('Auth Token', conn.token)]) object_count = prt_bytes(headers.get('x-container-object-count', 0), options['human']).lstrip() bytes_used = prt_bytes(headers.get('x-container-bytes-used', 0), options['human']).lstrip() items.extend([('Account', conn.url.rsplit('/', 1)[-1]), ('Container', container), ('Objects', object_count), ('Bytes', bytes_used), ('Read ACL', headers.get('x-container-read', '')), ('Write ACL', headers.get('x-container-write', '')), ('Sync To', headers.get('x-container-sync-to', '')), ('Sync Key', headers.get('x-container-sync-key', ''))]) return items, headers
def stat_object(conn, options, container, obj): req_headers = split_request_headers(options.get('header', [])) headers = conn.head_object(container, obj, headers=req_headers) items = [] if options['verbose'] > 1: path = '%s/%s/%s' % (conn.url, container, obj) items.extend([ ('URL', path), ('Auth Token', conn.token) ]) content_length = prt_bytes(headers.get('content-length', 0), options['human']).lstrip() items.extend([ ('Account', conn.url.rsplit('/', 1)[-1]), ('Container', container), ('Object', obj), ('Content Type', headers.get('content-type')), ('Content Length', content_length), ('Last Modified', headers.get('last-modified')), ('ETag', headers.get('etag')), ('Manifest', headers.get('x-object-manifest')) ]) return items, headers