summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorViacheslav Hletenko <v.gletenko@vyos.io>2022-09-05 18:35:39 +0000
committerViacheslav Hletenko <v.gletenko@vyos.io>2022-09-07 14:54:35 +0000
commita8e73794ec421ad2bb0053214504f20a1dc3b21a (patch)
treedef1b03e7a364803f21239a39dff56a1238b563a /python
parent735767f09f891c438e43565f935b927e6f1b317d (diff)
downloadvyos-1x-a8e73794ec421ad2bb0053214504f20a1dc3b21a.tar.gz
vyos-1x-a8e73794ec421ad2bb0053214504f20a1dc3b21a.zip
update-check: T3476: Allow update-check for VyOS images
Ability to autocheck available new images Parse remote URL JSON image-version.json file and compare version VyOS with a local current version, if find diff sent wall message that the new image is available Also, add op-mode command to check images "show system image" With option "auto-check" check will be once per 12 hours set system update-check auto-check set system update-check url 'http://example.com/image-version.json' If new version is available shows it per login (MOTD)
Diffstat (limited to 'python')
-rw-r--r--python/vyos/version.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/python/vyos/version.py b/python/vyos/version.py
index 871bb0f1b..fb706ad44 100644
--- a/python/vyos/version.py
+++ b/python/vyos/version.py
@@ -31,6 +31,7 @@ Example of the version data dict::
import os
import json
+import requests
import vyos.defaults
from vyos.util import read_file
@@ -105,3 +106,41 @@ def get_full_version_data(fname=version_file):
version_data['hardware_uuid'] = read_file(subsystem + '/product_uuid', 'Unknown')
return version_data
+
+def get_remote_version(url):
+ """
+ Get remote available JSON file from remote URL
+ An example of the image-version.json
+
+ [
+ {
+ "arch":"amd64",
+ "flavors":[
+ "generic"
+ ],
+ "image":"vyos-rolling-latest.iso",
+ "latest":true,
+ "lts":false,
+ "release_date":"2022-09-06",
+ "release_train":"sagitta",
+ "url":"http://xxx/rolling/current/vyos-rolling-latest.iso",
+ "version":"vyos-1.4-rolling-202209060217"
+ }
+ ]
+ """
+ headers = {}
+ try:
+ remote_data = requests.get(url=url, headers=headers)
+ remote_data.raise_for_status()
+ if remote_data.status_code != 200:
+ return False
+ return remote_data.json()
+ except requests.exceptions.HTTPError as errh:
+ print ("HTTP Error:", errh)
+ except requests.exceptions.ConnectionError as errc:
+ print ("Connecting error:", errc)
+ except requests.exceptions.Timeout as errt:
+ print ("Timeout error:", errt)
+ except requests.exceptions.RequestException as err:
+ print ("Unable to get remote data", err)
+ return False