summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-07-12 21:16:11 +0200
committerChristian Breunig <christian@breunig.cc>2023-07-12 21:16:56 +0200
commit4e2a087cc7e91a510dd590f7cc761e36ac8f77f8 (patch)
treefd7534645f6950a8fcaabbce4c1437f6432cf3ff
parent6e621e42f463d8643b504916a1cc7c967f5bd6f1 (diff)
downloadvyos-1x-4e2a087cc7e91a510dd590f7cc761e36ac8f77f8.tar.gz
vyos-1x-4e2a087cc7e91a510dd590f7cc761e36ac8f77f8.zip
T5195: move boot_* helpers to vyos.utils.boot
-rw-r--r--python/vyos/configquery.py5
-rw-r--r--python/vyos/configsource.py4
-rw-r--r--python/vyos/util.py22
-rw-r--r--python/vyos/utils/boot.py35
-rwxr-xr-xsrc/conf_mode/vpp.py3
-rwxr-xr-xsrc/helpers/vyos_net_name7
-rwxr-xr-xsrc/op_mode/powerctrl.py2
-rwxr-xr-xsrc/services/vyos-configd9
8 files changed, 50 insertions, 37 deletions
diff --git a/python/vyos/configquery.py b/python/vyos/configquery.py
index 85fef8777..9260da568 100644
--- a/python/vyos/configquery.py
+++ b/python/vyos/configquery.py
@@ -1,4 +1,4 @@
-# Copyright 2021 VyOS maintainers and contributors <maintainers@vyos.io>
+# Copyright 2021-2023 VyOS maintainers and contributors <maintainers@vyos.io>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -21,7 +21,8 @@ settings from op mode, and execution of arbitrary op mode commands.
import os
from subprocess import STDOUT
-from vyos.util import popen, boot_configuration_complete
+from vyos.util import popen
+from vyos.utils.boot import boot_configuration_complete
from vyos.config import Config
from vyos.configsource import ConfigSourceSession, ConfigSourceString
from vyos.defaults import directories
diff --git a/python/vyos/configsource.py b/python/vyos/configsource.py
index 510b5b65a..f582bdfab 100644
--- a/python/vyos/configsource.py
+++ b/python/vyos/configsource.py
@@ -1,5 +1,5 @@
-# Copyright 2020 VyOS maintainers and contributors <maintainers@vyos.io>
+# Copyright 2020-2023 VyOS maintainers and contributors <maintainers@vyos.io>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -19,7 +19,7 @@ import re
import subprocess
from vyos.configtree import ConfigTree
-from vyos.util import boot_configuration_complete
+from vyos.utils.boot import boot_configuration_complete
class VyOSError(Exception):
"""
diff --git a/python/vyos/util.py b/python/vyos/util.py
index ed651fdc3..bd47940bb 100644
--- a/python/vyos/util.py
+++ b/python/vyos/util.py
@@ -1130,28 +1130,6 @@ def is_wwan_connected(interface):
# return True/False if interface is in connected state
return dict_search('modem.generic.state', tmp) == 'connected'
-def boot_configuration_complete() -> bool:
- """ Check if the boot config loader has completed
- """
- from vyos.defaults import config_status
-
- if os.path.isfile(config_status):
- return True
- return False
-
-def boot_configuration_success() -> bool:
- from vyos.defaults import config_status
-
- try:
- with open(config_status) as f:
- res = f.read().strip()
- except FileNotFoundError:
- return False
-
- if int(res) == 0:
- return True
- return False
-
def sysctl_read(name):
""" Read and return current value of sysctl() option """
tmp = cmd(f'sysctl {name}')
diff --git a/python/vyos/utils/boot.py b/python/vyos/utils/boot.py
new file mode 100644
index 000000000..3aecbec64
--- /dev/null
+++ b/python/vyos/utils/boot.py
@@ -0,0 +1,35 @@
+# Copyright 2023 VyOS maintainers and contributors <maintainers@vyos.io>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# 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/>.
+
+import os
+
+def boot_configuration_complete() -> bool:
+ """ Check if the boot config loader has completed
+ """
+ from vyos.defaults import config_status
+ if os.path.isfile(config_status):
+ return True
+ return False
+
+def boot_configuration_success() -> bool:
+ from vyos.defaults import config_status
+ try:
+ with open(config_status) as f:
+ res = f.read().strip()
+ except FileNotFoundError:
+ return False
+ if int(res) == 0:
+ return True
+ return False
diff --git a/src/conf_mode/vpp.py b/src/conf_mode/vpp.py
index 87ebc3ea9..0b7a6993a 100755
--- a/src/conf_mode/vpp.py
+++ b/src/conf_mode/vpp.py
@@ -25,7 +25,8 @@ from vyos.configdep import set_dependents, call_dependents
from vyos.configdict import dict_merge
from vyos.configdict import node_changed
from vyos.ifconfig import Section
-from vyos.util import call, rc_cmd, boot_configuration_complete
+from vyos.util import call, rc_cmd
+from vyos.utils.boot import boot_configuration_complete
from vyos.utils.system import sysctl_read, sysctl_apply
from vyos.template import render
from vyos.xml import defaults
diff --git a/src/helpers/vyos_net_name b/src/helpers/vyos_net_name
index 1798e92db..7431f3713 100755
--- a/src/helpers/vyos_net_name
+++ b/src/helpers/vyos_net_name
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
-# Copyright (C) 2021 VyOS maintainers and contributors
+# Copyright (C) 2021-2023 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
@@ -13,8 +13,6 @@
#
# 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 os
import re
@@ -26,7 +24,8 @@ from sys import argv
from vyos.configtree import ConfigTree
from vyos.defaults import directories
-from vyos.util import cmd, boot_configuration_complete
+from vyos.util import cmd
+from vyos.utils.boot import boot_configuration_complete
from vyos.migrator import VirtualMigrator
vyos_udev_dir = directories['vyos_udev_dir']
diff --git a/src/op_mode/powerctrl.py b/src/op_mode/powerctrl.py
index dfacd45c2..2bb2e717b 100755
--- a/src/op_mode/powerctrl.py
+++ b/src/op_mode/powerctrl.py
@@ -104,7 +104,7 @@ def cancel_shutdown():
def check_unsaved_config():
from vyos.config_mgmt import unsaved_commits
- from vyos.util import boot_configuration_success
+ from vyos.utils.boot import boot_configuration_success
if unsaved_commits() and boot_configuration_success():
print("Warning: there are unsaved configuration changes!")
diff --git a/src/services/vyos-configd b/src/services/vyos-configd
index 48c9135e2..355182b26 100755
--- a/src/services/vyos-configd
+++ b/src/services/vyos-configd
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
-# Copyright (C) 2020 VyOS maintainers and contributors
+# Copyright (C) 2020-2023 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
@@ -13,8 +13,6 @@
#
# 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 os
import sys
@@ -28,8 +26,9 @@ import zmq
from contextlib import contextmanager
from vyos.defaults import directories
-from vyos.util import boot_configuration_complete
-from vyos.configsource import ConfigSourceString, ConfigSourceError
+from vyos.utils.boot import boot_configuration_complete
+from vyos.configsource import ConfigSourceString
+from vyos.configsource import ConfigSourceError
from vyos.config import Config
from vyos import ConfigError