Page Menu
Home
VyOS Platform
Search
Configure Global Search
Log In
Files
F118309491
system.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
system.py
View Options
#!/usr/bin/env python3
#
# Copyright (C) 2022 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
jmespath
import
json
import
sys
import
requests
import
typing
from
sys
import
exit
from
vyos.configquery
import
ConfigTreeQuery
import
vyos.opmode
import
vyos.version
config
=
ConfigTreeQuery
()
base
=
[
'system'
,
'update-check'
]
def
_compare_version_raw
():
url
=
config
.
value
(
base
+
[
'url'
])
local_data
=
vyos
.
version
.
get_full_version_data
()
remote_data
=
vyos
.
version
.
get_remote_version
(
url
)
if
not
remote_data
:
return
{
"error"
:
True
,
"reason"
:
"Unable to get remote version"
}
if
local_data
.
get
(
'version'
)
and
remote_data
:
local_version
=
local_data
.
get
(
'version'
)
remote_version
=
jmespath
.
search
(
'[0].version'
,
remote_data
)
image_url
=
jmespath
.
search
(
'[0].url'
,
remote_data
)
if
local_data
.
get
(
'version'
)
!=
remote_version
:
return
{
"error"
:
False
,
"update_available"
:
True
,
"local_version"
:
local_version
,
"remote_version"
:
remote_version
,
"url"
:
image_url
}
return
{
"update_available"
:
False
,
"local_version"
:
local_version
,
"remote_version"
:
remote_version
}
def
_formatted_compare_version
(
data
):
local_version
=
data
.
get
(
'local_version'
)
remote_version
=
data
.
get
(
'remote_version'
)
url
=
data
.
get
(
'url'
)
if
{
'update_available'
,
'local_version'
,
'remote_version'
,
'url'
}
<=
set
(
data
):
return
f
'Current version: {local_version}
\n\n
Update available: {remote_version}
\n
Update URL: {url}'
elif
local_version
==
remote_version
and
remote_version
is
not
None
:
return
f
'No available updates for your system
\n
'
\
f
'current version: {local_version}
\n
remote version: {remote_version}'
else
:
return
'Update not found'
def
_verify
():
if
not
config
.
exists
(
base
):
return
False
return
True
def
show_update
(
raw
:
bool
):
if
not
_verify
():
raise
vyos
.
opmode
.
UnconfiguredSubsystem
(
"system update-check not configured"
)
data
=
_compare_version_raw
()
if
raw
:
return
data
else
:
return
_formatted_compare_version
(
data
)
if
__name__
==
'__main__'
:
try
:
res
=
vyos
.
opmode
.
run
(
sys
.
modules
[
__name__
])
if
res
:
print
(
res
)
except
(
ValueError
,
vyos
.
opmode
.
Error
)
as
e
:
print
(
e
)
sys
.
exit
(
1
)
File Metadata
Details
Attached
Mime Type
text/x-script.python
Expires
Sat, Oct 17, 12:48 AM (16 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4354060
Default Alt Text
system.py (2 KB)
Attached To
Mode
rVYOSONEX vyos-1x
Attached
Detach File
Event Timeline
Log In to Comment