started adding simple configuration-loading module and getconfig frontend; checkpoint...
authorYang Zhang <y_z@mit.edu>
Sun, 27 Jul 2008 22:48:28 +0000 (18:48 -0400)
committerYang Zhang <y_z@mit.edu>
Sun, 27 Jul 2008 22:48:28 +0000 (18:48 -0400)
svn path=/trunk/packages/sipb-xen-base/; revision=726

files/usr/sbin/invirt-getconf [new file with mode: 0644]
files/usr/share/python-support/sipb-xen-base/invirt/__init__.py
files/usr/share/python-support/sipb-xen-base/invirt/config.py [new file with mode: 0644]

diff --git a/files/usr/sbin/invirt-getconf b/files/usr/sbin/invirt-getconf
new file mode 100644 (file)
index 0000000..cbb0a85
--- /dev/null
@@ -0,0 +1,18 @@
+#!/usr/bin/env python
+
+from invirt.config import load
+from sys import argv, stderr
+
+def main( argv ):
+    try: command, key = argv
+    except: print >> stderr, 'invirt-getconf KEY'
+    conf = load()
+    for component in key.split('.')[:-1]:
+        if component.isdigit(): component = int( component )
+        conf = conf[ component ]
+    print conf[key]
+
+if __name__ == '__main__':
+    main( argv )
+
+# vim:et:sw=4:ts=4
index 18d44f9..d880252 100644 (file)
@@ -19,3 +19,9 @@ Consult the source files for details.
 
 # You should have received a copy of the GNU General Public License
 # along with Invirt.  If not, see <http://www.gnu.org/licenses/>.
+
+__author__    = 'MIT SIPB'
+__version__   = '0.1'
+__copyright__ = 'Copyright (c) 2008 MIT SIPB'
+
+# vim:et:sw=4:ts=4
diff --git a/files/usr/share/python-support/sipb-xen-base/invirt/config.py b/files/usr/share/python-support/sipb-xen-base/invirt/config.py
new file mode 100644 (file)
index 0000000..42e3b2f
--- /dev/null
@@ -0,0 +1,10 @@
+from __future__ import with_statement
+import yaml
+
+default_path = '/etc/invirt/master.yaml'
+
+def load( path = default_path ):
+    with file( path ) as f:
+        return yaml.load( f, yaml.CSafeLoader )
+
+# vim:et:sw=4:ts=4