blob: b4b2a5c8c9e012741d534d543f51ab6db109775f [file] [log] [blame]
Michael Walsh6dbdfef2018-05-30 10:35:26 -05001#!/usr/bin/env python
2
3r"""
4This file contains utilities associated with the host OS.
5"""
6
7import bmc_ssh_utils
8import var_funcs
9
10
11def get_os_release_info():
12 r"""
13
14 Get os-release info and return it as a dictionary.
15
16 An example of the contents of /etc/os-release:
17
18 NAME="Red Hat Enterprise Linux Server"
19 VERSION="7.5 (Maipo)"
20 ID="rhel"
21 ID_LIKE="fedora"
22 VARIANT="Server"
23 VARIANT_ID="server"
24 VERSION_ID="7.5"
25 PRETTY_NAME="Red Hat Enterprise Linux Server 7.5 Beta (Maipo)"
26 ANSI_COLOR="0;31"
27 CPE_NAME="cpe:/o:redhat:enterprise_linux:7.5:beta:server"
28 HOME_URL="https://www.redhat.com/"
29 BUG_REPORT_URL="https://bugzilla.redhat.com/"
30
31 REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7"
32 REDHAT_BUGZILLA_PRODUCT_VERSION=7.5
33 REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
34 REDHAT_SUPPORT_PRODUCT_VERSION="7.5 Beta"
35
36 For the data shown above, this function will return the following
37 dictionary:
38
39 result:
40 [name]: Red Hat Enterprise Linux Server
41 [version]: 7.5 (Maipo)
42 [id]: rhel
43 [id_like]: fedora
44 [variant]: Server
45 [variant_id]: server
46 [version_id]: 7.5
47 [pretty_name]: Red Hat Enterprise Linux Server 7.5 Beta (Maipo)
48 [ansi_color]: 0;31
49 [cpe_name]: cpe:/o:redhat:enterprise_linux:7.5:beta:server
50 [home_url]: https://www.redhat.com/
51 [bug_report_url]: https://bugzilla.redhat.com/
52 [redhat_bugzilla_product]: Red Hat Enterprise Linux 7
53 [redhat_bugzilla_product_version]: 7.5
54 [redhat_support_product]: Red Hat Enterprise Linux
55 [redhat_support_product_version]: 7.5 Beta
56 """
57
58 stdout, stderr, rc =\
59 bmc_ssh_utils.os_execute_command("cat /etc/os-release")
60
61 return var_funcs.key_value_outbuf_to_dict(stdout, delim="=", strip='"')