blob: 10ebc19ce0914ee8b0a680b0b29071ef371c2051 [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
George Keishingb1cfbde2018-05-30 11:50:07 -05007import sys
8import os
9
10sys.path.append(os.path.join(os.path.dirname(__file__), "../lib"))
11
Michael Walsh6dbdfef2018-05-30 10:35:26 -050012import bmc_ssh_utils
13import var_funcs
14
Michael Walsh6dbdfef2018-05-30 10:35:26 -050015def get_os_release_info():
16 r"""
17
18 Get os-release info and return it as a dictionary.
19
20 An example of the contents of /etc/os-release:
21
22 NAME="Red Hat Enterprise Linux Server"
23 VERSION="7.5 (Maipo)"
24 ID="rhel"
25 ID_LIKE="fedora"
26 VARIANT="Server"
27 VARIANT_ID="server"
28 VERSION_ID="7.5"
29 PRETTY_NAME="Red Hat Enterprise Linux Server 7.5 Beta (Maipo)"
30 ANSI_COLOR="0;31"
31 CPE_NAME="cpe:/o:redhat:enterprise_linux:7.5:beta:server"
32 HOME_URL="https://www.redhat.com/"
33 BUG_REPORT_URL="https://bugzilla.redhat.com/"
34
35 REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7"
36 REDHAT_BUGZILLA_PRODUCT_VERSION=7.5
37 REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
38 REDHAT_SUPPORT_PRODUCT_VERSION="7.5 Beta"
39
40 For the data shown above, this function will return the following
41 dictionary:
42
43 result:
44 [name]: Red Hat Enterprise Linux Server
45 [version]: 7.5 (Maipo)
46 [id]: rhel
47 [id_like]: fedora
48 [variant]: Server
49 [variant_id]: server
50 [version_id]: 7.5
51 [pretty_name]: Red Hat Enterprise Linux Server 7.5 Beta (Maipo)
52 [ansi_color]: 0;31
53 [cpe_name]: cpe:/o:redhat:enterprise_linux:7.5:beta:server
54 [home_url]: https://www.redhat.com/
55 [bug_report_url]: https://bugzilla.redhat.com/
56 [redhat_bugzilla_product]: Red Hat Enterprise Linux 7
57 [redhat_bugzilla_product_version]: 7.5
58 [redhat_support_product]: Red Hat Enterprise Linux
59 [redhat_support_product_version]: 7.5 Beta
60 """
61
62 stdout, stderr, rc =\
63 bmc_ssh_utils.os_execute_command("cat /etc/os-release")
64
65 return var_funcs.key_value_outbuf_to_dict(stdout, delim="=", strip='"')