[_modules] add function to extract information from sources files (for now db-host)
authorArthur Lutz <arthur.lutz@logilab.fr>
Tue, 11 Oct 2016 14:47:31 +0200
changeset 85 3c8fc1103e94
parent 84 56452be19758
child 86 877e5d35b386
[_modules] add function to extract information from sources files (for now db-host)
_modules/cubicweb.py
--- a/_modules/cubicweb.py	Thu Oct 06 15:07:59 2016 +0200
+++ b/_modules/cubicweb.py	Tue Oct 11 14:47:31 2016 +0200
@@ -158,6 +158,29 @@
     cwlist = _cwlist(verbose)
     return 'instances' in cwlist and cwlist['instances'] or {}
 
+
+def sources(verbose=False):
+    '''
+    Return the list of sources of the Cubicweb instances. For now just
+    the db-host.
+
+    CLI Example::
+
+        salt '*' cubicweb.sources
+
+    '''
+    stdout = __salt__['cmd.run_stdout']('/bin/grep --with-filename ^db\-host /etc/cubicweb.d/*/sources', use_vt=True)
+    sources_dict = {}
+    for line in stdout.splitlines():
+        print line
+        filename, conf = line.split(':')
+        _, _, _, instance, _ = filename.split('/')
+        _, db_host = conf.split('=')
+        sources_dict[instance] = db_host
+    return sources_dict
+
+
+
 def status(instance=None):
     '''
     Return the status of Cubicweb instances; if an instance name is given, return