Changeset 1422


Ignore:
Timestamp:
Oct 29, 2008, 12:44:45 AM (16 years ago)
Author:
price
Message:

use /etc/invirt/conf.d/ too in invirt.config

Location:
trunk/packages/invirt-base
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/invirt-base/debian/changelog

    r1420 r1422  
    22
    33  * eliminate choice of source and cache files for invirt.config.load and
    4     invirt-getconf, so we can make it more complex
     4    invirt-getconf, so we can do what follows
     5  * look in /etc/invirt/conf.d/ as well as /etc/invirt/master.yaml
    56
    67 -- Greg Price <price@mit.edu>  Tue, 28 Oct 2008 21:16:14 -0400
  • trunk/packages/invirt-base/python/invirt/config.py

    r1421 r1422  
    33import json
    44from invirt.common import *
     5import os
    56from os import rename
    67from os.path import getmtime
     
    1112except: loader = yaml.SafeLoader
    1213
    13 src_path   = '/etc/invirt/master.yaml'
    14 cache_path = '/var/lib/invirt/cache.json'
    15 lock_path  = '/var/lib/invirt/cache.lock'
     14src_path    = '/etc/invirt/master.yaml'
     15src_dirpath = '/etc/invirt/conf.d'
     16cache_path  = '/var/lib/invirt/cache.json'
     17lock_path   = '/var/lib/invirt/cache.lock'
     18
     19def augment(d1, d2):
     20    """Splice dict-tree d2 into d1.  Return d1.
     21
     22    Example:
     23    >>> d = {'a': {'b': 1}, 'c': 2}
     24    >>> augment(d, {'a': {'d': 3}})
     25    {'a': {'b', 1, 'd': 3}, 'c': 2}
     26    >>> d
     27    {'a': {'b', 1, 'd': 3}, 'c': 2}
     28    """
     29    for k in d2:
     30        if k in d1 and isinstance(d1[k], dict):
     31            augment(d1[k], d2[k])
     32        else:
     33            d1[k] = d2[k]
     34    return d1
     35
     36def list_files():
     37    yield src_path
     38    for name in os.listdir(src_dirpath):
     39        yield os.path.join(src_dirpath, name)
    1640
    1741def load_master():
    18     with closing(file(src_path)) as f:
    19         return yaml.load(f, loader)
     42    config = dict()
     43    for filename in list_files():
     44        with closing(file(filename)) as f:
     45            augment(config, yaml.load(f, loader))
     46    return config
    2047
    2148def get_src_mtime():
    22     return getmtime(src_path)
     49    return max(max(getmtime(filename) for filename in list_files()),
     50               getmtime(src_dirpath))
    2351
    2452def load(force_refresh = False):
Note: See TracChangeset for help on using the changeset viewer.