def list_on_image(imagename, category): psfilter = ps_filter(imagename) if category == "containers": print_call(["docker", "ps", "-a"]+psfilter) elif category == "running": print_call(["docker", "ps"]+psfilter) elif category == "images": # list of images associated with image name imagelist = get_image_list_for(imagename) # list of all images res,sout,serr = run.call(["docker", "images"], silent=True) stringlines = sout.strip().split(os.linesep) # header print("Relevant images: %s" % ', '.join(imagelist) ) print(stringlines[0]) # full image line, if image is in imagelist for line in filter_string_lines(stringlines, imagelist): print(line) elif category == "last" or category == "stable": print(store.read_data(category, imagename)) elif category == "jcl": print(store.read_data("jockler-%s"%imagename, imagename)) else: unknown_category(category)
def start(args): if len(args) >= 2: instance = args[0] imagename = args[1] doattach = common.item(args, 2, False) if doattach == "attach": doattach=True if not instance in ["new", "last", "stable"]: common.fail("Incorrect instance name. Please use 'new', 'last', or 'stable' ") if instance == "new": containername = start_new_container(imagename, doattach) else: containername = store.read_data(instance, imagename) if containername: start_container(imagename, containername, doattach) else: common.fail("No instance %s for image %s"%(instance, imagename)) elif len(args) == 1: containername = args[0] imagename = extract_image_name(containername) if imagename: start_container(imagename, containername) else: common.fail("Unknown. Use 'jockler start {new|last|stable} IMAGE' or 'jockler start CONTAINER'")
def list_container_volumes(imagename, instance): if not instance in ["stable", "last"]: common.fail("Invalid instance [%s] - use last or stable" % instance) containername = store.read_data(instance, imagename) if not containername: common.fail("No candidate [%s] for image [%s]" % (instance, imagename)) print(os.linesep.join(mountdata_of(containername, "Name")))
def append_image_id(imagename, image_id): imagelist = store.read_data("images", imagename) if imagelist == None: imagelist = '' imagelist = imagelist.split(os.linesep) imagelist.append(image_id) common.remove_empty_strings(imagelist) imagelist = list(set(imagelist)) store.write_data("images", imagename, os.linesep.join(imagelist))
def get_image_list_for(imagename): #res,sout,serr = run.call(["docker", "ps", "-a", "--format", "{{.Image}}"] + ps_filter(imagename), silent=True) # #images = sout.strip().split(os.linesep) #common.remove_empty_strings(images) images = store.read_data("images", imagename) if not images: return [] images = list(set(images.split(os.linesep))) return images
def cleanup(args): if not common.args_check(args, 1): common.fail( "Remove all old containers and images, except for last and stable.\n\nUsage:\n\n jockler cleanup IMAGENAME" ) imagename = args[0] keep_images = [] keep_containers = [] for instance in ["stable", "last"]: container = store.read_data(instance, imagename) if container: keep_images.append(imagename) keep_containers.append(container) remove([imagename], keep_images, keep_containers)
def do_volume_backup(imagename, systemname, destination="."): containername = store.read_data("last", imagename) if not containername: common.fail("No candidate container for image [%s]" % imagename) destination = os.path.abspath(destination) mountpoints = volumes.mountdata_of(containername, "Destination") archivename = "%s-as-of-%s.tar.gz" % (containername, common.timestring()) if systemname == "linux": res, sout, serr = do_linux_volume_backup(containername, destination, archivename, mountpoints) elif systemname == "windows": #TODO - need a windows version common.fail("Not yet implemented") else: common.fail("Unkown system type [%s]" % systemname) if res == 0: print("Backup created in %s" % os.path.sep.join([destination, archivename])) else: common.fail("Backup operation failed!")
def print_stable_container(imagename): containername = store.read_data("stable", imagename) if containername: print(containername) else: print("No stable container marked for image [%s]"%imagename)
def read_options_file(imagename): jclfile = jcl_name(imagename) return store.read_data(jclfile, imagename)