George Keishing | e7e9171 | 2021-09-03 11:28:44 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Michael Walsh | 6dbdfef | 2018-05-30 10:35:26 -0500 | [diff] [blame] | 2 | |
| 3 | r""" |
| 4 | This file contains utilities associated with the host OS. |
| 5 | """ |
| 6 | |
George Keishing | b1cfbde | 2018-05-30 11:50:07 -0500 | [diff] [blame] | 7 | import sys |
| 8 | import os |
| 9 | |
| 10 | sys.path.append(os.path.join(os.path.dirname(__file__), "../lib")) |
| 11 | |
Michael Walsh | 6dbdfef | 2018-05-30 10:35:26 -0500 | [diff] [blame] | 12 | import bmc_ssh_utils |
| 13 | import var_funcs |
| 14 | |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 15 | |
Michael Walsh | 6dbdfef | 2018-05-30 10:35:26 -0500 | [diff] [blame] | 16 | def get_os_release_info(): |
| 17 | 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 |
| 61 | """ |
| 62 | |
| 63 | stdout, stderr, rc =\ |
| 64 | bmc_ssh_utils.os_execute_command("cat /etc/os-release") |
| 65 | |
| 66 | return var_funcs.key_value_outbuf_to_dict(stdout, delim="=", strip='"') |