[node-patches] Change in ovirt-node[master]: utils: Add kargs retrieval function
fabiand at fedoraproject.org
fabiand at fedoraproject.org
Wed Dec 18 17:47:49 UTC 2013
Fabian Deutsch has uploaded a new change for review.
Change subject: utils: Add kargs retrieval function
......................................................................
utils: Add kargs retrieval function
Change-Id: I23f317273ad95e1c1febdcfec69998b924c9c961
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M src/ovirt/node/utils/system.py
1 file changed, 48 insertions(+), 12 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/41/22541/1
diff --git a/src/ovirt/node/utils/system.py b/src/ovirt/node/utils/system.py
index c0733b9..7753336 100644
--- a/src/ovirt/node/utils/system.py
+++ b/src/ovirt/node/utils/system.py
@@ -18,22 +18,25 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html.
-from ovirt.node import base, utils, log
-from ovirt.node.utils import process
-from ovirt.node.utils.fs import File
-import glob
-import os
-import re
-import rpm
-import subprocess
-import sys
-import system_config_keyboard.keyboard
-import time
-
"""
A module to access system wide stuff
e.g. services, reboot ...
"""
+
+import glob
+import os
+import re
+import shlex
+import subprocess
+import sys
+import time
+
+import rpm
+import system_config_keyboard.keyboard
+
+from ovirt.node import base, utils, log
+from ovirt.node.utils import process
+from ovirt.node.utils.fs import File
LOGGER = log.getLogger(__name__)
@@ -89,6 +92,39 @@
return os.path.exists("/dev/HostVG")
+def kernel_cmdline_arguments():
+ """Return the arguments of the currently booted kernel
+ """
+ return _parse_cmdline_args(File("/proc/cmdline").read())
+
+
+def _parse_cmdline_args(cmdline):
+ """Parse the cmdline like we do it in the initfunctions
+
+ >>> sorted_args = lambda txt: sorted(_parse_cmdline_args(txt).items())
+ >>> sorted_args("a=1 b=2 c")
+ [('a', '1'), ('b', '2'), ('c', 'c')]
+ >>> sorted_args("a=1=2")
+ [('a', '1=2')]
+ >>> sorted_args("rd.lvm.lv=foo/bar")
+ [('rd.lvm.lv', 'foo/bar')]
+ >>> sorted_args("title='foo bar'")
+ [('title', 'foo bar')]
+ >>> sorted_args("a")
+ [('a', 'a')]
+ """
+ args_list = shlex.split(cmdline)
+ args = {}
+
+ for arg in args_list:
+ key = value = arg
+ if "=" in arg:
+ key, value = arg.split("=", 1)
+ args[key] = value
+
+ return args
+
+
def which(cmd):
"""Simulates the behavior of which
--
To view, visit http://gerrit.ovirt.org/22541
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I23f317273ad95e1c1febdcfec69998b924c9c961
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>
More information about the node-patches
mailing list