Пример #1
0
def images(*argv):
    usage = """
    Display available images
    """
    parser = ArgumentParser(usage=usage,
                            formatter_class=ArgumentDefaultsHelpFormatter)
    parser.add_argument("-l",
                        "--labeled-only",
                        dest="labeled",
                        action='store_true',
                        default=False,
                        help="""if specified, only images that have at least
                        one symlink to them are shown""")
    parser.add_argument("-p",
                        "--public-only",
                        action="store_true",
                        default=False,
                        help="displays only publicly visible images")
    parser.add_argument("-s",
                        "--size",
                        dest='sort_size',
                        action='store_true',
                        default=None,
                        help="sort by size (default is by name)")
    parser.add_argument("-d",
                        "--date",
                        dest='sort_date',
                        action='store_true',
                        default=None,
                        help="sort by date")
    parser.add_argument("-r",
                        "--reverse",
                        action='store_true',
                        default=False,
                        help="reverse sort")
    parser.add_argument("-n",
                        "--narrow",
                        action='store_true',
                        default=False,
                        help="""default is to show full paths, with this option
                        only radicals are displayed""")
    parser.add_argument("focus",
                        nargs="*",
                        type=str,
                        help="if provided, only images that contain "
                        "one of these strings are displayed")
    args = parser.parse_args(argv)
    imagesrepo = ImagesRepo()
    if args.sort_size is not None:
        args.sort_by = 'size'
    elif args.sort_date is not None:
        args.sort_by = 'date'
    else:
        args.sort_by = 'name'

    # if focus is an empty list, then everything is shown
    return imagesrepo.images(args.focus, args.sort_by, args.reverse,
                             args.labeled, args.public_only, args.narrow)
Пример #2
0
def share(*argv):
    usage = """
    Install privately-stored images into the global images repo
    Destination name is derived from the radical provided at save-time
      i.e. trailing part after saving__<date>__

    With the -a option, it is possible to make the new image
    **also** visible under that alias name.

    If your account is enabled in /etc/sudoers.d/rhubarbe-share,
    the command will actually perform the mv operation
    Requires to be run through 'sudo rhubarbe-share'
    """
    parser = ArgumentParser(usage=usage,
                            formatter_class=ArgumentDefaultsHelpFormatter)
    parser.add_argument("-a",
                        "--alias-name",
                        dest='alias',
                        action='store',
                        default=None,
                        help="also create a symlink of that name")
    # default=None so that imagesrepo.share can compute a default
    parser.add_argument("-n",
                        "--dry-run",
                        default=None,
                        action='store_true',
                        help="Only show what would be done "
                        "(default unless running under sudo")
    parser.add_argument("-f",
                        "--force",
                        default=False,
                        action='store_true',
                        help="Will move files even if destination exists")
    parser.add_argument("-c",
                        "--clean",
                        default=False,
                        action='store_true',
                        help="""Will remove other matches than the one that
                        gets promoted. In other words, useful when one name
                        has several matches and only the last one is desired.
                        Typically after a successful rsave""")
    parser.add_argument("image", type=str)
    args = parser.parse_args(argv)

    imagesrepo = ImagesRepo()
    return imagesrepo.share(args.image, args.alias, args.dry_run, args.force,
                            args.clean)
Пример #3
0
def resolve(*argv):
    usage = """for each input, find out and display
    what file exactly would be used if used with load
    and possible siblings if verbose mode is selected
    """

    parser = ArgumentParser(usage=usage,
                            formatter_class=ArgumentDefaultsHelpFormatter)
    #    parser.add_argument("-r", "--reverse", action='store_true', default=False,
    #                        help="reverse sort")
    parser.add_argument("-v",
                        "--verbose",
                        action='store_true',
                        default=False,
                        help="show all files (i.e. with all symlinks)")
    parser.add_argument("focus",
                        type=str,
                        help="the image radical name to resolve")
    args = parser.parse_args(argv)
    imagesrepo = ImagesRepo()
    # if focus is an empty list, then everything is shown
    return imagesrepo.resolve(args.focus, args.verbose)
Пример #4
0
    def global_load_image(self, image_name):

        # locate image
        the_imagesrepo = ImagesRepo()
        actual_image = the_imagesrepo.locate_image(image_name,
                                                   look_in_global=True)
        if not actual_image:
            self.print(f"image file {image_name} not found - emergency exit")
            exit(1)

        # load image
        self.verbose_msg(f"image={actual_image}")
        self.verbose_msg(f"bandwidth={self.bandwidth}")
        self.verbose_msg(f"timeout={self.load_timeout}")
        loader = ImageLoader(self.nodes,
                             image=actual_image,
                             bandwidth=self.bandwidth,
                             message_bus=self.bus,
                             display=self.display)
        self.print(f"loading image {actual_image}"
                   f" (timeout = {self.load_timeout})")
        loader.main(reset=True, timeout=self.load_timeout)
        self.print("load done")
Пример #5
0
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)
Пример #6
0
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)