| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
from __future__ import (absolute_import, division, print_function) |
| 14 |
__metaclass__ = type |
| 15 |
|
| 16 |
DOCUMENTATION = r''' |
| 17 |
--- |
| 18 |
module: ome_firmware_baseline_info |
| 19 |
short_description: Retrieves baseline details from OpenManage Enterprise |
| 20 |
version_added: "2.0.0" |
| 21 |
description: |
| 22 |
- This module retrieves the list and details of all the baselines on OpenManage Enterprise. |
| 23 |
extends_documentation_fragment: |
| 24 |
- dellemc.openmanage.ome_auth_options |
| 25 |
options: |
| 26 |
baseline_name: |
| 27 |
description: Name of the baseline.If I(baseline_name) is not provided, |
| 28 |
all the available firmware baselines are returned. |
| 29 |
type: str |
| 30 |
requirements: |
| 31 |
- "python >= 3.9.6" |
| 32 |
author: |
| 33 |
- "Sajna Shetty(@Sajna-Shetty)" |
| 34 |
- "Mangirish Kenkare(@MangirishK)" |
| 35 |
notes: |
| 36 |
- Run this module from a system that has direct access to Dell OpenManage Enterprise. |
| 37 |
- This module supports C(check_mode). |
| 38 |
''' |
| 39 |
|
| 40 |
EXAMPLES = r''' |
| 41 |
--- |
| 42 |
- name: Retrieve details of all the available firmware baselines |
| 43 |
dellemc.openmanage.ome_firmware_baseline_info: |
| 44 |
hostname: "192.168.0.1" |
| 45 |
username: "username" |
| 46 |
password: "password" |
| 47 |
ca_path: "/path/to/ca_cert.pem" |
| 48 |
|
| 49 |
- name: Retrieve details of a specific firmware baseline identified by its baseline name |
| 50 |
dellemc.openmanage.ome_firmware_baseline_info: |
| 51 |
hostname: "192.168.0.1" |
| 52 |
username: "username" |
| 53 |
password: "password" |
| 54 |
ca_path: "/path/to/ca_cert.pem" |
| 55 |
baseline_name: "baseline_name" |
| 56 |
''' |
| 57 |
|
| 58 |
RETURN = r''' |
| 59 |
--- |
| 60 |
msg: |
| 61 |
type: str |
| 62 |
description: Overall baseline information. |
| 63 |
returned: on error |
| 64 |
sample: "Successfully fetched firmware baseline information." |
| 65 |
baseline_info: |
| 66 |
type: dict |
| 67 |
description: Details of the baselines. |
| 68 |
returned: success |
| 69 |
sample: { |
| 70 |
"@odata.id": "/api/UpdateService/Baselines(239)", |
| 71 |
"@odata.type": "#UpdateService.Baselines", |
| 72 |
"CatalogId": 22, |
| 73 |
"ComplianceSummary": { |
| 74 |
"ComplianceStatus": "CRITICAL", |
| 75 |
"NumberOfCritical": 1, |
| 76 |
"NumberOfDowngrade": 0, |
| 77 |
"NumberOfNormal": 0, |
| 78 |
"NumberOfWarning": 0 |
| 79 |
}, |
| 80 |
"Description": "baseline_description", |
| 81 |
"[email protected]": "/api/UpdateService/Baselines(239)/DeviceComplianceReports", |
| 82 |
"DowngradeEnabled": true, |
| 83 |
"Id": 239, |
| 84 |
"Is64Bit": true, |
| 85 |
"LastRun": "2020-05-22 16:42:40.307", |
| 86 |
"Name": "baseline_name", |
| 87 |
"RepositoryId": 12, |
| 88 |
"RepositoryName": "HTTP DELL", |
| 89 |
"RepositoryType": "DELL_ONLINE", |
| 90 |
"Targets": [ |
| 91 |
{ |
| 92 |
"Id": 10342, |
| 93 |
"Type": { |
| 94 |
"Id": 1000, |
| 95 |
"Name": "DEVICE" |
| 96 |
} |
| 97 |
} |
| 98 |
], |
| 99 |
"TaskId": 41415, |
| 100 |
"TaskStatusId": 2060 |
| 101 |
} |
| 102 |
''' |
| 103 |
|
| 104 |
import json |
| 105 |
from ssl import SSLError |
| 106 |
from ansible_collections.dellemc.openmanage.plugins.module_utils.ome import RestOME, OmeAnsibleModule |
| 107 |
from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError |
| 108 |
from ansible.module_utils.urls import ConnectionError |
| 109 |
|
| 110 |
|
| 111 |
def get_specific_baseline(module, baseline_name, resp_data): |
| 112 |
"""Get specific baseline.""" |
| 113 |
baseline = None |
| 114 |
for each in resp_data["value"]: |
| 115 |
if each['Name'] == baseline_name: |
| 116 |
baseline = each |
| 117 |
break |
| 118 |
else: |
| 119 |
module.exit_json(msg="Unable to complete the operation because the requested baseline" |
| 120 |
" with name '{0}' does not exist.".format(baseline_name), baseline_info=[]) |
| 121 |
return baseline |
| 122 |
|
| 123 |
|
| 124 |
def main(): |
| 125 |
specs = { |
| 126 |
"baseline_name": {"type": 'str', "required": False}, |
| 127 |
} |
| 128 |
|
| 129 |
module = OmeAnsibleModule( |
| 130 |
argument_spec=specs, |
| 131 |
supports_check_mode=True |
| 132 |
) |
| 133 |
try: |
| 134 |
with RestOME(module.params, req_session=False) as rest_obj: |
| 135 |
baseline_name = module.params.get("baseline_name") |
| 136 |
resp = rest_obj.invoke_request('GET', "UpdateService/Baselines") |
| 137 |
data = resp.json_data |
| 138 |
if len(data["value"]) == 0 and not baseline_name: |
| 139 |
module.exit_json(msg="No baselines present.", baseline_info=[]) |
| 140 |
if baseline_name is not None: |
| 141 |
data = get_specific_baseline(module, baseline_name, data) |
| 142 |
module.exit_json(msg="Successfully fetched firmware baseline information.", baseline_info=data) |
| 143 |
except HTTPError as err: |
| 144 |
if err.getcode() == 404: |
| 145 |
module.exit_json(msg="404 Not Found.The requested resource is not available.", failed=True) |
| 146 |
module.exit_json(msg=str(err), error_info=json.load(err), failed=True) |
| 147 |
except URLError as err: |
| 148 |
module.exit_json(msg=str(err), unreachable=True) |
| 149 |
except (IOError, ValueError, SSLError, TypeError, ConnectionError, OSError) as err: |
| 150 |
module.exit_json(msg=str(err), failed=True) |
| 151 |
|
| 152 |
|
| 153 |
if __name__ == '__main__': |
| 154 |
main() |