blob: fe97de539d24ca20938660f8d19a3f7dd17e09f5 [file] [log] [blame]
George Keishinge7e91712021-09-03 11:28:44 -05001#!/usr/bin/env python3
Michael Walsh6dbdfef2018-05-30 10:35:26 -05002
3r"""
4This file contains utilities associated with the host OS.
5"""
6
Sridevi Ramesh47375aa2022-12-08 05:05:31 -06007import bmc_ssh_utils
8import var_funcs
9
George Keishingb1cfbde2018-05-30 11:50:07 -050010import sys
11import os
12
13sys.path.append(os.path.join(os.path.dirname(__file__), "../lib"))
14
Joy Onyerikwu004ad3c2018-06-11 16:29:56 -050015
George Keishing1ad128c2021-10-28 09:38:37 -050016def get_os_release_info(default_cmd="cat /etc/os-release"):
Michael Walsh6dbdfef2018-05-30 10:35:26 -050017 r"""
18
19 Get os-release info and return it as a dictionary.
20
21 An example of the contents of /etc/os-release:
22
23 NAME="Red Hat Enterprise Linux Server"
24 VERSION="7.5 (Maipo)"
25 ID="rhel"
26 ID_LIKE="fedora"
27 VARIANT="Server"
28 VARIANT_ID="server"
29 VERSION_ID="7.5"
30 PRETTY_NAME="Red Hat Enterprise Linux Server 7.5 Beta (Maipo)"
31 ANSI_COLOR="0;31"
32 CPE_NAME="cpe:/o:redhat:enterprise_linux:7.5:beta:server"
33 HOME_URL="https://www.redhat.com/"
34 BUG_REPORT_URL="https://bugzilla.redhat.com/"
35
36 REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7"
37 REDHAT_BUGZILLA_PRODUCT_VERSION=7.5
38 REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
39 REDHAT_SUPPORT_PRODUCT_VERSION="7.5 Beta"
40
41 For the data shown above, this function will return the following
42 dictionary:
43
44 result:
45 [name]: Red Hat Enterprise Linux Server
46 [version]: 7.5 (Maipo)
47 [id]: rhel
48 [id_like]: fedora
49 [variant]: Server
50 [variant_id]: server
51 [version_id]: 7.5
52 [pretty_name]: Red Hat Enterprise Linux Server 7.5 Beta (Maipo)
53 [ansi_color]: 0;31
54 [cpe_name]: cpe:/o:redhat:enterprise_linux:7.5:beta:server
55 [home_url]: https://www.redhat.com/
56 [bug_report_url]: https://bugzilla.redhat.com/
57 [redhat_bugzilla_product]: Red Hat Enterprise Linux 7
58 [redhat_bugzilla_product_version]: 7.5
59 [redhat_support_product]: Red Hat Enterprise Linux
60 [redhat_support_product_version]: 7.5 Beta
George Keishing1ad128c2021-10-28 09:38:37 -050061
62
63. Description of argument(s):
64 default_cmd A string command to be executed (e.g cat /etc/os-release).
65
Michael Walsh6dbdfef2018-05-30 10:35:26 -050066 """
67
68 stdout, stderr, rc =\
George Keishing1ad128c2021-10-28 09:38:37 -050069 bmc_ssh_utils.os_execute_command(default_cmd)
Michael Walsh6dbdfef2018-05-30 10:35:26 -050070
71 return var_funcs.key_value_outbuf_to_dict(stdout, delim="=", strip='"')