Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python2.7
- import docker,sys,os
- def getsize(path):
- """
- return human readable filesize given path
- """
- try:
- return e.strerror
- for unit in ['B','KB','MB','GB','TB']:
- if abs(size) < 1024.0:
- return "%3.1f%s" % (size, unit)
- size /= 1024.0
- def main():
- c = docker.Client(base_url='tcp://127.0.0.1:4243')
- c_names = [ i['Names'][0].strip('/') for i in c.containers(all=True) ]
- min_space = 4
- max_space = sorted(len(n) for n in c_names)[-1] + 5
- print('CONTAINER_ID%sNAME%sLOGSIZE' % \
- (min_space * ' ',(max_space - min_space) * ' '))
- for name in c_names:
- i = c.inspect_container(name)
- c_dir = i['HostnamePath'].replace('/hostname', '')
- c_logfile = c_dir + '/' + i['Id'] + '-json.log'
- print('%s%s%s%s%s' % \
- (i['Id'][:12],
- min_space * ' ',
- name,
- (max_space - len(name)) * ' ',
- getsize(c_logfile)))
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement