| 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_network_settings |
| 20 |
short_description: This module allows you to configure the session inactivity timeout settings |
| 21 |
version_added: "4.4.0" |
| 22 |
description: |
| 23 |
- This module allows you to configure the session inactivity timeout settings on OpenManage Enterprise |
| 24 |
and OpenManage Enterprise Modular. |
| 25 |
extends_documentation_fragment: |
| 26 |
- dellemc.openmanage.ome_auth_options |
| 27 |
options: |
| 28 |
session_inactivity_timeout: |
| 29 |
description: Session inactivity timeout settings. |
| 30 |
type: dict |
| 31 |
suboptions: |
| 32 |
enable_universal_timeout: |
| 33 |
description: |
| 34 |
- Enable or disable the universal inactivity timeout. |
| 35 |
type: bool |
| 36 |
universal_timeout: |
| 37 |
description: |
| 38 |
- Duration of inactivity in minutes after which all sessions end. |
| 39 |
- This is applicable when I(enable_universal_timeout) is C(true). |
| 40 |
- This is mutually exclusive with I(api_timeout), I(gui_timeout), I(ssh_timeout) and I(serial_timeout). |
| 41 |
type: float |
| 42 |
api_timeout: |
| 43 |
description: |
| 44 |
- Duration of inactivity in minutes after which the API session ends. |
| 45 |
- This is mutually exclusive with I(universal_timeout). |
| 46 |
type: float |
| 47 |
api_sessions: |
| 48 |
description: |
| 49 |
- The maximum number of API sessions to be allowed. |
| 50 |
type: int |
| 51 |
gui_timeout: |
| 52 |
description: |
| 53 |
- Duration of inactivity in minutes after which the web interface of |
| 54 |
Graphical User Interface (GUI) session ends. |
| 55 |
- This is mutually exclusive with I(universal_timeout). |
| 56 |
type: float |
| 57 |
gui_sessions: |
| 58 |
description: |
| 59 |
- The maximum number of GUI sessions to be allowed. |
| 60 |
type: int |
| 61 |
ssh_timeout: |
| 62 |
description: |
| 63 |
- Duration of inactivity in minutes after which the SSH session ends. |
| 64 |
- This is applicable only for OpenManage Enterprise Modular. |
| 65 |
- This is mutually exclusive with I(universal_timeout). |
| 66 |
type: float |
| 67 |
ssh_sessions: |
| 68 |
description: |
| 69 |
- The maximum number of SSH sessions to be allowed. |
| 70 |
- This is applicable to OME-M only. |
| 71 |
type: int |
| 72 |
serial_timeout: |
| 73 |
description: |
| 74 |
- Duration of inactivity in minutes after which the serial console session ends. |
| 75 |
- This is applicable only for OpenManage Enterprise Modular. |
| 76 |
- This is mutually exclusive with I(universal_timeout). |
| 77 |
type: float |
| 78 |
serial_sessions: |
| 79 |
description: |
| 80 |
- The maximum number of serial console sessions to be allowed. |
| 81 |
- This is applicable only for OpenManage Enterprise Modular. |
| 82 |
type: int |
| 83 |
requirements: |
| 84 |
- "python >= 3.9.6" |
| 85 |
notes: |
| 86 |
- Run this module from a system that has direct access to Dell OpenManage Enterprise |
| 87 |
or OpenManage Enterprise Modular. |
| 88 |
- To configure other network settings such as network address, web server, and so on, refer to the respective |
| 89 |
OpenManage Enterprise application network setting modules. |
| 90 |
- This module supports C(check_mode). |
| 91 |
author: |
| 92 |
- Sachin Apagundi(@sachin-apa) |
| 93 |
- Sapana Gupta (@sapana05) |
| 94 |
''' |
| 95 |
|
| 96 |
EXAMPLES = """ |
| 97 |
--- |
| 98 |
- name: Configure universal inactivity timeout |
| 99 |
ome_application_network_settings: |
| 100 |
hostname: "192.168.0.1" |
| 101 |
username: "username" |
| 102 |
password: "password" |
| 103 |
ca_path: "/path/to/ca_cert.pem" |
| 104 |
session_inactivity_timeout: |
| 105 |
enable_universal_timeout: true |
| 106 |
universal_timeout: 30 |
| 107 |
api_sessions: 90 |
| 108 |
gui_sessions: 5 |
| 109 |
ssh_sessions: 2 |
| 110 |
serial_sessions: 1 |
| 111 |
|
| 112 |
- name: Configure API and GUI timeout and sessions |
| 113 |
ome_application_network_settings: |
| 114 |
hostname: "192.168.0.1" |
| 115 |
username: "username" |
| 116 |
password: "password" |
| 117 |
ca_path: "/path/to/ca_cert.pem" |
| 118 |
session_inactivity_timeout: |
| 119 |
api_timeout: 20 |
| 120 |
api_sessions: 100 |
| 121 |
gui_timeout: 25 |
| 122 |
gui_sessions: 5 |
| 123 |
|
| 124 |
- name: Configure timeout and sessions for all parameters |
| 125 |
ome_application_network_settings: |
| 126 |
hostname: "192.168.0.1" |
| 127 |
username: "username" |
| 128 |
password: "password" |
| 129 |
ca_path: "/path/to/ca_cert.pem" |
| 130 |
session_inactivity_timeout: |
| 131 |
api_timeout: 20 |
| 132 |
api_sessions: 100 |
| 133 |
gui_timeout: 15 |
| 134 |
gui_sessions: 5 |
| 135 |
ssh_timeout: 30 |
| 136 |
ssh_sessions: 2 |
| 137 |
serial_timeout: 35 |
| 138 |
serial_sessions: 1 |
| 139 |
|
| 140 |
- name: Disable universal timeout and configure timeout and sessions for other parameters |
| 141 |
ome_application_network_settings: |
| 142 |
hostname: "192.168.0.1" |
| 143 |
username: "username" |
| 144 |
password: "password" |
| 145 |
ca_path: "/path/to/ca_cert.pem" |
| 146 |
session_inactivity_timeout: |
| 147 |
enable_universal_timeout: false |
| 148 |
api_timeout: 20 |
| 149 |
api_sessions: 100 |
| 150 |
gui_timeout: 15 |
| 151 |
gui_sessions: 5 |
| 152 |
ssh_timeout: 30 |
| 153 |
ssh_sessions: 2 |
| 154 |
serial_timeout: 35 |
| 155 |
serial_sessions: 1 |
| 156 |
""" |
| 157 |
|
| 158 |
RETURN = """ |
| 159 |
--- |
| 160 |
msg: |
| 161 |
type: str |
| 162 |
description: Overall status of the Session timeout settings. |
| 163 |
returned: always |
| 164 |
sample: "Successfully updated the session timeout settings." |
| 165 |
session_inactivity_setting: |
| 166 |
type: dict |
| 167 |
description: Returned when session inactivity timeout settings are updated successfully. |
| 168 |
returned: success |
| 169 |
sample: [ |
| 170 |
{ |
| 171 |
"SessionType": "API", |
| 172 |
"MaxSessions": 32, |
| 173 |
"SessionTimeout": 99600, |
| 174 |
"MinSessionTimeout": 60000, |
| 175 |
"MaxSessionTimeout": 86400000, |
| 176 |
"MinSessionsAllowed": 1, |
| 177 |
"MaxSessionsAllowed": 100, |
| 178 |
"MaxSessionsConfigurable": true, |
| 179 |
"SessionTimeoutConfigurable": true |
| 180 |
}, |
| 181 |
{ |
| 182 |
"SessionType": "GUI", |
| 183 |
"MaxSessions": 6, |
| 184 |
"SessionTimeout": 99600, |
| 185 |
"MinSessionTimeout": 60000, |
| 186 |
"MaxSessionTimeout": 7200000, |
| 187 |
"MinSessionsAllowed": 1, |
| 188 |
"MaxSessionsAllowed": 6, |
| 189 |
"MaxSessionsConfigurable": true, |
| 190 |
"SessionTimeoutConfigurable": true |
| 191 |
}, |
| 192 |
{ |
| 193 |
"SessionType": "SSH", |
| 194 |
"MaxSessions": 4, |
| 195 |
"SessionTimeout": 99600, |
| 196 |
"MinSessionTimeout": 60000, |
| 197 |
"MaxSessionTimeout": 10800000, |
| 198 |
"MinSessionsAllowed": 1, |
| 199 |
"MaxSessionsAllowed": 4, |
| 200 |
"MaxSessionsConfigurable": true, |
| 201 |
"SessionTimeoutConfigurable": true |
| 202 |
}, |
| 203 |
{ |
| 204 |
"SessionType": "Serial", |
| 205 |
"MaxSessions": 1, |
| 206 |
"SessionTimeout": 99600, |
| 207 |
"MinSessionTimeout": 60000, |
| 208 |
"MaxSessionTimeout": 86400000, |
| 209 |
"MinSessionsAllowed": 1, |
| 210 |
"MaxSessionsAllowed": 1, |
| 211 |
"MaxSessionsConfigurable": false, |
| 212 |
"SessionTimeoutConfigurable": true |
| 213 |
}, |
| 214 |
{ |
| 215 |
"SessionType": "UniversalTimeout", |
| 216 |
"MaxSessions": 0, |
| 217 |
"SessionTimeout": -1, |
| 218 |
"MinSessionTimeout": -1, |
| 219 |
"MaxSessionTimeout": 86400000, |
| 220 |
"MinSessionsAllowed": 0, |
| 221 |
"MaxSessionsAllowed": 0, |
| 222 |
"MaxSessionsConfigurable": false, |
| 223 |
"SessionTimeoutConfigurable": true |
| 224 |
} |
| 225 |
] |
| 226 |
error_info: |
| 227 |
description: Details of the HTTP Error. |
| 228 |
returned: on HTTP error |
| 229 |
type: dict |
| 230 |
sample: { |
| 231 |
"error": { |
| 232 |
"code": "Base.1.0.GeneralError", |
| 233 |
"message": "A general error has occurred. See ExtendedInfo for more information.", |
| 234 |
"@Message.ExtendedInfo": [ |
| 235 |
{ |
| 236 |
"MessageId": "CUSR1233", |
| 237 |
"RelatedProperties": [], |
| 238 |
"Message": "The number of allowed concurrent sessions for API must be between 1 and 100 sessions.", |
| 239 |
"MessageArgs": [ |
| 240 |
"API", |
| 241 |
"1", |
| 242 |
"100" |
| 243 |
], |
| 244 |
"Severity": "Critical", |
| 245 |
"Resolution": "Enter values in the correct range and retry the operation." |
| 246 |
} |
| 247 |
] |
| 248 |
} |
| 249 |
} |
| 250 |
""" |
| 251 |
|
| 252 |
from ssl import SSLError |
| 253 |
from ansible.module_utils.six.moves.urllib.error import URLError, HTTPError |
| 254 |
from ansible.module_utils.urls import ConnectionError |
| 255 |
from ansible_collections.dellemc.openmanage.plugins.module_utils.ome import RestOME, OmeAnsibleModule |
| 256 |
|
| 257 |
SUCCESS_MSG = "Successfully updated the session timeout settings." |
| 258 |
SESSION_INACTIVITY_GET = "SessionService/SessionConfiguration" |
| 259 |
SESSION_INACTIVITY_POST = "SessionService/Actions/SessionService.SessionConfigurationUpdate" |
| 260 |
NO_CHANGES = "No changes found to be applied." |
| 261 |
CHANGES_FOUND = "Changes found to be applied." |
| 262 |
session_type_map = { |
| 263 |
"UniversalTimeout": {"SessionTimeout": "universal_timeout", "MaxSessions": None}, |
| 264 |
"API": {"SessionTimeout": "api_timeout", "MaxSessions": "api_sessions"}, |
| 265 |
"GUI": {"SessionTimeout": "gui_timeout", "MaxSessions": "gui_sessions"}, |
| 266 |
"SSH": {"SessionTimeout": "ssh_timeout", "MaxSessions": "ssh_sessions"}, |
| 267 |
"Serial": {"SessionTimeout": "serial_timeout", "MaxSessions": "serial_sessions"} |
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
def fetch_session_inactivity_settings(rest_obj): |
| 272 |
final_resp = rest_obj.invoke_request("GET", SESSION_INACTIVITY_GET) |
| 273 |
ret_data = final_resp.json_data.get('value') |
| 274 |
return ret_data |
| 275 |
|
| 276 |
|
| 277 |
def update_session_inactivity_settings(rest_obj, payload): |
| 278 |
final_resp = rest_obj.invoke_request("POST", SESSION_INACTIVITY_POST, data=payload) |
| 279 |
return final_resp |
| 280 |
|
| 281 |
|
| 282 |
def update_payload(module, curr_payload): |
| 283 |
diff = 0 |
| 284 |
sit_param = module.params.get("session_inactivity_timeout").copy() |
| 285 |
eut = sit_param.get("enable_universal_timeout") |
| 286 |
eut_enabled = is_universal_timeout_enabled(curr_payload) |
| 287 |
if eut is False: |
| 288 |
sit_param["universal_timeout"] = -1 |
| 289 |
for up in curr_payload: |
| 290 |
stm = session_type_map.get(up.get("SessionType"), None) |
| 291 |
if stm and not ((up.get("SessionType") == "UniversalTimeout") and (eut is None)): |
| 292 |
sess_time = get_value(sit_param, up, stm.get("SessionTimeout", None), "SessionTimeout") |
| 293 |
if sess_time != up.get("SessionTimeout") and ((not eut_enabled) or eut is not None): |
| 294 |
diff += 1 |
| 295 |
up["SessionTimeout"] = sess_time |
| 296 |
max_sess = get_value(sit_param, up, stm.get("MaxSessions", None), "MaxSessions") |
| 297 |
if max_sess != up.get("MaxSessions"): |
| 298 |
diff += 1 |
| 299 |
up["MaxSessions"] = max_sess |
| 300 |
return curr_payload, diff |
| 301 |
|
| 302 |
|
| 303 |
def is_universal_timeout_enabled(payload): |
| 304 |
u_sess_timeout = -1 |
| 305 |
for up in payload: |
| 306 |
if up.get("SessionType") == "UniversalTimeout": |
| 307 |
u_sess_timeout = up.get("SessionTimeout") |
| 308 |
break |
| 309 |
return u_sess_timeout > 0 |
| 310 |
|
| 311 |
|
| 312 |
def get_value(input_module, resp, mod_key, attr_key): |
| 313 |
ret_value = input_module.get(mod_key) |
| 314 |
if ret_value is None: |
| 315 |
ret_value = resp.get(attr_key) |
| 316 |
elif attr_key == "SessionTimeout" and ret_value != -1: |
| 317 |
ret_value = ret_value * 60000 |
| 318 |
return ret_value |
| 319 |
|
| 320 |
|
| 321 |
def process_check_mode(module, diff): |
| 322 |
if not diff: |
| 323 |
module.exit_json(msg=NO_CHANGES) |
| 324 |
elif module.check_mode: |
| 325 |
module.exit_json(msg=CHANGES_FOUND, changed=True) |
| 326 |
|
| 327 |
|
| 328 |
def main(): |
| 329 |
session_inactivity_options = { |
| 330 |
"enable_universal_timeout": {"type": "bool", "required": False}, |
| 331 |
"universal_timeout": {"type": "float", "required": False}, |
| 332 |
"api_timeout": {"type": "float", "required": False}, |
| 333 |
"api_sessions": {"type": "int", "required": False}, |
| 334 |
"gui_timeout": {"type": "float", "required": False}, |
| 335 |
"gui_sessions": {"type": "int", "required": False}, |
| 336 |
"ssh_timeout": {"type": "float", "required": False}, |
| 337 |
"ssh_sessions": {"type": "int", "required": False}, |
| 338 |
"serial_timeout": {"type": "float", "required": False}, |
| 339 |
"serial_sessions": {"type": "int", "required": False}, |
| 340 |
} |
| 341 |
specs = { |
| 342 |
"session_inactivity_timeout": { |
| 343 |
"required": False, |
| 344 |
"type": "dict", |
| 345 |
"options": session_inactivity_options, |
| 346 |
"mutually_exclusive": [ |
| 347 |
['universal_timeout', 'api_timeout'], |
| 348 |
['universal_timeout', 'gui_timeout'], |
| 349 |
['universal_timeout', 'ssh_timeout'], |
| 350 |
['universal_timeout', 'serial_timeout'] |
| 351 |
], |
| 352 |
"required_if": [ |
| 353 |
['enable_universal_timeout', True, ['universal_timeout']] |
| 354 |
] |
| 355 |
} |
| 356 |
} |
| 357 |
|
| 358 |
module = OmeAnsibleModule( |
| 359 |
argument_spec=specs, |
| 360 |
supports_check_mode=True |
| 361 |
) |
| 362 |
try: |
| 363 |
with RestOME(module.params, req_session=True) as rest_obj: |
| 364 |
curr_resp = fetch_session_inactivity_settings(rest_obj) |
| 365 |
payload, diff = update_payload(module, curr_resp) |
| 366 |
process_check_mode(module, diff) |
| 367 |
resp = update_session_inactivity_settings(rest_obj, payload) |
| 368 |
module.exit_json(msg=SUCCESS_MSG, |
| 369 |
session_inactivity_setting=resp.json_data, changed=True) |
| 370 |
|
| 371 |
except HTTPError as err: |
| 372 |
module.exit_json(msg=str(err), failed=True) |
| 373 |
except URLError as err: |
| 374 |
module.exit_json(msg=str(err), unreachable=True) |
| 375 |
except ( |
| 376 |
IOError, ValueError, SSLError, TypeError, ConnectionError, AttributeError, IndexError, KeyError, |
| 377 |
OSError) as err: |
| 378 |
module.exit_json(msg=str(err), failed=True) |
| 379 |
|
| 380 |
|
| 381 |
if __name__ == '__main__': |
| 382 |
main() |