summaryrefslogtreecommitdiff
path: root/python/vyos/version.py
diff options
context:
space:
mode:
authorRunar Borge <runar@borge.nu>2018-06-23 23:51:10 +0200
committerRunar Borge <runar@borge.nu>2018-06-23 23:51:10 +0200
commit598f1e0385c3e3d797ebe172d4e9acba88038993 (patch)
tree1b2172d3086f3c0a45daeefdb00fca2f6b2132ee /python/vyos/version.py
parentd4e3868629fd097c57ff6c47fe60b83ba4c3e272 (diff)
parent4c6282a43bc1a2ddfe690eef88536cfcd2b88535 (diff)
downloadvyos-1x-598f1e0385c3e3d797ebe172d4e9acba88038993.tar.gz
vyos-1x-598f1e0385c3e3d797ebe172d4e9acba88038993.zip
Merge branch 'current' of git://github.com/vyos/vyos-1x into current
Diffstat (limited to 'python/vyos/version.py')
-rw-r--r--python/vyos/version.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/python/vyos/version.py b/python/vyos/version.py
index b7fb04b52..383efbc1e 100644
--- a/python/vyos/version.py
+++ b/python/vyos/version.py
@@ -13,6 +13,21 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
+"""
+VyOS version data access library.
+
+VyOS stores its version data, which include the version number and some
+additional information in a JSON file. This module provides a convenient
+interface to reading it.
+
+Example of the version data dict::
+ {
+ 'built_by': 'autobuild@vyos.net',
+ 'build_id': '021ac2ee-cd07-448b-9991-9c68d878cddd',
+ 'version': '1.2.0-rolling+201806200337',
+ 'built_on': 'Wed 20 Jun 2018 03:37 UTC'
+ }
+"""
import os
import json
@@ -22,11 +37,29 @@ import vyos.defaults
version_file = os.path.join(vyos.defaults.directories['data'], 'version.json')
def get_version_data(file=version_file):
+ """
+ Get complete version data
+
+ Args:
+ file (str): path to the version file
+
+ Returns:
+ dict: version data
+
+ The optional ``file`` argument comes in handy in upgrade scripts
+ that need to retrieve information from images other than the running image.
+ It should not be used on a running system since the location of that file
+ is an implementation detail and may change in the future, while the interface
+ of this module will stay the same.
+ """
with open(file, 'r') as f:
version_data = json.load(f)
return version_data
def get_version(file=None):
+ """
+ Get the version number
+ """
version_data = None
if file:
version_data = get_version_data(file=file)