def save(*argv): usage = f""" Save an image from a node Mandatory radical needs to be provided with --output This info, together with nodename and date, is stored on resulting image in /etc/rhubarbe-image {RESERVATION_REQUIRED} """ config = Config() config.check_binaries() parser = ArgumentParser(usage=usage, formatter_class=ArgumentDefaultsHelpFormatter) parser.add_argument("-o", "--output", action='store', dest='radical', default=None, required=True, help="Mandatory radical to name resulting image") parser.add_argument("-t", "--timeout", action='store', default=config.value('nodes', 'save_default_timeout'), type=float, help="Specify global timeout for the whole process") parser.add_argument("-c", "--comment", dest='comment', default=None, help="one-liner comment to insert in " "/etc/rhubarbe-image") parser.add_argument("-n", "--no-reset", dest='reset', action='store_false', default=True, help="""use this with a node that is already running a frisbee image. It won't get reset, neither before or after the frisbee session""") parser.add_argument("node") args = parser.parse_args(argv) message_bus = asyncio.Queue() selector = Selector() selector.add_range(args.node) # in case there was one argument but it was not found in inventory if len(selector) != 1: parser.print_help() cmc_name = next(selector.cmc_names()) node = Node(cmc_name, message_bus) nodename = node.control_hostname() imagesrepo = ImagesRepo() actual_image = imagesrepo.where_to_save(nodename, args.radical) message_bus.put_nowait({'info': f"Saving image {actual_image}"}) # curses has no interest here since we focus on one node display_class = Display display = display_class([node], message_bus) saver = ImageSaver(node, image=actual_image, radical=args.radical, message_bus=message_bus, display=display, comment=args.comment) return saver.main(reset=args.reset, timeout=args.timeout)
def load(*argv): usage = f""" Load an image on selected nodes in parallel {RESERVATION_REQUIRED} """ config = Config() config.check_binaries() imagesrepo = ImagesRepo() parser = ArgumentParser(usage=usage, formatter_class=ArgumentDefaultsHelpFormatter) parser.add_argument("-i", "--image", action='store', default=imagesrepo.default(), help="Specify image to load") parser.add_argument("-t", "--timeout", action='store', default=config.value('nodes', 'load_default_timeout'), type=float, help="Specify global timeout for the whole process") parser.add_argument("-b", "--bandwidth", action='store', default=config.value('networking', 'bandwidth'), type=int, help="Set bandwidth in Mibps for frisbee uploading") parser.add_argument("-c", "--curses", action='store_true', default=False, help="Use curses to provide term-based animation") # this is more for debugging parser.add_argument("-n", "--no-reset", dest='reset', action='store_false', default=True, help="""use this with nodes that are already running a frisbee image. They won't get reset, neither before or after the frisbee session""") add_selector_arguments(parser) args = parser.parse_args(argv) message_bus = asyncio.Queue() selector = selected_selector(args) if selector.is_empty(): parser.print_help() return 1 nodes = [ Node(cmc_name, message_bus) # pylint: disable=w0621 for cmc_name in selector.cmc_names() ] # send feedback message_bus.put_nowait({'selected_nodes': selector}) from rhubarbe.logger import logger logger.info(f"timeout is {args.timeout}s") logger.info(f"bandwidth is {args.bandwidth} Mibps") actual_image = imagesrepo.locate_image(args.image, look_in_global=True) if not actual_image: print(f"Image file {args.image} not found - emergency exit") exit(1) # send feedback message_bus.put_nowait({'loading_image': actual_image}) display_class = Display if not args.curses else DisplayCurses display = display_class(nodes, message_bus) loader = ImageLoader(nodes, image=actual_image, bandwidth=args.bandwidth, message_bus=message_bus, display=display) return loader.main(reset=args.reset, timeout=args.timeout)