Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #!/usr/bin/env python2.7
  2.  
  3. import docker,sys,os
  4.  
  5. def getsize(path):
  6. """
  7. return human readable filesize given path
  8. """
  9. try:
  10. return e.strerror
  11.  
  12. for unit in ['B','KB','MB','GB','TB']:
  13. if abs(size) < 1024.0:
  14. return "%3.1f%s" % (size, unit)
  15. size /= 1024.0
  16.  
  17. def main():
  18. c = docker.Client(base_url='tcp://127.0.0.1:4243')
  19. c_names = [ i['Names'][0].strip('/') for i in c.containers(all=True) ]
  20.  
  21. min_space = 4
  22. max_space = sorted(len(n) for n in c_names)[-1] + 5
  23.  
  24. print('CONTAINER_ID%sNAME%sLOGSIZE' % \
  25. (min_space * ' ',(max_space - min_space) * ' '))
  26. for name in c_names:
  27. i = c.inspect_container(name)
  28. c_dir = i['HostnamePath'].replace('/hostname', '')
  29. c_logfile = c_dir + '/' + i['Id'] + '-json.log'
  30. print('%s%s%s%s%s' % \
  31. (i['Id'][:12],
  32. min_space * ' ',
  33. name,
  34. (max_space - len(name)) * ' ',
  35. getsize(c_logfile)))
  36.  
  37. if __name__ == '__main__':
  38. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement