[modules] add cubicweb.versions execution function
authorJulien Cristau <julien.cristau@logilab.fr>
Fri, 04 Mar 2016 12:26:41 +0100
changeset 74 e8c227f254c0
parent 73 2ed939744ec0
child 75 6bd9ee482905
[modules] add cubicweb.versions execution function
_modules/cubicweb.py
--- a/_modules/cubicweb.py	Fri Mar 04 12:26:01 2016 +0100
+++ b/_modules/cubicweb.py	Fri Mar 04 12:26:41 2016 +0100
@@ -180,6 +180,19 @@
             return m.group('pid')
     return ''
 
+def versions(name):
+    '''Return a dict mapping cube name to version number for a given instance.
+    '''
+    cmd = 'cubicweb-ctl versions {0}'.format(name)
+    result = __salt__['cmd.run_stdout'](cmd)
+    d = {}
+    for row in result.splitlines():
+        if not row.strip():
+            continue
+        cube, version = row.split(': ', 1)
+        d[cube] = version
+    return d
+
 def create(name, cubes, install_type='all-in-one', **kwargs):
     '''
     Return the list of available Cubicweb cubes, configurations and instances