diff --git a/createhdds.py b/createhdds.py index e291ad1..f2e3112 100755 --- a/createhdds.py +++ b/createhdds.py @@ -657,29 +657,35 @@ def check(hdds, nextrel=None): def cli_all(args, hdds): """Function for the CLI 'all' subcommand. Creates all images. If - args.delete is set, blows all existing images away and recreates - them; otherwise it will just fill in missing or outdated images. - If args.clean is set, also wipes 'unknown' images. + args.force is set, rebuild all images; otherwise it will just fill + in missing or outdated images. If args.clean is set, also wipes + 'unknown' images. If args.rel is non-zero, operation is limited to + the specified release number; implicitly, images without a release + number (i.e. guestfs images) are skipped. """ - if args.delete: - logger.info("Removing all images...") - delete_all() - # handle renamed images (see do_renames docstring) do_renames(hdds) - # call check() to find out what we need to do + # call check() to find missing, outdated, unknown images (missing, outdated, unknown) = check(hdds, nextrel=args.nextrel) + if args.force or args.delete: + # rebuild all images + todo = get_all_images(hdds, nextrel=args.nextrel) + else: + # 'missing' plus 'outdated' is all the images we need to build + todo = missing + outdated + # wipe 'unknown' images if requested if args.clean: clean(unknown) - # 'missing' plus 'outdated' is all the images we need to build; if - # args.delete was set, all images will be in this list - missing.extend(outdated) - for (num, img) in enumerate(missing, 1): - logger.info("Creating image %s...[%s/%s]", img.filename, str(num), str(len(missing))) + # if args.rel was passed, limit to images for that release + if args.rel: + todo = [img for img in todo if (hasattr(img, "release") and img.release == args.rel)] + + for (num, img) in enumerate(todo, 1): + logger.info("Creating image %s...[%s/%s]", img.filename, str(num), str(len(todo))) img.create(args.textinst) def cli_check(args, hdds): @@ -692,7 +698,7 @@ def cli_check(args, hdds): if args.rename: do_renames(hdds) - (missing, outdated, unknown) = check(hdds, nextrel=args.nextrel) + (missing, outdated, unknown) = check(hdds, nextrel=args.nextrel, rel=args.rel) if missing: print("Missing images: {0}".format(', '.join([img.filename for img in missing]))) if outdated: @@ -781,9 +787,6 @@ def parse_args(hdds): parser_all = subparsers.add_parser( 'all', description="Ensure all images are present and up-to-date.") - parser_all.add_argument( - '-d', '--delete', help="Delete and re-build all images", - action='store_true') parser_all.add_argument( '-c', '--clean', help="Remove unknown (usually old) images", action='store_true') @@ -792,6 +795,15 @@ def parse_args(hdds): "- this determines what releases some images will be built for. If " "not set or set to 0, createhdds will try to discover it when needed", type=int, default=0) + parser_all.add_argument( + '-r', '--rel', help="Limit operation to only the release specified (by number or 'eln')", + type=str, default="") + parser_all.add_argument( + '-f', '--force', help="Rebuild images even if they exist and are up to date", + action='store_true') + parser_all.add_argument( + '-d', '--delete', help="Deprecated, does the same as --force", + action='store_true', deprecated=True) parser_all.set_defaults(func=cli_all) parser_check = subparsers.add_parser(