blob: a1b4223bb5b41f5a2076c0d2a6f6fa0a1796efd0 [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
George Keishinge635ddc2022-12-08 07:38:02 -06007import os
Patrick Williams20f38712022-12-08 06:18:26 -06008import sys
George Keishinge635ddc2022-12-08 07:38:02 -06009
George Keishingb1cfbde2018-05-30 11:50:07 -050010sys.path.append(os.path.join(os.path.dirname(__file__), "../lib"))
11
George Keishing09679892022-12-08 08:21:52 -060012import bmc_ssh_utils # NOQA
Patrick Williams20f38712022-12-08 06:18:26 -060013import var_funcs # NOQA
George Keishing37c58c82022-12-08 07:42:54 -060014
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
Patrick Williams20f38712022-12-08 06:18:26 -060019 Get os-release info and return it as a dictionary.
Michael Walsh6dbdfef2018-05-30 10:35:26 -050020
Patrick Williams20f38712022-12-08 06:18:26 -060021 An example of the contents of /etc/os-release:
Michael Walsh6dbdfef2018-05-30 10:35:26 -050022
Patrick Williams20f38712022-12-08 06:18:26 -060023 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/"
Michael Walsh6dbdfef2018-05-30 10:35:26 -050035
Patrick Williams20f38712022-12-08 06:18:26 -060036 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"
Michael Walsh6dbdfef2018-05-30 10:35:26 -050040
Patrick Williams20f38712022-12-08 06:18:26 -060041 For the data shown above, this function will return the following
42 dictionary:
Michael Walsh6dbdfef2018-05-30 10:35:26 -050043
Patrick Williams20f38712022-12-08 06:18:26 -060044 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
Patrick Williams20f38712022-12-08 06:18:26 -060063 . Description of argument(s):
64 default_cmd A string command to be executed (e.g cat /etc/os-release).
George Keishing1ad128c2021-10-28 09:38:37 -050065
Michael Walsh6dbdfef2018-05-30 10:35:26 -050066 """
67
Patrick Williams20f38712022-12-08 06:18:26 -060068 stdout, stderr, rc = bmc_ssh_utils.os_execute_command(default_cmd)
Michael Walsh6dbdfef2018-05-30 10:35:26 -050069
70 return var_funcs.key_value_outbuf_to_dict(stdout, delim="=", strip='"')