Mercurial > hg > speedtest
view speedtest/docker_images.py @ 0:26e919a36f86 default tip
speedtest containerized dispatching software
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Thu, 09 Feb 2017 09:47:04 -0800 |
parents | |
children |
line wrap: on
line source
#!/usr/bin/env python """ docker image manipulation """ # imports import argparse import json import sys import docker def main(args=sys.argv[1:]): """CLI""" # parse command line parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--repo', '--respoistory', dest='repository', nargs='?', default=False, const=None, help="select images of this repository (<none> by default)") parser.add_argument('--count', dest='count', action='store_true', default=False, help="print count of images and exit") parser.add_argument('--rm', '--remove', dest='remove', action='store_true', default=False, help="remove selected images") options = parser.parse_args(args) # get images images = docker.images() if not options.repository == False: # select images by repository images = [image for image in images if image['REPOSITORY'] == options.repository] if options.remove: if options.repository == False: parser.error("Cowardly refusing to remove all images") images = [image['IMAGE ID'] for image in images] docker.remove_image(*images) # refresh what we output: # just use all images for now images = docker.images() # output if options.count: print len(images) else: print (json.dumps(images, indent=2)) if __name__ == "__main__": main()