Eli Mesika has uploaded a new change for review.

Change subject: vdsm: adding handling for NGN in osinfo.py
......................................................................

vdsm: adding handling for NGN in osinfo.py

Current osinfo.py implementation lacks handling for NGN (New Generation
Node).

This patch adds another parameter in addition to the osname, release and
version named pretty_name, that is empty bu default and if
/etc/os-release file exists on the OS, will return the content of the
PRETTY_NAME value (if exists) from that file.

Change-Id: Ida119527b263302bf3f78e359bac12113718b744
Bug-Url : https://bugzilla.redhat.com/show_bug.cgi?id=1324447
Signed-off-by: emesika <[email protected]>
---
M lib/api/vdsm-api.yml
M lib/vdsm/osinfo.py
2 files changed, 32 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/31/59431/1

diff --git a/lib/api/vdsm-api.yml b/lib/api/vdsm-api.yml
index 475ccda..2814fc5 100644
--- a/lib/api/vdsm-api.yml
+++ b/lib/api/vdsm-api.yml
@@ -4650,6 +4650,10 @@
         -   description: The OS version (eg. 17 for Fedora 17)
             name: version
             type: string
+
+        -   description: The OS pretty name
+            name: pretty_name
+            type: string
         type: object
 
     WatchdogEventAction: &WatchdogEventAction
diff --git a/lib/vdsm/osinfo.py b/lib/vdsm/osinfo.py
index 8ad99a1..0910872 100644
--- a/lib/vdsm/osinfo.py
+++ b/lib/vdsm/osinfo.py
@@ -23,6 +23,7 @@
 import glob
 import linecache
 import logging
+import shlex
 import time
 import os
 
@@ -106,18 +107,34 @@
         return OSName.UNKNOWN
 
 
-def _parse_node_version(path):
+def _parse_release_file(path):
     data = {}
-    with open(path) as f:
-        for line in f:
-            try:
-                key, value = [kv.strip() for kv in line.split('=', 1)]
-            except ValueError:
-                continue
+    try:
+        with open(path) as f:
+            for line in shlex.split(f, comments=True):
+                try:
+                    key, value = line.split('=', 1)
+                except ValueError:
+                    continue
 
-            data[key] = value
+                data[key] = value
+    except IOError:
+        logging.exception('Fail to read release file')
+    return data
 
+
+def _parse_node_version(path):
+    data = _parse_release_file(path)
     return data.get('VERSION', ''), data.get('RELEASE', '')
+
+
+def _get_pretty_name():
+    pretty_name = ''
+    if os.path.exists('/etc/os-release'):
+        data = _parse_release_file('/etc/os-release')
+        if data.get('PRETTY_NAME') is not None:
+            pretty_name = data.get('PRETTY_NAME').strip('"')
+    return pretty_name
 
 
 @utils.memoized
@@ -131,6 +148,7 @@
     version = release_name = ''
 
     osname = _release_name()
+    pretty_name = _get_pretty_name()
     try:
         if osname == OSName.RHEVH or osname == OSName.OVIRT:
             version, release_name = _parse_node_version('/etc/default/version')
@@ -150,7 +168,8 @@
     except:
         logging.error('failed to find version/release', exc_info=True)
 
-    return dict(release=release_name, version=version, name=osname)
+    return dict(release=release_name, version=version,
+                name=osname, pretty_name=pretty_name)
 
 
 def selinux_status():


-- 
To view, visit https://gerrit.ovirt.org/59431
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ida119527b263302bf3f78e359bac12113718b744
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Eli Mesika <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/admin/lists/[email protected]

Reply via email to