| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
""" |
| 8 |
The module file for sonic_mgmt_servers |
| 9 |
""" |
| 10 |
|
| 11 |
from __future__ import absolute_import, division, print_function |
| 12 |
__metaclass__ = type |
| 13 |
|
| 14 |
DOCUMENTATION = """ |
| 15 |
--- |
| 16 |
module: sonic_mgmt_servers |
| 17 |
version_added: 2.5.0 |
| 18 |
notes: |
| 19 |
- Tested against Enterprise SONiC Distribution by Dell Technologies. |
| 20 |
- Supports C(check_mode). |
| 21 |
short_description: Manage management servers configuration on SONiC |
| 22 |
description: |
| 23 |
- This module provides configuration management of management servers for devices running SONiC |
| 24 |
author: S. Talabi (@stalabi1) |
| 25 |
options: |
| 26 |
config: |
| 27 |
description: |
| 28 |
- Management servers configuration |
| 29 |
type: dict |
| 30 |
suboptions: |
| 31 |
rest: |
| 32 |
description: |
| 33 |
REST server configuration |
| 34 |
type: dict |
| 35 |
suboptions: |
| 36 |
api_timeout: |
| 37 |
description: |
| 38 |
- Maximum time in seconds the REST server will wait for a REST API request-response cycle to complete |
| 39 |
- Range 0-4294967295 |
| 40 |
type: int |
| 41 |
default: 900 |
| 42 |
client_auth: |
| 43 |
description: |
| 44 |
- Client authentication methods list |
| 45 |
- Specify as a comma separated list. Options for list are password, jwt, cert, and none. |
| 46 |
type: str |
| 47 |
default: password,jwt |
| 48 |
log_level: |
| 49 |
description: |
| 50 |
- Log level of REST server, range 0-255 |
| 51 |
type: int |
| 52 |
default: 0 |
| 53 |
port: |
| 54 |
description: |
| 55 |
- Port that the REST server listens on, range 0-65535 |
| 56 |
type: int |
| 57 |
default: 443 |
| 58 |
read_timeout: |
| 59 |
description: |
| 60 |
- Maximum time in seconds the REST server will wait for an HTTP request-response cycle to complete |
| 61 |
- Range 0-4294967295 |
| 62 |
type: int |
| 63 |
default: 15 |
| 64 |
req_limit: |
| 65 |
description: |
| 66 |
- Maximum number of concurrent requests that the client can make to the REST server |
| 67 |
- Range 0-4294967295 |
| 68 |
type: int |
| 69 |
security_profile: |
| 70 |
description: |
| 71 |
- Name of security profile |
| 72 |
type: str |
| 73 |
shutdown: |
| 74 |
description: |
| 75 |
- Enables/disables REST server from listening on the port |
| 76 |
type: bool |
| 77 |
vrf: |
| 78 |
description: |
| 79 |
- Name of VRF |
| 80 |
type: str |
| 81 |
choices: |
| 82 |
- mgmt |
| 83 |
cipher_suite: |
| 84 |
version_added: 3.1.0 |
| 85 |
description: |
| 86 |
- Cipher suites used for TLS connection with the clients |
| 87 |
- Specify as a comma separated list. Options are ecdhe-ecdsa-with-aes-256-gcm-SHA384, |
| 88 |
ecdhe-ecdsa-with-chacha20-poly1305-SHA256 and ecdhe-ecdsa-with-aes-128-gcm-SHA256. |
| 89 |
type: str |
| 90 |
default: ecdhe-ecdsa-with-aes-256-gcm-SHA384,ecdhe-ecdsa-with-chacha20-poly1305-SHA256,ecdhe-ecdsa-with-aes-128-gcm-SHA256 |
| 91 |
telemetry: |
| 92 |
description: |
| 93 |
- Telemetry server configuration |
| 94 |
type: dict |
| 95 |
suboptions: |
| 96 |
api_timeout: |
| 97 |
description: |
| 98 |
- Maximum time in seconds the telemetry server will wait for a gNMI request-response cycle to complete |
| 99 |
- Range 0-4294967295 |
| 100 |
type: int |
| 101 |
default: 0 |
| 102 |
client_auth: |
| 103 |
description: |
| 104 |
- Client authentication methods list |
| 105 |
- Specify as a comma separated list. Options for list are password, jwt, cert, and none. |
| 106 |
type: str |
| 107 |
default: password,jwt |
| 108 |
jwt_refresh: |
| 109 |
description: |
| 110 |
- Duration of time in seconds before JWT expires and can be refreshed |
| 111 |
- Range 0-4294967295 |
| 112 |
type: int |
| 113 |
default: 900 |
| 114 |
jwt_valid: |
| 115 |
description: |
| 116 |
- Duration of time in seconds for which JWT is valid on the telemetry server |
| 117 |
- Range 0-4294967295 |
| 118 |
type: int |
| 119 |
default: 3600 |
| 120 |
log_level: |
| 121 |
description: |
| 122 |
- Log level of telemetry server, range 0-255 |
| 123 |
type: int |
| 124 |
default: 0 |
| 125 |
port: |
| 126 |
description: |
| 127 |
- Port that the telemetry server listens on, range 0-65535 |
| 128 |
type: int |
| 129 |
default: 8080 |
| 130 |
security_profile: |
| 131 |
description: |
| 132 |
- Name of security profile |
| 133 |
type: str |
| 134 |
vrf: |
| 135 |
description: |
| 136 |
- Name of VRF |
| 137 |
type: str |
| 138 |
choices: |
| 139 |
- mgmt |
| 140 |
state: |
| 141 |
description: |
| 142 |
- The state of the configuration after module completion. |
| 143 |
type: str |
| 144 |
choices: |
| 145 |
- merged |
| 146 |
- deleted |
| 147 |
- overridden |
| 148 |
- replaced |
| 149 |
default: merged |
| 150 |
""" |
| 151 |
|
| 152 |
EXAMPLES = """ |
| 153 |
# Using "merged" state |
| 154 |
# |
| 155 |
# Before state: |
| 156 |
# ------------- |
| 157 |
# |
| 158 |
# sonic# show ip rest |
| 159 |
# |
| 160 |
# Log level is 0 |
| 161 |
# Port is 443 |
| 162 |
# Request limit is not-set |
| 163 |
# Read timeout is 15 seconds |
| 164 |
# Client authentication mode is password,jwt |
| 165 |
# Security profile is not-set |
| 166 |
# API timeout is 900 seconds |
| 167 |
# vrf is not-set |
| 168 |
# Cipher suite is ecdhe-ecdsa-with-aes-256-gcm-SHA384,ecdhe-ecdsa-with-chacha20-poly1305-SHA256,ecdhe-ecdsa-with-aes-128-gcm-SHA256 |
| 169 |
# |
| 170 |
# sonic# show ip telemetry |
| 171 |
# |
| 172 |
# Log level is 0 |
| 173 |
# JWT valid is 3600 seconds |
| 174 |
# JWT refresh is 900 seconds |
| 175 |
# Port is 8080 |
| 176 |
# Client authentication mode is password,jwt |
| 177 |
# Security profile is not-set |
| 178 |
# API timeout is 0 seconds |
| 179 |
# vrf is not-set |
| 180 |
|
| 181 |
- name: Merge mgmt servers configuration |
| 182 |
dellemc.enterprise_sonic.sonic_mgmt_servers: |
| 183 |
config: |
| 184 |
rest: |
| 185 |
api_timeout: 120 |
| 186 |
client_auth: password |
| 187 |
log_level: 6 |
| 188 |
port: 443 |
| 189 |
read_timeout: 60 |
| 190 |
req_limit: 100 |
| 191 |
security_profile: profile1 |
| 192 |
shutdown: true |
| 193 |
vrf: mgmt |
| 194 |
cipher_suite: ecdhe-ecdsa-with-aes-256-gcm-SHA384 |
| 195 |
telemetry: |
| 196 |
api_timeout: 45 |
| 197 |
client_auth: cert,jwt |
| 198 |
jwt_refresh: 80 |
| 199 |
jwt_valid: 300 |
| 200 |
log_level: 10 |
| 201 |
port: 1234 |
| 202 |
security_profile: profile2 |
| 203 |
vrf: mgmt |
| 204 |
state: merged |
| 205 |
|
| 206 |
# After state: |
| 207 |
# ------------ |
| 208 |
# |
| 209 |
# sonic# show ip rest |
| 210 |
# |
| 211 |
# Log level is 6 |
| 212 |
# Port is 443, disabled |
| 213 |
# Request limit is 100 |
| 214 |
# Read timeout is 60 seconds |
| 215 |
# Client authentication mode is password |
| 216 |
# Security profile is profile1 |
| 217 |
# API timeout is 120 seconds |
| 218 |
# vrf is mgmt |
| 219 |
# Cipher suite is ecdhe-ecdsa-with-aes-256-gcm-SHA384 |
| 220 |
# |
| 221 |
# sonic# show ip telemetry |
| 222 |
# |
| 223 |
# Log level is 10 |
| 224 |
# JWT valid is 300 seconds |
| 225 |
# JWT refresh is 80 seconds |
| 226 |
# Port is 1234 |
| 227 |
# Client authentication mode is cert,jwt |
| 228 |
# Security profile is profile2 |
| 229 |
# API timeout is 45 seconds |
| 230 |
# vrf is mgmt |
| 231 |
|
| 232 |
|
| 233 |
# Using "replaced" state |
| 234 |
# |
| 235 |
# Before state: |
| 236 |
# ------------- |
| 237 |
# |
| 238 |
# sonic# show ip rest |
| 239 |
# |
| 240 |
# Log level is 6 |
| 241 |
# Port is 443, disabled |
| 242 |
# Request limit is 100 |
| 243 |
# Read timeout is 60 seconds |
| 244 |
# Client authentication mode is password |
| 245 |
# Security profile is profile1 |
| 246 |
# API timeout is 120 seconds |
| 247 |
# vrf is mgmt |
| 248 |
# Cipher suite is ecdhe-ecdsa-with-aes-256-gcm-SHA384 |
| 249 |
# |
| 250 |
# sonic# show ip telemetry |
| 251 |
# |
| 252 |
# Log level is 10 |
| 253 |
# JWT valid is 300 seconds |
| 254 |
# JWT refresh is 80 seconds |
| 255 |
# Port is 1234 |
| 256 |
# Client authentication mode is cert,jwt |
| 257 |
# Security profile is profile2 |
| 258 |
# API timeout is 45 seconds |
| 259 |
# vrf is mgmt |
| 260 |
|
| 261 |
- name: Replace mgmt servers configuration |
| 262 |
dellemc.enterprise_sonic.sonic_mgmt_servers: |
| 263 |
config: |
| 264 |
rest: |
| 265 |
api_timeout: 180 |
| 266 |
vrf: mgmt |
| 267 |
cipher_suite: ecdhe-ecdsa-with-aes-256-gcm-SHA384,ecdhe-ecdsa-with-chacha20-poly1305-SHA256 |
| 268 |
telemetry: |
| 269 |
log_level: 25 |
| 270 |
security_profile: profile2 |
| 271 |
state: replaced |
| 272 |
|
| 273 |
# After state: |
| 274 |
# ------------ |
| 275 |
# |
| 276 |
# sonic# show ip rest |
| 277 |
# |
| 278 |
# Log level is 0 |
| 279 |
# Port is 443 |
| 280 |
# Request limit is not-set |
| 281 |
# Read timeout is 15 seconds |
| 282 |
# Client authentication mode is password,jwt |
| 283 |
# Security profile is not-set |
| 284 |
# API timeout is 180 seconds |
| 285 |
# vrf is mgmt |
| 286 |
# Cipher suite is ecdhe-ecdsa-with-aes-256-gcm-SHA384,ecdhe-ecdsa-with-chacha20-poly1305-SHA256 |
| 287 |
# |
| 288 |
# sonic# show ip telemetry |
| 289 |
# |
| 290 |
# Log level is 25 |
| 291 |
# JWT valid is 3600 seconds |
| 292 |
# JWT refresh is 900 seconds |
| 293 |
# Port is 8080 |
| 294 |
# Client authentication mode is password,jwt |
| 295 |
# Security profile is profile2 |
| 296 |
# API timeout is 0 seconds |
| 297 |
# vrf is not-set |
| 298 |
|
| 299 |
|
| 300 |
# Using "overridden" state |
| 301 |
# |
| 302 |
# Before state: |
| 303 |
# ------------- |
| 304 |
# |
| 305 |
# sonic# show ip rest |
| 306 |
# |
| 307 |
# Log level is 6 |
| 308 |
# Port is 443, disabled |
| 309 |
# Request limit is 100 |
| 310 |
# Read timeout is 60 seconds |
| 311 |
# Client authentication mode is password |
| 312 |
# Security profile is profile1 |
| 313 |
# API timeout is 120 seconds |
| 314 |
# vrf is mgmt |
| 315 |
# Cipher suite is ecdhe-ecdsa-with-aes-256-gcm-SHA384,ecdhe-ecdsa-with-chacha20-poly1305-SHA256 |
| 316 |
# |
| 317 |
# sonic# show ip telemetry |
| 318 |
# |
| 319 |
# Log level is 10 |
| 320 |
# JWT valid is 300 seconds |
| 321 |
# JWT refresh is 80 seconds |
| 322 |
# Port is 1234 |
| 323 |
# Client authentication mode is cert,jwt |
| 324 |
# Security profile is profile2 |
| 325 |
# API timeout is 45 seconds |
| 326 |
# vrf is mgmt |
| 327 |
|
| 328 |
- name: Override mgmt servers configuration |
| 329 |
dellemc.enterprise_sonic.sonic_mgmt_servers: |
| 330 |
config: |
| 331 |
rest: |
| 332 |
api_timeout: 120 |
| 333 |
client_auth: password |
| 334 |
log_level: 6 |
| 335 |
port: 443 |
| 336 |
read_timeout: 60 |
| 337 |
req_limit: 100 |
| 338 |
security_profile: profile1 |
| 339 |
shutdown: true |
| 340 |
vrf: mgmt |
| 341 |
cipher_suite: ecdhe-ecdsa-with-aes-128-gcm-SHA256,ecdhe-ecdsa-with-aes-256-gcm-SHA384 |
| 342 |
state: overridden |
| 343 |
|
| 344 |
# After state: |
| 345 |
# ------------ |
| 346 |
# |
| 347 |
# sonic# show ip rest |
| 348 |
# |
| 349 |
# Log level is 6 |
| 350 |
# Port is 443, disabled |
| 351 |
# Request limit is 100 |
| 352 |
# Read timeout is 60 seconds |
| 353 |
# Client authentication mode is password |
| 354 |
# Security profile is profile1 |
| 355 |
# API timeout is 120 seconds |
| 356 |
# vrf is mgmt |
| 357 |
# Cipher suite is ecdhe-ecdsa-with-aes-128-gcm-SHA256,ecdhe-ecdsa-with-aes-256-gcm-SHA384 |
| 358 |
# |
| 359 |
# sonic# show ip telemetry |
| 360 |
# |
| 361 |
# Log level is 0 |
| 362 |
# JWT valid is 3600 seconds |
| 363 |
# JWT refresh is 900 seconds |
| 364 |
# Port is 8080 |
| 365 |
# Client authentication mode is password,jwt |
| 366 |
# Security profile is not-set |
| 367 |
# API timeout is 0 seconds |
| 368 |
# vrf is not-set |
| 369 |
|
| 370 |
|
| 371 |
# Using "deleted" state |
| 372 |
# |
| 373 |
# Before state: |
| 374 |
# ------------- |
| 375 |
# |
| 376 |
# sonic# show ip rest |
| 377 |
# |
| 378 |
# Log level is 6 |
| 379 |
# Port is 443, disabled |
| 380 |
# Request limit is 100 |
| 381 |
# Read timeout is 60 seconds |
| 382 |
# Client authentication mode is password |
| 383 |
# Security profile is profile1 |
| 384 |
# API timeout is 120 seconds |
| 385 |
# vrf is mgmt |
| 386 |
# Cipher suite is ecdhe-ecdsa-with-aes-128-gcm-SHA256,ecdhe-ecdsa-with-aes-256-gcm-SHA384 |
| 387 |
# |
| 388 |
# sonic# show ip telemetry |
| 389 |
# |
| 390 |
# Log level is 10 |
| 391 |
# JWT valid is 300 seconds |
| 392 |
# JWT refresh is 80 seconds |
| 393 |
# Port is 1234 |
| 394 |
# Client authentication mode is cert,jwt |
| 395 |
# Security profile is profile2 |
| 396 |
# API timeout is 45 seconds |
| 397 |
# vrf is mgmt |
| 398 |
|
| 399 |
- name: Delete mgmt servers configuration |
| 400 |
dellemc.enterprise_sonic.sonic_mgmt_servers: |
| 401 |
config: |
| 402 |
rest: |
| 403 |
api_timeout: 120 |
| 404 |
client_auth: password |
| 405 |
log_level: 6 |
| 406 |
port: 443 |
| 407 |
read_timeout: 60 |
| 408 |
req_limit: 100 |
| 409 |
security_profile: profile1 |
| 410 |
shutdown: true |
| 411 |
vrf: mgmt |
| 412 |
cipher_suite: ecdhe-ecdsa-with-aes-256-gcm-SHA384,ecdhe-ecdsa-with-aes-128-gcm-SHA256 |
| 413 |
telemetry: |
| 414 |
api_timeout: 45 |
| 415 |
client_auth: cert,jwt |
| 416 |
jwt_refresh: 80 |
| 417 |
jwt_valid: 300 |
| 418 |
log_level: 10 |
| 419 |
port: 1234 |
| 420 |
security_profile: profile2 |
| 421 |
vrf: mgmt |
| 422 |
state: deleted |
| 423 |
|
| 424 |
# After state: |
| 425 |
# ------------ |
| 426 |
# |
| 427 |
# sonic# show ip rest |
| 428 |
# |
| 429 |
# Log level is 0 |
| 430 |
# Port is 443 |
| 431 |
# Request limit is not-set |
| 432 |
# Read timeout is 15 seconds |
| 433 |
# Client authentication mode is password,jwt |
| 434 |
# Security profile is not-set |
| 435 |
# API timeout is 900 seconds |
| 436 |
# vrf is not-set |
| 437 |
# Cipher suite is ecdhe-ecdsa-with-aes-256-gcm-SHA384,ecdhe-ecdsa-with-chacha20-poly1305-SHA256,ecdhe-ecdsa-with-aes-128-gcm-SHA256 |
| 438 |
# |
| 439 |
# sonic# show ip telemetry |
| 440 |
# |
| 441 |
# Log level is 0 |
| 442 |
# JWT valid is 3600 seconds |
| 443 |
# JWT refresh is 900 seconds |
| 444 |
# Port is 8080 |
| 445 |
# Client authentication mode is password,jwt |
| 446 |
# Security profile is not-set |
| 447 |
# API timeout is 0 seconds |
| 448 |
# vrf is not-set |
| 449 |
""" |
| 450 |
|
| 451 |
RETURN = """ |
| 452 |
before: |
| 453 |
description: The configuration prior to the module invocation. |
| 454 |
returned: always |
| 455 |
type: list |
| 456 |
sample: > |
| 457 |
The configuration returned will always be in the same format |
| 458 |
as the parameters above. |
| 459 |
after: |
| 460 |
description: The resulting configuration module invocation. |
| 461 |
returned: when changed |
| 462 |
type: list |
| 463 |
sample: > |
| 464 |
The configuration returned will always be in the same format |
| 465 |
as the parameters above. |
| 466 |
after_generated: |
| 467 |
description: The generated configuration from module invocation. |
| 468 |
returned: when C(check_mode) |
| 469 |
type: list |
| 470 |
sample: > |
| 471 |
The configuration returned will always be in the same format |
| 472 |
as the parameters above. |
| 473 |
commands: |
| 474 |
description: The set of commands pushed to the remote device. |
| 475 |
returned: always |
| 476 |
type: list |
| 477 |
sample: ['command 1', 'command 2', 'command 3'] |
| 478 |
""" |
| 479 |
|
| 480 |
|
| 481 |
from ansible.module_utils.basic import AnsibleModule |
| 482 |
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.mgmt_servers.mgmt_servers import Mgmt_serversArgs |
| 483 |
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.mgmt_servers.mgmt_servers import Mgmt_servers |
| 484 |
|
| 485 |
|
| 486 |
def main(): |
| 487 |
""" |
| 488 |
Main entry point for module execution |
| 489 |
|
| 490 |
:returns: the result form module invocation |
| 491 |
""" |
| 492 |
module = AnsibleModule(argument_spec=Mgmt_serversArgs.argument_spec, |
| 493 |
supports_check_mode=True) |
| 494 |
|
| 495 |
result = Mgmt_servers(module).execute_module() |
| 496 |
module.exit_json(**result) |
| 497 |
|
| 498 |
|
| 499 |
if __name__ == '__main__': |
| 500 |
main() |