Ejemplo n.º 1
0
def update_config():
    i = inotify.adapters.Inotify()
    i.add_watch(Config.path, mask=IN_CLOSE_WRITE)
    for _ in i.event_gen(yield_nones=False):
        Config.data = {}
        Config.load_data()
        MirrorManager.update_mirror_list()
Ejemplo n.º 2
0
def watch(ctx, img_dir, streams_dir):
    Config.load_data()
    # Lauch threads
    update_config()
    update_metadata(img_dir, streams_dir)

    i = inotify.adapters.InotifyTree(
        str(Path(img_dir).resolve()),
        mask=(IN_ATTRIB | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO
              | IN_CLOSE_WRITE))

    while True:
        events = i.event_gen(yield_nones=False, timeout_s=15)
        files_changed = needs_update(events)
        if files_changed:
            event_queue.put(files_changed)
Ejemplo n.º 3
0
def configure_log(verbose=False):
    log_config = Config.get('logging', {})
    if verbose:
        for ltype in ['handlers', 'loggers']:
            for elem in log_config.get(ltype, []):
                elem.setLeve('DEBUG')
    dictConfig(log_config)
Ejemplo n.º 4
0
 def update_mirror_list(cls):
     with cls._lock:
         for name, mirror in Config.get('mirrors', {}).items():
             cls.mirrors[name] = Mirror(name, mirror['user'],
                                        mirror['key_path'], mirror['url'],
                                        mirror.get('remote'), cls.img_dir)
         logger.info('Mirror list updated')
     cls.update()
Ejemplo n.º 5
0
def update_config(skipWatchingNonExistent=True):
    i = config_inotify_setup(skipWatchingNonExistent)
    while True:
        reload = False
        for event in i.event_gen(yield_nones=False):
            (_, mask, dir, file) = event
            fp = os.path.join(dir, file).rstrip(os.path.sep)
            for p in Config.paths:
                if p == fp or (dir == p):
                    reload = True
                    break
            if reload:
                break

        if reload:
            logger.debug("Will reload configuration")
            Config.reload_data()
            i = config_inotify_setup()
            MirrorManager.update_mirror_list()
        else:
            logger.debug("No need to reload configuration")
Ejemplo n.º 6
0
def watch(ctx, img_dir, streams_dir, skip_watch_config_non_existent: bool):
    path_img_dir = str(Path(img_dir).expanduser().resolve())
    path_streams_dir = str(Path(streams_dir).expanduser().resolve())
    logger.info("lxd-image-server: Starting watch process")

    Config.load_data()
    # Lauch threads
    # SEEME: in case an event will come from watching config files, there is a race condition between update_config
    # thread using indirectly MirrorManager.img_dir and thread update_metadata setting MirrorManager.img_dir
    # Also, race condition on calling MirrorManager.update_mirror_list() in both threads.
    update_config(skip_watch_config_non_existent)
    update_metadata(path_img_dir, path_streams_dir)
    logger.debug("Watching image directory {}".format(path_img_dir))

    i = inotify.adapters.InotifyTree(
        path_img_dir,
        mask=(IN_ATTRIB | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO
              | IN_CLOSE_WRITE))

    while True:
        events = i.event_gen(yield_nones=False, timeout_s=15)
        files_changed = needs_update(events)
        if files_changed:
            event_queue.put(files_changed)
Ejemplo n.º 7
0
def cli(verbose):
    Config.load_data()
    configure_log(verbose)
Ejemplo n.º 8
0
 def reload_on_signal(signum, frame):
     logger.info('Relading configuration')
     Config.load_data()
     configure_log()
     MirrorManager.update_mirror_list()