| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
from __future__ import (absolute_import, division, print_function) |
| 14 |
|
| 15 |
__metaclass__ = type |
| 16 |
|
| 17 |
DOCUMENTATION = r''' |
| 18 |
--- |
| 19 |
module: ome_application_console_preferences |
| 20 |
short_description: Configure console preferences on OpenManage Enterprise. |
| 21 |
description: This module allows user to configure the console preferences on OpenManage Enterprise. |
| 22 |
version_added: "5.2.0" |
| 23 |
extends_documentation_fragment: |
| 24 |
- dellemc.openmanage.ome_auth_options |
| 25 |
options: |
| 26 |
report_row_limit: |
| 27 |
description: The maximum number of rows that you can view on OpenManage Enterprise reports. |
| 28 |
type: int |
| 29 |
device_health: |
| 30 |
description: The time after which the health of the devices must be automatically monitored and updated |
| 31 |
on the OpenManage Enterprise dashboard. |
| 32 |
type: dict |
| 33 |
suboptions: |
| 34 |
health_check_interval: |
| 35 |
description: The frequency at which the device health must be recorded and data stored. |
| 36 |
type: int |
| 37 |
health_check_interval_unit: |
| 38 |
description: |
| 39 |
- The time unit of the frequency at which the device health must be recorded and data stored. |
| 40 |
- C(Hourly) to set the frequency in hours. |
| 41 |
- C(Minutes) to set the frequency in minutes. |
| 42 |
type: str |
| 43 |
choices: [Hourly, Minutes] |
| 44 |
health_and_power_state_on_connection_lost: |
| 45 |
description: |
| 46 |
- The latest recorded device health. |
| 47 |
- C(last_known) to display the latest recorded device health when the power connection was lost. |
| 48 |
- C(unknown) to display the latest recorded device health when the device status moved to unknown. |
| 49 |
type: str |
| 50 |
choices: [last_known, unknown] |
| 51 |
discovery_settings: |
| 52 |
description: The device naming to be used by the OpenManage Enterprise to identify the discovered iDRACs |
| 53 |
and other devices. |
| 54 |
type: dict |
| 55 |
suboptions: |
| 56 |
general_device_naming: |
| 57 |
description: |
| 58 |
- Applicable to all the discovered devices other than the iDRACs. |
| 59 |
- C(DNS) to use the DNS name. |
| 60 |
- C(NETBIOS) to use the NetBIOS name. |
| 61 |
type: str |
| 62 |
choices: [DNS, NETBIOS] |
| 63 |
default: DNS |
| 64 |
server_device_naming: |
| 65 |
description: |
| 66 |
- Applicable to iDRACs only. |
| 67 |
- C(IDRAC_HOSTNAME) to use the iDRAC hostname. |
| 68 |
- C(IDRAC_SYSTEM_HOSTNAME) to use the system hostname. |
| 69 |
type: str |
| 70 |
choices: [IDRAC_HOSTNAME, IDRAC_SYSTEM_HOSTNAME] |
| 71 |
default: IDRAC_SYSTEM_HOSTNAME |
| 72 |
invalid_device_hostname: |
| 73 |
description: The invalid hostnames separated by a comma. |
| 74 |
type: str |
| 75 |
common_mac_addresses: |
| 76 |
description: The common MAC addresses separated by a comma. |
| 77 |
type: str |
| 78 |
server_initiated_discovery: |
| 79 |
description: Server initiated discovery settings. |
| 80 |
type: dict |
| 81 |
suboptions: |
| 82 |
device_discovery_approval_policy: |
| 83 |
description: |
| 84 |
- Discovery approval policies. |
| 85 |
- "C(Automatic) allows servers with iDRAC Firmware version 4.00.00.00, which are on the same network as the |
| 86 |
console, to be discovered automatically by the console." |
| 87 |
- C(Manual) for the servers to be discovered by the user manually. |
| 88 |
type: str |
| 89 |
choices: [Automatic, Manual] |
| 90 |
set_trap_destination: |
| 91 |
description: Trap destination settings. |
| 92 |
type: bool |
| 93 |
mx7000_onboarding_preferences: |
| 94 |
description: |
| 95 |
- Alert-forwarding behavior on chassis when they are onboarded. |
| 96 |
- C(all) to receive all alert. |
| 97 |
- C(chassis) to receive chassis category alerts only. |
| 98 |
type: str |
| 99 |
choices: [all, chassis] |
| 100 |
builtin_appliance_share: |
| 101 |
description: The external network share that the appliance must access to complete operations. |
| 102 |
type: dict |
| 103 |
suboptions: |
| 104 |
share_options: |
| 105 |
description: |
| 106 |
- The share options. |
| 107 |
- C(CIFS) to select CIFS share type. |
| 108 |
- C(HTTPS) to select HTTPS share type. |
| 109 |
type: str |
| 110 |
choices: [CIFS, HTTPS] |
| 111 |
cifs_options: |
| 112 |
description: |
| 113 |
- The SMB protocol version. |
| 114 |
- I(cifs_options) is required I(share_options) is C(CIFS). |
| 115 |
- C(V1) to enable SMBv1. |
| 116 |
- C(V2) to enable SMBv2 |
| 117 |
type: str |
| 118 |
choices: [V1, V2] |
| 119 |
email_sender_settings: |
| 120 |
description: The email address of the user who is sending an email message. |
| 121 |
type: str |
| 122 |
trap_forwarding_format: |
| 123 |
description: |
| 124 |
- The trap forwarding format. |
| 125 |
- C(Original) to retain the trap data as is. |
| 126 |
- C(Normalized) to normalize the trap data. |
| 127 |
type: str |
| 128 |
choices: [Original, Normalized] |
| 129 |
metrics_collection_settings: |
| 130 |
description: The frequency of the PowerManager extension data maintenance and purging. |
| 131 |
type: int |
| 132 |
requirements: |
| 133 |
- "python >= 3.9.6" |
| 134 |
notes: |
| 135 |
- This module supports C(check_mode). |
| 136 |
author: |
| 137 |
- Sachin Apagundi(@sachin-apa) |
| 138 |
- Husniya Hameed (@husniya-hameed) |
| 139 |
- ShivamSh3 (@ShivamSh3) |
| 140 |
''' |
| 141 |
|
| 142 |
EXAMPLES = r''' |
| 143 |
--- |
| 144 |
- name: Update Console preferences with all the settings. |
| 145 |
dellemc.openmanage.ome_application_console_preferences: |
| 146 |
hostname: "192.168.0.1" |
| 147 |
username: "username" |
| 148 |
password: "password" |
| 149 |
ca_path: "/path/to/ca_cert.pem" |
| 150 |
report_row_limit: 123 |
| 151 |
device_health: |
| 152 |
health_check_interval: 1 |
| 153 |
health_check_interval_unit: Hourly |
| 154 |
health_and_power_state_on_connection_lost: last_known |
| 155 |
discovery_settings: |
| 156 |
general_device_naming: DNS |
| 157 |
server_device_naming: IDRAC_HOSTNAME |
| 158 |
invalid_device_hostname: "localhost" |
| 159 |
common_mac_addresses: "::" |
| 160 |
server_initiated_discovery: |
| 161 |
device_discovery_approval_policy: Automatic |
| 162 |
set_trap_destination: true |
| 163 |
mx7000_onboarding_preferences: all |
| 164 |
builtin_appliance_share: |
| 165 |
share_options: CIFS |
| 166 |
cifs_options: V1 |
| 167 |
email_sender_settings: "[email protected]" |
| 168 |
trap_forwarding_format: Normalized |
| 169 |
metrics_collection_settings: 31 |
| 170 |
|
| 171 |
- name: Update Console preferences with report and device health settings. |
| 172 |
dellemc.openmanage.ome_application_console_preferences: |
| 173 |
hostname: "192.168.0.1" |
| 174 |
username: "username" |
| 175 |
password: "password" |
| 176 |
ca_path: "/path/to/ca_cert.pem" |
| 177 |
report_row_limit: 236 |
| 178 |
device_health: |
| 179 |
health_check_interval: 10 |
| 180 |
health_check_interval_unit: Hourly |
| 181 |
health_and_power_state_on_connection_lost: last_known |
| 182 |
|
| 183 |
- name: Update Console preferences with invalid device health settings. |
| 184 |
dellemc.openmanage.ome_application_console_preferences: |
| 185 |
hostname: "192.168.0.1" |
| 186 |
username: "username" |
| 187 |
password: "password" |
| 188 |
ca_path: "/path/to/ca_cert.pem" |
| 189 |
device_health: |
| 190 |
health_check_interval: 65 |
| 191 |
health_check_interval_unit: Minutes |
| 192 |
|
| 193 |
- name: Update Console preferences with discovery and built in appliance share settings. |
| 194 |
dellemc.openmanage.ome_application_console_preferences: |
| 195 |
hostname: "192.168.0.1" |
| 196 |
username: "username" |
| 197 |
password: "password" |
| 198 |
ca_path: "/path/to/ca_cert.pem" |
| 199 |
discovery_settings: |
| 200 |
general_device_naming: DNS |
| 201 |
server_device_naming: IDRAC_SYSTEM_HOSTNAME |
| 202 |
invalid_device_hostname: "localhost" |
| 203 |
common_mac_addresses: "00:53:45:00:00:00" |
| 204 |
builtin_appliance_share: |
| 205 |
share_options: CIFS |
| 206 |
cifs_options: V1 |
| 207 |
|
| 208 |
- name: Update Console preferences with server initiated discovery, mx7000 onboarding preferences, email sender, |
| 209 |
trap forwarding format, and metrics collection settings. |
| 210 |
dellemc.openmanage.ome_application_console_preferences: |
| 211 |
hostname: "192.168.0.1" |
| 212 |
username: "username" |
| 213 |
password: "password" |
| 214 |
ca_path: "/path/to/ca_cert.pem" |
| 215 |
server_initiated_discovery: |
| 216 |
device_discovery_approval_policy: Automatic |
| 217 |
set_trap_destination: true |
| 218 |
mx7000_onboarding_preferences: chassis |
| 219 |
email_sender_settings: "[email protected]" |
| 220 |
trap_forwarding_format: Original |
| 221 |
metrics_collection_settings: 365 |
| 222 |
''' |
| 223 |
|
| 224 |
RETURN = r''' |
| 225 |
--- |
| 226 |
msg: |
| 227 |
type: str |
| 228 |
description: Overall status of the console preferences. |
| 229 |
returned: always |
| 230 |
sample: "Successfully update the console preferences." |
| 231 |
console_preferences: |
| 232 |
type: list |
| 233 |
description: Details of the console preferences. |
| 234 |
returned: on success |
| 235 |
sample: |
| 236 |
[ |
| 237 |
{ |
| 238 |
"Name": "DEVICE_PREFERRED_NAME", |
| 239 |
"DefaultValue": "SLOT_NAME", |
| 240 |
"Value": "PREFER_DNS,PREFER_IDRAC_SYSTEM_HOSTNAME", |
| 241 |
"DataType": "java.lang.String", |
| 242 |
"GroupName": "DISCOVERY_SETTING" |
| 243 |
}, |
| 244 |
{ |
| 245 |
"Name": "INVALID_DEVICE_HOSTNAME", |
| 246 |
"DefaultValue": "", |
| 247 |
"Value": "localhost,localhost.localdomain,not defined,pv132t,pv136t,default,dell,idrac-", |
| 248 |
"DataType": "java.lang.String", |
| 249 |
"GroupName": "DISCOVERY_SETTING" |
| 250 |
}, |
| 251 |
{ |
| 252 |
"Name": "COMMON_MAC_ADDRESSES", |
| 253 |
"DefaultValue": "", |
| 254 |
"Value": "00:53:45:00:00:00,33:50:6F:45:30:30,50:50:54:50:30:30,00:00:FF:FF:FF:FF,20:41:53:59:4E:FF,00:00:00:00:00:00,20:41:53:59:4e:ff,00:00:00:00:00:00", |
| 255 |
"DataType": "java.lang.String", |
| 256 |
"GroupName": "DISCOVERY_SETTING" |
| 257 |
}, |
| 258 |
{ |
| 259 |
"Name": "SHARE_TYPE", |
| 260 |
"DefaultValue": "CIFS", |
| 261 |
"Value": "CIFS", |
| 262 |
"DataType": "java.lang.String", |
| 263 |
"GroupName": "BUILT_IN_APPLIANCE_SHARE_SETTINGS" |
| 264 |
}, |
| 265 |
{ |
| 266 |
"Name": "TRAP_FORWARDING_SETTING", |
| 267 |
"DefaultValue": "AsIs", |
| 268 |
"Value": "Normalized", |
| 269 |
"DataType": "java.lang.String", |
| 270 |
"GroupName": "" |
| 271 |
}, |
| 272 |
{ |
| 273 |
"Name": "DATA_PURGE_INTERVAL", |
| 274 |
"DefaultValue": "365", |
| 275 |
"Value": "3650000", |
| 276 |
"DataType": "java.lang.Integer", |
| 277 |
"GroupName": "" |
| 278 |
}, |
| 279 |
{ |
| 280 |
"Name": "CONSOLE_CONNECTION_SETTING", |
| 281 |
"DefaultValue": "last_known", |
| 282 |
"Value": "last_known", |
| 283 |
"DataType": "java.lang.String", |
| 284 |
"GroupName": "CONSOLE_CONNECTION_SETTING" |
| 285 |
}, |
| 286 |
{ |
| 287 |
"Name": "MIN_PROTOCOL_VERSION", |
| 288 |
"DefaultValue": "V2", |
| 289 |
"Value": "V1", |
| 290 |
"DataType": "java.lang.String", |
| 291 |
"GroupName": "CIFS_PROTOCOL_SETTINGS" |
| 292 |
}, |
| 293 |
{ |
| 294 |
"Name": "ALERT_ACKNOWLEDGEMENT_VIEW", |
| 295 |
"DefaultValue": "2000", |
| 296 |
"Value": "2000", |
| 297 |
"DataType": "java.lang.Integer", |
| 298 |
"GroupName": "" |
| 299 |
}, |
| 300 |
{ |
| 301 |
"Name": "AUTO_CONSOLE_UPDATE_AFTER_DOWNLOAD", |
| 302 |
"DefaultValue": "false", |
| 303 |
"Value": "false", |
| 304 |
"DataType": "java.lang.Boolean", |
| 305 |
"GroupName": "CONSOLE_UPDATE_SETTING_GROUP" |
| 306 |
}, |
| 307 |
{ |
| 308 |
"Name": "NODE_INITIATED_DISCOVERY_SET_TRAP_DESTINATION", |
| 309 |
"DefaultValue": "false", |
| 310 |
"Value": "false", |
| 311 |
"DataType": "java.lang.Boolean", |
| 312 |
"GroupName": "" |
| 313 |
}, |
| 314 |
{ |
| 315 |
"Name": "REPORTS_MAX_RESULTS_LIMIT", |
| 316 |
"DefaultValue": "0", |
| 317 |
"Value": "2000000000000000000000000", |
| 318 |
"DataType": "java.lang.Integer", |
| 319 |
"GroupName": "" |
| 320 |
}, |
| 321 |
{ |
| 322 |
"Name": "EMAIL_SENDER", |
| 323 |
"DefaultValue": "[email protected]", |
| 324 |
"Value": "[email protected]@[email protected]", |
| 325 |
"DataType": "java.lang.String", |
| 326 |
"GroupName": "" |
| 327 |
}, |
| 328 |
{ |
| 329 |
"Name": "MX7000_ONBOARDING_PREF", |
| 330 |
"DefaultValue": "all", |
| 331 |
"Value": "test_chassis", |
| 332 |
"DataType": "java.lang.String", |
| 333 |
"GroupName": "" |
| 334 |
}, |
| 335 |
{ |
| 336 |
"Name": "DISCOVERY_APPROVAL_POLICY", |
| 337 |
"DefaultValue": "Automatic", |
| 338 |
"Value": "Automatic_test", |
| 339 |
"DataType": "java.lang.String", |
| 340 |
"GroupName": "" |
| 341 |
} |
| 342 |
] |
| 343 |
error_info: |
| 344 |
description: Details of the HTTP error. |
| 345 |
returned: on HTTP error |
| 346 |
type: dict |
| 347 |
sample: |
| 348 |
{ |
| 349 |
"error": { |
| 350 |
"code": "Base.1.0.GeneralError", |
| 351 |
"message": "A general error has occurred. See ExtendedInfo for more information.", |
| 352 |
"@Message.ExtendedInfo": [ |
| 353 |
{ |
| 354 |
"MessageId": "CGEN1006", |
| 355 |
"RelatedProperties": [], |
| 356 |
"Message": "Unable to complete the request because the resource URI does not exist or is not implemented.", |
| 357 |
"MessageArgs": [], |
| 358 |
"Severity": "Critical", |
| 359 |
"Resolution": "Enter a valid URI and retry the operation." |
| 360 |
} |
| 361 |
] |
| 362 |
} |
| 363 |
} |
| 364 |
''' |
| 365 |
|
| 366 |
import json |
| 367 |
from ssl import SSLError |
| 368 |
from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError |
| 369 |
from ansible.module_utils.urls import ConnectionError |
| 370 |
from ansible_collections.dellemc.openmanage.plugins.module_utils.ome import RestOME, OmeAnsibleModule |
| 371 |
from ansible_collections.dellemc.openmanage.plugins.module_utils.utils import strip_substr_dict |
| 372 |
|
| 373 |
SUCCESS_MSG = "Successfully updated the Console Preferences settings." |
| 374 |
SETTINGS_URL = "ApplicationService/Settings" |
| 375 |
NO_CHANGES = "No changes found to be applied." |
| 376 |
CHANGES_FOUND = "Changes found to be applied." |
| 377 |
HEALTH_CHECK_UNIT_REQUIRED = "The health check unit is required when health check interval is specified." |
| 378 |
HEALTH_CHECK_INTERVAL_REQUIRED = "The health check interval is required when health check unit is specified." |
| 379 |
HEALTH_CHECK_INTERVAL_INVALID = "The health check interval specified is invalid for the {0}" |
| 380 |
JOB_URL = "JobService/Jobs" |
| 381 |
CIFS_URL = "ApplicationService/Actions/ApplicationService.UpdateShareTypeSettings" |
| 382 |
CONSOLE_SETTINGS_VALUES = ["DATA_PURGE_INTERVAL", "EMAIL_SENDER", "TRAP_FORWARDING_SETTING", |
| 383 |
"MX7000_ONBOARDING_PREF", "REPORTS_MAX_RESULTS_LIMIT", |
| 384 |
"DISCOVERY_APPROVAL_POLICY", "NODE_INITIATED_DISCOVERY_SET_TRAP_DESTINATION", |
| 385 |
"DEVICE_PREFERRED_NAME", "INVALID_DEVICE_HOSTNAME", "COMMON_MAC_ADDRESSES", |
| 386 |
"CONSOLE_CONNECTION_SETTING", "MIN_PROTOCOL_VERSION", "SHARE_TYPE"] |
| 387 |
|
| 388 |
|
| 389 |
def job_details(rest_obj): |
| 390 |
query_param = {"$filter": "JobType/Id eq 6"} |
| 391 |
job_resp = rest_obj.invoke_request("GET", JOB_URL, query_param=query_param) |
| 392 |
job_data = job_resp.json_data.get('value') |
| 393 |
tmp_list = [x["Id"] for x in job_data] |
| 394 |
sorted_id = sorted(tmp_list) |
| 395 |
latest_job = [val for val in job_data if val["Id"] == sorted_id[-1]] |
| 396 |
return latest_job[0] |
| 397 |
|
| 398 |
|
| 399 |
def create_job(module): |
| 400 |
schedule = None |
| 401 |
job_payload = None |
| 402 |
device_health = module.params.get("device_health") |
| 403 |
if device_health: |
| 404 |
if device_health.get("health_check_interval_unit") == "Hourly": |
| 405 |
schedule = "0 0 0/" + str(device_health.get("health_check_interval")) + " 1/1 * ? *" |
| 406 |
elif device_health.get("health_check_interval_unit") == "Minutes": |
| 407 |
schedule = "0 0/" + str(device_health.get("health_check_interval")) + " * 1/1 * ? *" |
| 408 |
job_payload = {"Id": 0, |
| 409 |
"JobName": "Global Health Task", |
| 410 |
"JobDescription": "Global Health Task", |
| 411 |
"Schedule": schedule, |
| 412 |
"State": "Enabled", |
| 413 |
"JobType": {"Id": 6, "Name": "Health_Task"}, |
| 414 |
"Params": [{"Key": "metricType", "Value": "40, 50"}], |
| 415 |
"Targets": [{"Id": 500, "Data": "", "TargetType": {"Id": 6000, "Name": "GROUP"}}]} |
| 416 |
return job_payload, schedule |
| 417 |
|
| 418 |
|
| 419 |
def fetch_cp_settings(rest_obj): |
| 420 |
final_resp = rest_obj.invoke_request("GET", SETTINGS_URL) |
| 421 |
ret_data = final_resp.json_data.get('value') |
| 422 |
return ret_data |
| 423 |
|
| 424 |
|
| 425 |
def create_payload_dict(curr_payload): |
| 426 |
payload = {} |
| 427 |
for pay in curr_payload: |
| 428 |
payload[pay["Name"]] = pay |
| 429 |
return payload |
| 430 |
|
| 431 |
|
| 432 |
def create_payload(module, curr_payload): |
| 433 |
console_setting_list = [] |
| 434 |
updated_payload = {"ConsoleSetting": []} |
| 435 |
payload_dict = create_payload_dict(curr_payload) |
| 436 |
get_sid = module.params.get("server_initiated_discovery") |
| 437 |
get_ds = module.params.get("discovery_settings") |
| 438 |
get_mcs = module.params.get("metrics_collection_settings") |
| 439 |
get_email = module.params.get("email_sender_settings") |
| 440 |
get_tff = module.params.get("trap_forwarding_format") |
| 441 |
get_mx = module.params.get("mx7000_onboarding_preferences") |
| 442 |
get_rrl = module.params.get("report_row_limit") |
| 443 |
get_dh = module.params.get("device_health") |
| 444 |
get_bas = module.params.get("builtin_appliance_share") |
| 445 |
if get_mcs: |
| 446 |
payload1 = payload_dict["DATA_PURGE_INTERVAL"].copy() |
| 447 |
payload1["Value"] = get_mcs |
| 448 |
console_setting_list.append(payload1) |
| 449 |
if get_email: |
| 450 |
payload2 = payload_dict["EMAIL_SENDER"].copy() |
| 451 |
payload2["Value"] = get_email |
| 452 |
console_setting_list.append(payload2) |
| 453 |
if get_tff: |
| 454 |
dict1 = {"Original": "AsIs", "Normalized": "Normalized"} |
| 455 |
payload3 = payload_dict["TRAP_FORWARDING_SETTING"].copy() |
| 456 |
payload3["Value"] = dict1.get(get_tff) |
| 457 |
console_setting_list.append(payload3) |
| 458 |
if get_mx: |
| 459 |
payload4 = payload_dict["MX7000_ONBOARDING_PREF"].copy() |
| 460 |
payload4["Value"] = get_mx |
| 461 |
console_setting_list.append(payload4) |
| 462 |
if get_rrl: |
| 463 |
payload5 = payload_dict["REPORTS_MAX_RESULTS_LIMIT"].copy() |
| 464 |
payload5["Value"] = get_rrl |
| 465 |
console_setting_list.append(payload5) |
| 466 |
if get_sid: |
| 467 |
if get_sid.get("device_discovery_approval_policy"): |
| 468 |
payload6 = payload_dict["DISCOVERY_APPROVAL_POLICY"].copy() |
| 469 |
payload6["Value"] = get_sid.get("device_discovery_approval_policy") |
| 470 |
console_setting_list.append(payload6) |
| 471 |
if get_sid.get("set_trap_destination") is not None: |
| 472 |
payload7 = payload_dict["NODE_INITIATED_DISCOVERY_SET_TRAP_DESTINATION"].copy() |
| 473 |
payload7["Value"] = get_sid.get("set_trap_destination") |
| 474 |
console_setting_list.append(payload7) |
| 475 |
if get_ds: |
| 476 |
if get_ds.get("general_device_naming") and get_ds.get("server_device_naming"): |
| 477 |
value = "PREFER_" + module.params["discovery_settings"]["general_device_naming"] + "," + "PREFER_" +\ |
| 478 |
get_ds["server_device_naming"] |
| 479 |
payload8 = payload_dict["DEVICE_PREFERRED_NAME"].copy() |
| 480 |
payload8["Value"] = value |
| 481 |
console_setting_list.append(payload8) |
| 482 |
elif get_ds.get("general_device_naming"): |
| 483 |
payload9 = payload_dict["DEVICE_PREFERRED_NAME"].copy() |
| 484 |
payload9["Value"] = "PREFER_" + get_ds["general_device_naming"] |
| 485 |
console_setting_list.append(payload9) |
| 486 |
elif get_ds.get("server_device_naming"): |
| 487 |
payload10 = payload_dict["DEVICE_PREFERRED_NAME"].copy() |
| 488 |
payload10["Value"] = "PREFER_" + get_ds["server_device_naming"] |
| 489 |
console_setting_list.append(payload10) |
| 490 |
if get_ds.get("invalid_device_hostname"): |
| 491 |
payload11 = payload_dict["INVALID_DEVICE_HOSTNAME"].copy() |
| 492 |
payload11["Value"] = get_ds.get("invalid_device_hostname") |
| 493 |
console_setting_list.append(payload11) |
| 494 |
if get_ds.get("common_mac_addresses"): |
| 495 |
payload12 = payload_dict["COMMON_MAC_ADDRESSES"].copy() |
| 496 |
payload12["Value"] = get_ds.get("common_mac_addresses") |
| 497 |
console_setting_list.append(payload12) |
| 498 |
if get_dh and get_dh.get("health_and_power_state_on_connection_lost"): |
| 499 |
payload13 = payload_dict["CONSOLE_CONNECTION_SETTING"].copy() |
| 500 |
payload13["Value"] = get_dh.get("health_and_power_state_on_connection_lost") |
| 501 |
console_setting_list.append(payload13) |
| 502 |
if get_bas and get_bas.get("share_options") == "CIFS": |
| 503 |
payload14 = payload_dict["MIN_PROTOCOL_VERSION"].copy() |
| 504 |
payload14["Value"] = get_bas.get("cifs_options") |
| 505 |
console_setting_list.append(payload14) |
| 506 |
updated_payload["ConsoleSetting"] = console_setting_list |
| 507 |
return updated_payload, payload_dict |
| 508 |
|
| 509 |
|
| 510 |
def create_cifs_payload(module, curr_payload): |
| 511 |
console_setting_list = [] |
| 512 |
updated_payload = {"ConsoleSetting": []} |
| 513 |
payload_dict = create_payload_dict(curr_payload) |
| 514 |
get_bas = module.params.get("builtin_appliance_share") |
| 515 |
if get_bas and get_bas.get("share_options"): |
| 516 |
payload = payload_dict["SHARE_TYPE"].copy() |
| 517 |
payload["Value"] = get_bas.get("share_options") |
| 518 |
console_setting_list.append(payload) |
| 519 |
updated_payload["ConsoleSetting"] = console_setting_list |
| 520 |
return updated_payload |
| 521 |
|
| 522 |
|
| 523 |
def update_console_preferences(module, rest_obj, payload, payload_cifs, job_payload, job, payload_dict, schedule): |
| 524 |
cifs_resp = None |
| 525 |
job_final_resp = None |
| 526 |
get_bas = module.params.get("builtin_appliance_share") |
| 527 |
device_health = module.params.get("device_health") |
| 528 |
[payload["ConsoleSetting"].remove(i) for i in payload["ConsoleSetting"] if i["Name"] == "SHARE_TYPE"] |
| 529 |
if device_health and device_health.get("health_check_interval_unit") and job["Schedule"] != schedule: |
| 530 |
job_final_resp = rest_obj.invoke_request("POST", JOB_URL, data=job_payload) |
| 531 |
if get_bas and get_bas.get("share_options") and payload_dict["SHARE_TYPE"]["Value"] != \ |
| 532 |
get_bas.get("share_options"): |
| 533 |
cifs_resp = rest_obj.invoke_request("POST", CIFS_URL, data=payload_cifs) |
| 534 |
final_resp = rest_obj.invoke_request("POST", SETTINGS_URL, data=payload) |
| 535 |
return final_resp, cifs_resp, job_final_resp |
| 536 |
|
| 537 |
|
| 538 |
def _diff_payload(curr_resp, update_resp, payload_cifs, schedule, job_det): |
| 539 |
diff = 0 |
| 540 |
update_resp["ConsoleSetting"].extend(payload_cifs["ConsoleSetting"]) |
| 541 |
if schedule and job_det["Schedule"] != schedule: |
| 542 |
diff += 1 |
| 543 |
for i in curr_resp: |
| 544 |
for j in update_resp["ConsoleSetting"]: |
| 545 |
if i["Name"] == j["Name"]: |
| 546 |
if isinstance(j["Value"], bool): |
| 547 |
j["Value"] = str(j["Value"]).lower() |
| 548 |
if isinstance(j["Value"], int): |
| 549 |
j["Value"] = str(j["Value"]) |
| 550 |
if i["Value"] != j["Value"]: |
| 551 |
diff += 1 |
| 552 |
return diff |
| 553 |
|
| 554 |
|
| 555 |
def process_check_mode(module, diff): |
| 556 |
if not diff: |
| 557 |
module.exit_json(msg=NO_CHANGES) |
| 558 |
elif diff and module.check_mode: |
| 559 |
module.exit_json(msg=CHANGES_FOUND, changed=True) |
| 560 |
|
| 561 |
|
| 562 |
def _validate_params(module): |
| 563 |
error_message = _validate_health_check_interval(module) |
| 564 |
if error_message: |
| 565 |
module.exit_json(msg=error_message, failed=True) |
| 566 |
|
| 567 |
|
| 568 |
def _validate_health_check_interval(module): |
| 569 |
error_message = None |
| 570 |
device_health = module.params.get("device_health") |
| 571 |
if device_health: |
| 572 |
hci = device_health.get("health_check_interval") |
| 573 |
hciu = device_health.get("health_check_interval_unit") |
| 574 |
if hci and not hciu: |
| 575 |
error_message = HEALTH_CHECK_UNIT_REQUIRED |
| 576 |
if hciu and not hci: |
| 577 |
error_message = HEALTH_CHECK_INTERVAL_REQUIRED |
| 578 |
if hciu and hci: |
| 579 |
if hciu == "Hourly" and (hci < 1 or hci > 23): |
| 580 |
error_message = HEALTH_CHECK_INTERVAL_INVALID.format(hciu) |
| 581 |
if hciu == "Minutes" and (hci < 1 or hci > 59): |
| 582 |
error_message = HEALTH_CHECK_INTERVAL_INVALID.format(hciu) |
| 583 |
return error_message |
| 584 |
|
| 585 |
|
| 586 |
def main(): |
| 587 |
device_health_opt = {"health_check_interval": {"type": "int", "required": False}, |
| 588 |
"health_check_interval_unit": {"type": "str", "required": False, |
| 589 |
"choices": ["Hourly", "Minutes"]}, |
| 590 |
"health_and_power_state_on_connection_lost": {"type": "str", "required": False, |
| 591 |
"choices": ["last_known", "unknown"]} |
| 592 |
} |
| 593 |
discovery_settings_opt = { |
| 594 |
"general_device_naming": {"type": "str", "required": False, "default": "DNS", |
| 595 |
"choices": ["DNS", "NETBIOS"]}, |
| 596 |
"server_device_naming": {"type": "str", "required": False, "default": "IDRAC_SYSTEM_HOSTNAME", |
| 597 |
"choices": ["IDRAC_HOSTNAME", "IDRAC_SYSTEM_HOSTNAME"]}, |
| 598 |
"invalid_device_hostname": {"type": "str", "required": False}, |
| 599 |
"common_mac_addresses": {"type": "str", "required": False} |
| 600 |
} |
| 601 |
server_initiated_discovery_opt = { |
| 602 |
"device_discovery_approval_policy": {"type": "str", "required": False, "choices": ["Automatic", "Manual"]}, |
| 603 |
"set_trap_destination": {"type": "bool", "required": False, }, |
| 604 |
} |
| 605 |
builtin_appliance_share_opt = { |
| 606 |
"share_options": {"type": "str", "required": False, |
| 607 |
"choices": ["CIFS", "HTTPS"]}, |
| 608 |
"cifs_options": {"type": "str", "required": False, |
| 609 |
"choices": ["V1", "V2"] |
| 610 |
}, |
| 611 |
} |
| 612 |
|
| 613 |
specs = { |
| 614 |
"report_row_limit": {"required": False, "type": "int"}, |
| 615 |
"device_health": {"required": False, "type": "dict", |
| 616 |
"options": device_health_opt |
| 617 |
}, |
| 618 |
"discovery_settings": {"required": False, "type": "dict", |
| 619 |
"options": discovery_settings_opt |
| 620 |
}, |
| 621 |
"server_initiated_discovery": {"required": False, "type": "dict", |
| 622 |
"options": server_initiated_discovery_opt |
| 623 |
}, |
| 624 |
"mx7000_onboarding_preferences": {"required": False, "type": "str", "choices": ["all", "chassis"]}, |
| 625 |
"builtin_appliance_share": {"required": False, "type": "dict", |
| 626 |
"options": builtin_appliance_share_opt, |
| 627 |
"required_if": [['share_options', "CIFS", ('cifs_options',)]] |
| 628 |
}, |
| 629 |
"email_sender_settings": {"required": False, "type": "str"}, |
| 630 |
"trap_forwarding_format": {"required": False, "type": "str", "choices": ["Normalized", "Original"]}, |
| 631 |
"metrics_collection_settings": {"required": False, "type": "int"}, |
| 632 |
} |
| 633 |
|
| 634 |
module = OmeAnsibleModule(argument_spec=specs, |
| 635 |
required_one_of=[["report_row_limit", "device_health", "discovery_settings", |
| 636 |
"server_initiated_discovery", "mx7000_onboarding_preferences", |
| 637 |
"builtin_appliance_share", "email_sender_settings", |
| 638 |
"trap_forwarding_format", "metrics_collection_settings"]], |
| 639 |
supports_check_mode=True) |
| 640 |
|
| 641 |
try: |
| 642 |
_validate_params(module) |
| 643 |
with RestOME(module.params, req_session=True) as rest_obj: |
| 644 |
job = job_details(rest_obj) |
| 645 |
job_payload, schedule = create_job(module) |
| 646 |
curr_resp = fetch_cp_settings(rest_obj) |
| 647 |
payload, payload_dict = create_payload(module, curr_resp) |
| 648 |
cifs_payload = create_cifs_payload(module, curr_resp) |
| 649 |
diff = _diff_payload(curr_resp, payload, cifs_payload, schedule, job) |
| 650 |
process_check_mode(module, diff) |
| 651 |
resp, cifs_resp, job_resp = update_console_preferences(module, rest_obj, payload, cifs_payload, |
| 652 |
job_payload, job, payload_dict, schedule) |
| 653 |
resp_req = fetch_cp_settings(rest_obj) |
| 654 |
cp_list = [] |
| 655 |
resp_data = list(filter(lambda d: d['Name'] in CONSOLE_SETTINGS_VALUES, resp_req)) |
| 656 |
for cp in resp_data: |
| 657 |
cp_data = strip_substr_dict(cp) |
| 658 |
cp_list.append(cp_data) |
| 659 |
module.exit_json(msg=SUCCESS_MSG, console_preferences=cp_list, changed=True) |
| 660 |
except HTTPError as err: |
| 661 |
module.exit_json(msg=str(err), error_info=json.load(err), failed=True) |
| 662 |
except URLError as err: |
| 663 |
module.exit_json(msg=str(err), unreachable=True) |
| 664 |
except (IOError, ValueError, SSLError, TypeError, ConnectionError, AttributeError, IndexError, KeyError, OSError) as err: |
| 665 |
module.exit_json(msg=str(err), failed=True) |
| 666 |
|
| 667 |
|
| 668 |
if __name__ == '__main__': |
| 669 |
main() |