| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
__metaclass__ = type |
| 9 |
|
| 10 |
DOCUMENTATION = r''' |
| 11 |
--- |
| 12 |
module: bigiq_device_info |
| 13 |
short_description: Collect information from F5 BIG-IQ devices |
| 14 |
description: |
| 15 |
- Collect information from F5 BIG-IQ devices. |
| 16 |
- This module was called C(bigiq_device_facts) before Ansible 2.9. The usage did not change. |
| 17 |
version_added: "1.0.0" |
| 18 |
options: |
| 19 |
gather_subset: |
| 20 |
description: |
| 21 |
- When supplied, this argument restricts the information returned to a given subset. |
| 22 |
- You can specify a list of values to include a larger subset. |
| 23 |
- Values can also be used with an initial C(!) to specify a specific subset |
| 24 |
should not be collected. |
| 25 |
type: list |
| 26 |
elements: str |
| 27 |
required: True |
| 28 |
choices: |
| 29 |
- all |
| 30 |
- applications |
| 31 |
- managed-devices |
| 32 |
- purchased-pool-licenses |
| 33 |
- regkey-pools |
| 34 |
- system-info |
| 35 |
- vlans |
| 36 |
- "!all" |
| 37 |
- "!applications" |
| 38 |
- "!managed-devices" |
| 39 |
- "!purchased-pool-licenses" |
| 40 |
- "!regkey-pools" |
| 41 |
- "!system-info" |
| 42 |
- "!vlans" |
| 43 |
extends_documentation_fragment: f5networks.f5_modules.f5 |
| 44 |
notes: |
| 45 |
- This module is supported with all BIG-IQ versions |
| 46 |
- With BIGIQ 7.0 and later, a few metadata fields not included/supported (for example, uptime, product_changelist, product_jobid) |
| 47 |
author: |
| 48 |
- Tim Rupp (@caphrim007) |
| 49 |
''' |
| 50 |
|
| 51 |
EXAMPLES = r''' |
| 52 |
- name: Collect BIG-IQ information |
| 53 |
bigiq_device_info: |
| 54 |
gather_subset: |
| 55 |
- system-info |
| 56 |
- vlans |
| 57 |
provider: |
| 58 |
server: lb.mydomain.com |
| 59 |
user: admin |
| 60 |
password: secret |
| 61 |
delegate_to: localhost |
| 62 |
|
| 63 |
- name: Collect all BIG-IQ information |
| 64 |
bigiq_device_info: |
| 65 |
gather_subset: |
| 66 |
- all |
| 67 |
provider: |
| 68 |
server: cm.mydomain.com |
| 69 |
user: admin |
| 70 |
password: secret |
| 71 |
delegate_to: localhost |
| 72 |
|
| 73 |
- name: Collect all BIG-IP information except trunks |
| 74 |
bigiq_device_info: |
| 75 |
gather_subset: |
| 76 |
- all |
| 77 |
- "!trunks" |
| 78 |
provider: |
| 79 |
server: cm.mydomain.com |
| 80 |
user: admin |
| 81 |
password: secret |
| 82 |
delegate_to: localhost |
| 83 |
''' |
| 84 |
|
| 85 |
RETURN = r''' |
| 86 |
applications: |
| 87 |
description: Application related information |
| 88 |
returned: When C(managed-devices) is specified in C(gather_subset). |
| 89 |
type: complex |
| 90 |
contains: |
| 91 |
protection_mode: |
| 92 |
description: |
| 93 |
- The type of F5 Web Application Security Service protection on the application. |
| 94 |
returned: changed |
| 95 |
type: str |
| 96 |
sample: Not Protected |
| 97 |
id: |
| 98 |
description: |
| 99 |
- ID of the application as known to the BIG-IQ. |
| 100 |
returned: changed |
| 101 |
type: str |
| 102 |
sample: 996baae8-5d1d-3662-8a2d-3612fa2aceae |
| 103 |
name: |
| 104 |
description: |
| 105 |
- Name of the application. |
| 106 |
returned: changed |
| 107 |
type: str |
| 108 |
sample: site12http.example.com |
| 109 |
status: |
| 110 |
description: |
| 111 |
- Current state of the application. |
| 112 |
returned: changed |
| 113 |
type: str |
| 114 |
sample: DEPLOYED |
| 115 |
transactions_per_second: |
| 116 |
description: |
| 117 |
- Current measurement of Transactions Per second being handled by the application. |
| 118 |
returned: changed |
| 119 |
type: float |
| 120 |
sample: 0.87 |
| 121 |
connections: |
| 122 |
description: |
| 123 |
- Current number of connections established to the application. |
| 124 |
returned: changed |
| 125 |
type: float |
| 126 |
sample: 3.06 |
| 127 |
new_connections: |
| 128 |
description: |
| 129 |
- Number of new connections being established per second. |
| 130 |
returned: changed |
| 131 |
type: float |
| 132 |
sample: 0.35 |
| 133 |
response_time: |
| 134 |
description: |
| 135 |
- Measured response time of the application in milliseconds. |
| 136 |
returned: changed |
| 137 |
type: float |
| 138 |
sample: 0.02 |
| 139 |
health: |
| 140 |
description: |
| 141 |
- Health of the application. |
| 142 |
returned: changed |
| 143 |
type: str |
| 144 |
sample: Good |
| 145 |
active_alerts: |
| 146 |
description: |
| 147 |
- Number of alerts active on the application. |
| 148 |
returned: changed |
| 149 |
type: int |
| 150 |
sample: 0 |
| 151 |
bad_traffic: |
| 152 |
description: |
| 153 |
- Percent of traffic to application that is determined to be 'bad'. |
| 154 |
- This value is dependent on C(protection_mode) being enabled. |
| 155 |
returned: changed |
| 156 |
type: float |
| 157 |
sample: 1.7498 |
| 158 |
enhanced_analytics: |
| 159 |
description: |
| 160 |
- Whether enhanced analytics is enabled for the application or not. |
| 161 |
returned: changed |
| 162 |
type: bool |
| 163 |
sample: true |
| 164 |
bad_traffic_growth: |
| 165 |
description: |
| 166 |
- Whether or not Bad Traffic Growth alerts are configured to be triggered or not. |
| 167 |
returned: changed |
| 168 |
type: bool |
| 169 |
sample: false |
| 170 |
sample: hash/dictionary of values |
| 171 |
managed_devices: |
| 172 |
description: Managed device related information. |
| 173 |
returned: When C(managed-devices) is specified in C(gather_subset). |
| 174 |
type: complex |
| 175 |
contains: |
| 176 |
address: |
| 177 |
description: |
| 178 |
- Address where the device was discovered. |
| 179 |
returned: changed |
| 180 |
type: str |
| 181 |
sample: 10.10.10.10 |
| 182 |
build: |
| 183 |
description: |
| 184 |
- Build of the version. |
| 185 |
returned: changed |
| 186 |
type: str |
| 187 |
sample: 0.0.4 |
| 188 |
device_uri: |
| 189 |
description: |
| 190 |
- URI to reach the management interface of the device. |
| 191 |
returned: changed |
| 192 |
type: str |
| 193 |
sample: "https://10.10.10.10:443" |
| 194 |
edition: |
| 195 |
description: |
| 196 |
- Edition string of the product version. |
| 197 |
returned: changed |
| 198 |
type: str |
| 199 |
sample: Final |
| 200 |
group_name: |
| 201 |
description: |
| 202 |
- BIG-IQ group that the device is a member of. |
| 203 |
returned: changed |
| 204 |
type: str |
| 205 |
sample: cm-bigip-allBigIpDevices |
| 206 |
hostname: |
| 207 |
description: |
| 208 |
- Discovered hostname of the device. |
| 209 |
returned: changed |
| 210 |
type: str |
| 211 |
sample: tier2labB1.lab.fp.foo.com |
| 212 |
https_port: |
| 213 |
description: |
| 214 |
- HTTPS port available on the management interface of the device. |
| 215 |
returned: changed |
| 216 |
type: int |
| 217 |
sample: 443 |
| 218 |
is_clustered: |
| 219 |
description: |
| 220 |
- Whether the device is clustered or not. |
| 221 |
returned: changed |
| 222 |
type: bool |
| 223 |
sample: false |
| 224 |
is_license_expired: |
| 225 |
description: |
| 226 |
- Whether the license on the device is expired or not. |
| 227 |
returned: changed |
| 228 |
type: bool |
| 229 |
sample: true |
| 230 |
is_virtual: |
| 231 |
description: |
| 232 |
- Whether the device is a virtual edition or not. |
| 233 |
returned: changed |
| 234 |
type: bool |
| 235 |
sample: true |
| 236 |
machine_id: |
| 237 |
description: |
| 238 |
- Machine specific ID assigned to this device by BIG-IQ. |
| 239 |
returned: changed |
| 240 |
type: str |
| 241 |
sample: c141bc88-f734-4434-be64-a3e9ea98356e |
| 242 |
management_address: |
| 243 |
description: |
| 244 |
- IP address of the management interface on the device. |
| 245 |
returned: changed |
| 246 |
type: str |
| 247 |
sample: 10.10.10.10 |
| 248 |
mcp_device_name: |
| 249 |
description: |
| 250 |
- Device name as known by MCPD on the BIG-IP. |
| 251 |
returned: changed |
| 252 |
type: str |
| 253 |
sample: /Common/tier2labB1.lab.fp.foo.com |
| 254 |
product: |
| 255 |
description: |
| 256 |
- Product that the managed device is identified as. |
| 257 |
returned: changed |
| 258 |
type: str |
| 259 |
sample: BIG-IP |
| 260 |
rest_framework_version: |
| 261 |
description: |
| 262 |
- REST framework version running on the device |
| 263 |
returned: changed |
| 264 |
type: str |
| 265 |
sample: 13.1.1-0.0.4 |
| 266 |
self_link: |
| 267 |
description: |
| 268 |
- Internal reference to the managed device in BIG-IQ. |
| 269 |
returned: changed |
| 270 |
type: str |
| 271 |
sample: "https://localhost/mgmt/shared/resolver/device-groups/cm-bigip-allBigIpDevices/devices/c141bc88-f734-4434-be64-a3e9ea98356e" |
| 272 |
slots: |
| 273 |
description: |
| 274 |
- Volumes on the device and versions of software installed in those volumes. |
| 275 |
returned: changed |
| 276 |
type: dict |
| 277 |
sample: {"volume": "HD1.1", "product": "BIG-IP", "version": "13.1.1", "build": "0.0.4", "isActive": "yes"} |
| 278 |
state: |
| 279 |
description: |
| 280 |
- State of the device. |
| 281 |
returned: changed |
| 282 |
type: str |
| 283 |
sample: ACTIVE |
| 284 |
tags: |
| 285 |
description: |
| 286 |
- Misc tags that are assigned to the device. |
| 287 |
returned: changed |
| 288 |
type: dict |
| 289 |
sample: {'BIGIQ_tier_2_device': '2018-08-22T13:30:47.693-07:00', 'BIGIQ_SSG_name': 'tim-ssg'} |
| 290 |
trust_domain_guid: |
| 291 |
description: |
| 292 |
- GUID of the trust domain the device is part of. |
| 293 |
returned: changed |
| 294 |
type: str |
| 295 |
sample: 40ddf541-e604-4905-bde3005056813e36 |
| 296 |
uuid: |
| 297 |
description: |
| 298 |
- UUID of the device in BIG-IQ. |
| 299 |
returned: changed |
| 300 |
type: str |
| 301 |
sample: c141bc88-f734-4434-be64-a3e9ea98356e |
| 302 |
version: |
| 303 |
description: |
| 304 |
- Version of TMOS installed on the device. |
| 305 |
returned: changed |
| 306 |
type: str |
| 307 |
sample: 13.1.1 |
| 308 |
sample: hash/dictionary of values |
| 309 |
purchased_pool_licenses: |
| 310 |
description: Purchased Pool License related information. |
| 311 |
returned: When C(purchased-pool-licenses) is specified in C(gather_subset). |
| 312 |
type: complex |
| 313 |
contains: |
| 314 |
base_reg_key: |
| 315 |
description: |
| 316 |
- Base registration key of the purchased pool |
| 317 |
returned: changed |
| 318 |
type: str |
| 319 |
sample: XXXXX-XXXXX-XXXXX-XXXXX-XXXXXXX |
| 320 |
dossier: |
| 321 |
description: |
| 322 |
- Dossier of the purchased pool license |
| 323 |
returned: changed |
| 324 |
type: str |
| 325 |
sample: d6bd4b8ba5...e9a1a1199b73af9932948a |
| 326 |
free_device_licenses: |
| 327 |
description: |
| 328 |
- Number of free licenses remaining. |
| 329 |
returned: changed |
| 330 |
type: int |
| 331 |
sample: 34 |
| 332 |
name: |
| 333 |
description: |
| 334 |
- Name of the purchased pool |
| 335 |
returned: changed |
| 336 |
type: str |
| 337 |
sample: my-pool1 |
| 338 |
state: |
| 339 |
description: |
| 340 |
- State of the purchased pool license |
| 341 |
returned: changed |
| 342 |
type: str |
| 343 |
sample: LICENSED |
| 344 |
total_device_licenses: |
| 345 |
description: |
| 346 |
- Total number of licenses in the pool. |
| 347 |
returned: changed |
| 348 |
type: int |
| 349 |
sample: 40 |
| 350 |
uuid: |
| 351 |
description: |
| 352 |
- UUID of the purchased pool license |
| 353 |
returned: changed |
| 354 |
type: str |
| 355 |
sample: b2112329-cba7-4f1f-9a26-fab9be416d60 |
| 356 |
vendor: |
| 357 |
description: |
| 358 |
- Vendor who provided the license |
| 359 |
returned: changed |
| 360 |
type: str |
| 361 |
sample: F5 Networks, Inc |
| 362 |
licensed_date_time: |
| 363 |
description: |
| 364 |
- Timestamp that the pool was licensed. |
| 365 |
returned: changed |
| 366 |
type: str |
| 367 |
sample: "2018-09-10T00:00:00-07:00" |
| 368 |
licensed_version: |
| 369 |
description: |
| 370 |
- Version of BIG-IQ that is licensed. |
| 371 |
returned: changed |
| 372 |
type: str |
| 373 |
sample: 6.0.1 |
| 374 |
evaluation_start_date_time: |
| 375 |
description: |
| 376 |
- Date that evaluation license starts. |
| 377 |
returned: changed |
| 378 |
type: str |
| 379 |
sample: "2018-09-09T00:00:00-07:00" |
| 380 |
evaluation_end_date_time: |
| 381 |
description: |
| 382 |
- Date that evaluation license ends. |
| 383 |
returned: changed |
| 384 |
type: str |
| 385 |
sample: "2018-10-11T00:00:00-07:00" |
| 386 |
license_end_date_time: |
| 387 |
description: |
| 388 |
- Date that the license expires. |
| 389 |
returned: changed |
| 390 |
type: str |
| 391 |
sample: "2018-10-11T00:00:00-07:00" |
| 392 |
license_start_date_time: |
| 393 |
description: |
| 394 |
- Date that the license starts. |
| 395 |
returned: changed |
| 396 |
type: str |
| 397 |
sample: "2018-09-09T00:00:00-07:00" |
| 398 |
registration_key: |
| 399 |
description: |
| 400 |
- Purchased pool license key. |
| 401 |
returned: changed |
| 402 |
type: str |
| 403 |
sample: XXXXX-XXXXX-XXXXX-XXXXX-XXXXXXX |
| 404 |
sample: hash/dictionary of values |
| 405 |
regkey_pools: |
| 406 |
description: Regkey Pool related information. |
| 407 |
returned: When C(regkey-pools) is specified in C(gather_subset). |
| 408 |
type: complex |
| 409 |
contains: |
| 410 |
name: |
| 411 |
description: |
| 412 |
- Name of the regkey pool. |
| 413 |
returned: changed |
| 414 |
type: str |
| 415 |
sample: pool1 |
| 416 |
id: |
| 417 |
description: |
| 418 |
- ID of the regkey pool. |
| 419 |
returned: changed |
| 420 |
type: str |
| 421 |
sample: 4f9b565c-0831-4657-b6c2-6dde6182a502 |
| 422 |
total_offerings: |
| 423 |
description: |
| 424 |
- Total number of offerings in the pool |
| 425 |
returned: changed |
| 426 |
type: int |
| 427 |
sample: 10 |
| 428 |
offerings: |
| 429 |
description: List of the offerings in the pool. |
| 430 |
type: complex |
| 431 |
contains: |
| 432 |
dossier: |
| 433 |
description: |
| 434 |
- Dossier of the license. |
| 435 |
returned: changed |
| 436 |
type: str |
| 437 |
sample: d6bd4b8ba5...e9a1a1199b73af9932948a |
| 438 |
name: |
| 439 |
description: |
| 440 |
- Name of the regkey. |
| 441 |
returned: changed |
| 442 |
type: str |
| 443 |
sample: regkey1 |
| 444 |
state: |
| 445 |
description: |
| 446 |
- State of the regkey license |
| 447 |
returned: changed |
| 448 |
type: str |
| 449 |
sample: LICENSED |
| 450 |
licensed_date_time: |
| 451 |
description: |
| 452 |
- Timestamp that the regkey was licensed. |
| 453 |
returned: changed |
| 454 |
type: str |
| 455 |
sample: "2018-09-10T00:00:00-07:00" |
| 456 |
licensed_version: |
| 457 |
description: |
| 458 |
- Version of BIG-IQ that is licensed. |
| 459 |
returned: changed |
| 460 |
type: str |
| 461 |
sample: 6.0.1 |
| 462 |
evaluation_start_date_time: |
| 463 |
description: |
| 464 |
- Date that evaluation license starts. |
| 465 |
returned: changed |
| 466 |
type: str |
| 467 |
sample: "2018-09-09T00:00:00-07:00" |
| 468 |
evaluation_end_date_time: |
| 469 |
description: |
| 470 |
- Date that evaluation license ends. |
| 471 |
returned: changed |
| 472 |
type: str |
| 473 |
sample: "2018-10-11T00:00:00-07:00" |
| 474 |
license_end_date_time: |
| 475 |
description: |
| 476 |
- Date that the license expires. |
| 477 |
returned: changed |
| 478 |
type: str |
| 479 |
sample: "2018-10-11T00:00:00-07:00" |
| 480 |
license_start_date_time: |
| 481 |
description: |
| 482 |
- Date that the license starts. |
| 483 |
returned: changed |
| 484 |
type: str |
| 485 |
sample: "2018-09-09T00:00:00-07:00" |
| 486 |
registration_key: |
| 487 |
description: |
| 488 |
- Registration license key. |
| 489 |
returned: changed |
| 490 |
type: str |
| 491 |
sample: XXXXX-XXXXX-XXXXX-XXXXX-XXXXXXX |
| 492 |
sample: hash/dictionary of values |
| 493 |
sample: hash/dictionary of values |
| 494 |
system_info: |
| 495 |
description: System info related information. |
| 496 |
returned: When C(system-info) is specified in C(gather_subset). |
| 497 |
type: complex |
| 498 |
contains: |
| 499 |
base_mac_address: |
| 500 |
description: |
| 501 |
- Media Access Control address (MAC address) of the device. |
| 502 |
returned: changed |
| 503 |
type: str |
| 504 |
sample: "fa:16:3e:c3:42:6f" |
| 505 |
marketing_name: |
| 506 |
description: |
| 507 |
- Marketing name of the device platform. |
| 508 |
returned: changed |
| 509 |
type: str |
| 510 |
sample: BIG-IQ Virtual Edition |
| 511 |
time: |
| 512 |
description: |
| 513 |
- Mapping of the current time information to specific time-named keys. |
| 514 |
returned: changed |
| 515 |
type: complex |
| 516 |
contains: |
| 517 |
day: |
| 518 |
description: |
| 519 |
- The current day of the month, in numeric form. |
| 520 |
returned: changed |
| 521 |
type: int |
| 522 |
sample: 7 |
| 523 |
hour: |
| 524 |
description: |
| 525 |
- The current hour of the day in 24-hour form. |
| 526 |
returned: changed |
| 527 |
type: int |
| 528 |
sample: 18 |
| 529 |
minute: |
| 530 |
description: |
| 531 |
- The current minute of the hour. |
| 532 |
returned: changed |
| 533 |
type: int |
| 534 |
sample: 16 |
| 535 |
month: |
| 536 |
description: |
| 537 |
- The current month, in numeric form. |
| 538 |
returned: changed |
| 539 |
type: int |
| 540 |
sample: 6 |
| 541 |
second: |
| 542 |
description: |
| 543 |
- The current second of the minute. |
| 544 |
returned: changed |
| 545 |
type: int |
| 546 |
sample: 51 |
| 547 |
year: |
| 548 |
description: |
| 549 |
- The current year in 4-digit form. |
| 550 |
returned: changed |
| 551 |
type: int |
| 552 |
sample: 2018 |
| 553 |
hardware_information: |
| 554 |
description: |
| 555 |
- Information related to the hardware (drives and CPUs) of the system. |
| 556 |
type: complex |
| 557 |
returned: changed |
| 558 |
contains: |
| 559 |
model: |
| 560 |
description: |
| 561 |
- The model of the hardware. |
| 562 |
type: str |
| 563 |
sample: Virtual Disk |
| 564 |
name: |
| 565 |
description: |
| 566 |
- The name of the hardware. |
| 567 |
type: str |
| 568 |
sample: HD1 |
| 569 |
type: |
| 570 |
description: |
| 571 |
- The type of hardware. |
| 572 |
type: str |
| 573 |
sample: physical-disk |
| 574 |
versions: |
| 575 |
description: |
| 576 |
- Hardware specific properties |
| 577 |
type: complex |
| 578 |
contains: |
| 579 |
name: |
| 580 |
description: |
| 581 |
- Name of the property |
| 582 |
type: str |
| 583 |
sample: Size |
| 584 |
version: |
| 585 |
description: |
| 586 |
- Value of the property |
| 587 |
type: str |
| 588 |
sample: 154.00G |
| 589 |
is_admin_password_changed: |
| 590 |
description: |
| 591 |
- Whether the admin password was changed from its default or not. |
| 592 |
returned: changed |
| 593 |
type: bool |
| 594 |
sample: true |
| 595 |
is_root_password_changed: |
| 596 |
description: |
| 597 |
- Whether the root password was changed from its default or not. |
| 598 |
returned: changed |
| 599 |
type: bool |
| 600 |
sample: false |
| 601 |
is_system_setup: |
| 602 |
description: |
| 603 |
- Whether the system has been setup or not. |
| 604 |
returned: changed |
| 605 |
type: bool |
| 606 |
sample: true |
| 607 |
package_edition: |
| 608 |
description: |
| 609 |
- Displays the software edition. |
| 610 |
returned: changed |
| 611 |
type: str |
| 612 |
sample: Point Release 7 |
| 613 |
package_version: |
| 614 |
description: |
| 615 |
- A string combining the C(product_build) and C(product_build_date). |
| 616 |
type: str |
| 617 |
sample: "Build 0.0.1 - Tue May 15 15:26:30 PDT 2018" |
| 618 |
product_code: |
| 619 |
description: |
| 620 |
- Code identifying the product. |
| 621 |
type: str |
| 622 |
sample: BIG-IQ |
| 623 |
product_build: |
| 624 |
description: |
| 625 |
- Build version of the release version. |
| 626 |
type: str |
| 627 |
sample: 0.0.1 |
| 628 |
product_version: |
| 629 |
description: |
| 630 |
- Major product version of the running software. |
| 631 |
type: str |
| 632 |
sample: 6.0.0 |
| 633 |
product_built: |
| 634 |
description: |
| 635 |
- Unix timestamp of when the product was built. |
| 636 |
type: int |
| 637 |
sample: 180515152630 |
| 638 |
product_build_date: |
| 639 |
description: |
| 640 |
- Human readable build date. |
| 641 |
type: str |
| 642 |
sample: "Tue May 15 15:26:30 PDT 2018" |
| 643 |
product_changelist: |
| 644 |
description: |
| 645 |
- Changelist that product branches from. |
| 646 |
- Not supported with BIGIQ 7.0 and later versions |
| 647 |
type: int |
| 648 |
sample: 2557198 |
| 649 |
product_jobid: |
| 650 |
description: |
| 651 |
- ID of the job that built the product version. |
| 652 |
- Not supported with BIGIQ 7.0 and later versions |
| 653 |
type: int |
| 654 |
sample: 1012030 |
| 655 |
chassis_serial: |
| 656 |
description: |
| 657 |
- Serial of the chassis |
| 658 |
type: str |
| 659 |
sample: 11111111-2222-3333-444444444444 |
| 660 |
host_board_part_revision: |
| 661 |
description: |
| 662 |
- Revision of the host board. |
| 663 |
type: str |
| 664 |
host_board_serial: |
| 665 |
description: |
| 666 |
- Serial of the host board. |
| 667 |
type: str |
| 668 |
platform: |
| 669 |
description: |
| 670 |
- Platform identifier. |
| 671 |
type: str |
| 672 |
sample: Z100 |
| 673 |
switch_board_part_revision: |
| 674 |
description: |
| 675 |
- Switch board revision. |
| 676 |
type: str |
| 677 |
switch_board_serial: |
| 678 |
description: |
| 679 |
- Serial of the switch board. |
| 680 |
type: str |
| 681 |
uptime: |
| 682 |
description: |
| 683 |
- Time, in seconds, since the system booted. |
| 684 |
- Not supported with BIGIQ 7.0 and later versions |
| 685 |
type: int |
| 686 |
sample: 603202 |
| 687 |
sample: hash/dictionary of values |
| 688 |
vlans: |
| 689 |
description: List of VLAN information. |
| 690 |
returned: When C(vlans) is specified in C(gather_subset). |
| 691 |
type: complex |
| 692 |
contains: |
| 693 |
auto_lasthop: |
| 694 |
description: |
| 695 |
- Allows the system to send return traffic to the MAC address that transmitted the |
| 696 |
request, even if the routing table points to a different network or interface. |
| 697 |
returned: changed |
| 698 |
type: str |
| 699 |
sample: enabled |
| 700 |
cmp_hash_algorithm: |
| 701 |
description: |
| 702 |
- Specifies how the traffic on the VLAN will be disaggregated. |
| 703 |
returned: changed |
| 704 |
type: str |
| 705 |
sample: default |
| 706 |
description: |
| 707 |
description: |
| 708 |
- Description of the VLAN. |
| 709 |
returned: changed |
| 710 |
type: str |
| 711 |
sample: My vlan |
| 712 |
failsafe_action: |
| 713 |
description: |
| 714 |
- Action for the system to take when the fail-safe mechanism is triggered. |
| 715 |
returned: changed |
| 716 |
type: str |
| 717 |
sample: reboot |
| 718 |
failsafe_enabled: |
| 719 |
description: |
| 720 |
- Whether failsafe is enabled or not. |
| 721 |
returned: changed |
| 722 |
type: bool |
| 723 |
sample: true |
| 724 |
failsafe_timeout: |
| 725 |
description: |
| 726 |
- Number of seconds that an active unit can run without detecting network traffic |
| 727 |
on this VLAN before it starts a failover. |
| 728 |
returned: changed |
| 729 |
type: int |
| 730 |
sample: 90 |
| 731 |
if_index: |
| 732 |
description: |
| 733 |
- Index assigned to this VLAN. It is a unique identifier assigned for all objects |
| 734 |
displayed in the SNMP IF-MIB. |
| 735 |
returned: changed |
| 736 |
type: int |
| 737 |
sample: 176 |
| 738 |
learning_mode: |
| 739 |
description: |
| 740 |
- Whether switch ports placed in the VLAN are configured for switch learning, |
| 741 |
forwarding only, or dropped. |
| 742 |
returned: changed |
| 743 |
type: str |
| 744 |
sample: enable-forward |
| 745 |
interfaces: |
| 746 |
description: |
| 747 |
- List of tagged or untagged interfaces and trunks that you want to configure for the VLAN. |
| 748 |
returned: changed |
| 749 |
type: complex |
| 750 |
contains: |
| 751 |
full_path: |
| 752 |
description: |
| 753 |
- Full name of the resource as known to BIG-IP. |
| 754 |
returned: changed |
| 755 |
type: str |
| 756 |
sample: 1.3 |
| 757 |
name: |
| 758 |
description: |
| 759 |
- Relative name of the resource in BIG-IP. |
| 760 |
returned: changed |
| 761 |
type: str |
| 762 |
sample: 1.3 |
| 763 |
tagged: |
| 764 |
description: |
| 765 |
- Whether the interface is tagged or not. |
| 766 |
returned: changed |
| 767 |
type: bool |
| 768 |
sample: false |
| 769 |
mtu: |
| 770 |
description: |
| 771 |
- Specific maximum transition unit (MTU) for the VLAN. |
| 772 |
returned: changed |
| 773 |
type: int |
| 774 |
sample: 1500 |
| 775 |
sflow_poll_interval: |
| 776 |
description: |
| 777 |
- Maximum interval in seconds between two pollings. |
| 778 |
returned: changed |
| 779 |
type: int |
| 780 |
sample: 0 |
| 781 |
sflow_poll_interval_global: |
| 782 |
description: |
| 783 |
- Whether the global VLAN poll-interval setting, overrides the object-level |
| 784 |
poll-interval setting. |
| 785 |
returned: changed |
| 786 |
type: bool |
| 787 |
sample: false |
| 788 |
sflow_sampling_rate: |
| 789 |
description: |
| 790 |
- Ratio of packets observed to the samples generated. |
| 791 |
returned: changed |
| 792 |
type: int |
| 793 |
sample: 0 |
| 794 |
sflow_sampling_rate_global: |
| 795 |
description: |
| 796 |
- Whether the global VLAN sampling-rate setting, overrides the object-level |
| 797 |
sampling-rate setting. |
| 798 |
returned: changed |
| 799 |
type: bool |
| 800 |
sample: true |
| 801 |
source_check_enabled: |
| 802 |
description: |
| 803 |
- Specifies that only connections that have a return route in the routing table are accepted. |
| 804 |
returned: changed |
| 805 |
type: bool |
| 806 |
sample: true |
| 807 |
true_mac_address: |
| 808 |
description: |
| 809 |
- Media access control (MAC) address for the lowest-numbered interface assigned to this VLAN. |
| 810 |
returned: changed |
| 811 |
type: str |
| 812 |
sample: "fa:16:3e:10:da:ff" |
| 813 |
tag: |
| 814 |
description: |
| 815 |
- Tag number for the VLAN. |
| 816 |
returned: changed |
| 817 |
type: int |
| 818 |
sample: 30 |
| 819 |
sample: hash/dictionary of values |
| 820 |
''' |
| 821 |
|
| 822 |
import copy |
| 823 |
import datetime |
| 824 |
import traceback |
| 825 |
import math |
| 826 |
import re |
| 827 |
|
| 828 |
try: |
| 829 |
from packaging.version import Version |
| 830 |
except ImportError: |
| 831 |
HAS_PACKAGING = False |
| 832 |
Version = None |
| 833 |
PACKAGING_IMPORT_ERROR = traceback.format_exc() |
| 834 |
else: |
| 835 |
HAS_PACKAGING = True |
| 836 |
PACKAGING_IMPORT_ERROR = None |
| 837 |
|
| 838 |
from ansible.module_utils.basic import ( |
| 839 |
AnsibleModule, missing_required_lib |
| 840 |
) |
| 841 |
|
| 842 |
from ansible.module_utils.six import ( |
| 843 |
iteritems, string_types |
| 844 |
) |
| 845 |
|
| 846 |
from ..module_utils.bigip import F5RestClient |
| 847 |
from ..module_utils.common import ( |
| 848 |
F5ModuleError, AnsibleF5Parameters, f5_argument_spec, flatten_boolean, transform_name |
| 849 |
) |
| 850 |
from ..module_utils.icontrol import bigiq_version |
| 851 |
from ..module_utils.teem import send_teem |
| 852 |
|
| 853 |
|
| 854 |
def parseStats(entry): |
| 855 |
if 'description' in entry: |
| 856 |
return entry['description'] |
| 857 |
elif 'value' in entry: |
| 858 |
return entry['value'] |
| 859 |
elif 'entries' in entry or 'nestedStats' in entry and 'entries' in entry['nestedStats']: |
| 860 |
if 'entries' in entry: |
| 861 |
entries = entry['entries'] |
| 862 |
else: |
| 863 |
entries = entry['nestedStats']['entries'] |
| 864 |
result = None |
| 865 |
|
| 866 |
for name in entries: |
| 867 |
entry = entries[name] |
| 868 |
if 'https://localhost' in name: |
| 869 |
name = name.split('/') |
| 870 |
name = name[-1] |
| 871 |
if result and isinstance(result, list): |
| 872 |
result.append(parseStats(entry)) |
| 873 |
elif result and isinstance(result, dict): |
| 874 |
result[name] = parseStats(entry) |
| 875 |
else: |
| 876 |
try: |
| 877 |
int(name) |
| 878 |
result = list() |
| 879 |
result.append(parseStats(entry)) |
| 880 |
except ValueError: |
| 881 |
result = dict() |
| 882 |
result[name] = parseStats(entry) |
| 883 |
else: |
| 884 |
if '.' in name: |
| 885 |
names = name.split('.') |
| 886 |
key = names[0] |
| 887 |
value = names[1] |
| 888 |
if not result[key]: |
| 889 |
result[key] = {} |
| 890 |
result[key][value] = parseStats(entry) |
| 891 |
else: |
| 892 |
if result and isinstance(result, list): |
| 893 |
result.append(parseStats(entry)) |
| 894 |
elif result and isinstance(result, dict): |
| 895 |
result[name] = parseStats(entry) |
| 896 |
else: |
| 897 |
try: |
| 898 |
int(name) |
| 899 |
result = list() |
| 900 |
result.append(parseStats(entry)) |
| 901 |
except ValueError: |
| 902 |
result = dict() |
| 903 |
result[name] = parseStats(entry) |
| 904 |
return result |
| 905 |
|
| 906 |
|
| 907 |
class BaseManager(object): |
| 908 |
def __init__(self, *args, **kwargs): |
| 909 |
self.module = kwargs.get('module', None) |
| 910 |
self.client = kwargs.get('client', None) |
| 911 |
self.kwargs = kwargs |
| 912 |
|
| 913 |
def exec_module(self): |
| 914 |
start = datetime.datetime.now().isoformat() |
| 915 |
version = bigiq_version(self.client) |
| 916 |
results = [] |
| 917 |
facts = self.read_facts() |
| 918 |
for item in facts: |
| 919 |
attrs = item.to_return() |
| 920 |
results.append(attrs) |
| 921 |
send_teem(start, self.client, self.module, version) |
| 922 |
return results |
| 923 |
|
| 924 |
|
| 925 |
class Parameters(AnsibleF5Parameters): |
| 926 |
@property |
| 927 |
def gather_subset(self): |
| 928 |
if isinstance(self._values['gather_subset'], string_types): |
| 929 |
self._values['gather_subset'] = [self._values['gather_subset']] |
| 930 |
elif not isinstance(self._values['gather_subset'], list): |
| 931 |
raise F5ModuleError( |
| 932 |
"The specified gather_subset must be a list." |
| 933 |
) |
| 934 |
tmp = list(set(self._values['gather_subset'])) |
| 935 |
tmp.sort() |
| 936 |
self._values['gather_subset'] = tmp |
| 937 |
|
| 938 |
return self._values['gather_subset'] |
| 939 |
|
| 940 |
|
| 941 |
class BaseParameters(Parameters): |
| 942 |
@property |
| 943 |
def enabled(self): |
| 944 |
return flatten_boolean(self._values['enabled']) |
| 945 |
|
| 946 |
@property |
| 947 |
def disabled(self): |
| 948 |
return flatten_boolean(self._values['disabled']) |
| 949 |
|
| 950 |
def _remove_internal_keywords(self, resource): |
| 951 |
resource.pop('kind', None) |
| 952 |
resource.pop('generation', None) |
| 953 |
resource.pop('selfLink', None) |
| 954 |
resource.pop('isSubcollection', None) |
| 955 |
resource.pop('fullPath', None) |
| 956 |
|
| 957 |
def to_return(self): |
| 958 |
result = {} |
| 959 |
for returnable in self.returnables: |
| 960 |
result[returnable] = getattr(self, returnable) |
| 961 |
result = self._filter_params(result) |
| 962 |
return result |
| 963 |
|
| 964 |
|
| 965 |
class ApplicationsParameters(BaseParameters): |
| 966 |
api_map = { |
| 967 |
'protectionMode': 'protection_mode', |
| 968 |
'transactionsPerSecond': 'transactions_per_second', |
| 969 |
'newConnections': 'new_connections', |
| 970 |
'responseTime': 'response_time', |
| 971 |
'activeAlerts': 'active_alerts', |
| 972 |
'badTraffic': 'bad_traffic', |
| 973 |
'enhancedAnalytics': 'enhanced_analytics', |
| 974 |
'badTrafficGrowth': 'bad_traffic_growth' |
| 975 |
} |
| 976 |
|
| 977 |
returnables = [ |
| 978 |
'protection_mode', |
| 979 |
'id', |
| 980 |
'name', |
| 981 |
'status', |
| 982 |
'transactions_per_second', |
| 983 |
'connections', |
| 984 |
'new_connections', |
| 985 |
'response_time', |
| 986 |
'health', |
| 987 |
'active_alerts', |
| 988 |
'bad_traffic', |
| 989 |
'enhanced_analytics', |
| 990 |
'bad_traffic_growth', |
| 991 |
] |
| 992 |
|
| 993 |
@property |
| 994 |
def enhanced_analytics(self): |
| 995 |
return flatten_boolean(self._values['enhanced_analytics']) |
| 996 |
|
| 997 |
@property |
| 998 |
def bad_traffic_growth(self): |
| 999 |
return flatten_boolean(self._values['bad_traffic_growth']) |
| 1000 |
|
| 1001 |
|
| 1002 |
class ApplicationsFactManager(BaseManager): |
| 1003 |
def __init__(self, *args, **kwargs): |
| 1004 |
self.client = kwargs.get('client', None) |
| 1005 |
self.module = kwargs.get('module', None) |
| 1006 |
super(ApplicationsFactManager, self).__init__(**kwargs) |
| 1007 |
|
| 1008 |
def exec_module(self): |
| 1009 |
facts = self._exec_module() |
| 1010 |
result = dict(applications=facts) |
| 1011 |
return result |
| 1012 |
|
| 1013 |
def _exec_module(self): |
| 1014 |
results = [] |
| 1015 |
facts = self.read_facts() |
| 1016 |
for item in facts: |
| 1017 |
attrs = item.to_return() |
| 1018 |
results.append(attrs) |
| 1019 |
results = sorted(results, key=lambda k: k['name']) |
| 1020 |
return results |
| 1021 |
|
| 1022 |
def read_facts(self): |
| 1023 |
results = [] |
| 1024 |
collection = self.read_collection_from_device() |
| 1025 |
for resource in collection: |
| 1026 |
params = ApplicationsParameters(params=resource) |
| 1027 |
results.append(params) |
| 1028 |
return results |
| 1029 |
|
| 1030 |
def read_collection_from_device(self): |
| 1031 |
uri = "https://{0}:{1}/mgmt/ap/query/v1/tenants/default/reports/AllApplicationsList".format( |
| 1032 |
self.client.provider['server'], |
| 1033 |
self.client.provider['server_port'], |
| 1034 |
) |
| 1035 |
resp = self.client.api.get(uri) |
| 1036 |
try: |
| 1037 |
response = resp.json() |
| 1038 |
except ValueError as ex: |
| 1039 |
raise F5ModuleError(str(ex)) |
| 1040 |
|
| 1041 |
if 'code' in response and response['code'] == 400: |
| 1042 |
if 'message' in response: |
| 1043 |
raise F5ModuleError(response['message']) |
| 1044 |
else: |
| 1045 |
raise F5ModuleError(resp.content) |
| 1046 |
try: |
| 1047 |
return response['result']['items'] |
| 1048 |
except KeyError: |
| 1049 |
return [] |
| 1050 |
|
| 1051 |
|
| 1052 |
class ManagedDevicesParameters(BaseParameters): |
| 1053 |
api_map = { |
| 1054 |
'deviceUri': 'device_uri', |
| 1055 |
'groupName': 'group_name', |
| 1056 |
'httpsPort': 'https_port', |
| 1057 |
'isClustered': 'is_clustered', |
| 1058 |
'isLicenseExpired': 'is_license_expired', |
| 1059 |
'isVirtual': 'is_virtual', |
| 1060 |
'machineId': 'machine_id', |
| 1061 |
'managementAddress': 'management_address', |
| 1062 |
'mcpDeviceName': 'mcp_device_name', |
| 1063 |
'restFrameworkVersion': 'rest_framework_version', |
| 1064 |
'selfLink': 'self_link', |
| 1065 |
'trustDomainGuid': 'trust_domain_guid', |
| 1066 |
} |
| 1067 |
|
| 1068 |
returnables = [ |
| 1069 |
'address', |
| 1070 |
'build', |
| 1071 |
'device_uri', |
| 1072 |
'edition', |
| 1073 |
'group_name', |
| 1074 |
'hostname', |
| 1075 |
'https_port', |
| 1076 |
'is_clustered', |
| 1077 |
'is_license_expired', |
| 1078 |
'is_virtual', |
| 1079 |
'machine_id', |
| 1080 |
'management_address', |
| 1081 |
'mcp_device_name', |
| 1082 |
'product', |
| 1083 |
'rest_framework_version', |
| 1084 |
'self_link', |
| 1085 |
'slots', |
| 1086 |
'state', |
| 1087 |
'tags', |
| 1088 |
'trust_domain_guid', |
| 1089 |
'uuid', |
| 1090 |
'version', |
| 1091 |
] |
| 1092 |
|
| 1093 |
@property |
| 1094 |
def slots(self): |
| 1095 |
result = [] |
| 1096 |
if self._values['slots'] is None: |
| 1097 |
return None |
| 1098 |
for x in self._values['slots']: |
| 1099 |
x['is_active'] = flatten_boolean(x.pop('isActive', False)) |
| 1100 |
result.append(x) |
| 1101 |
return result |
| 1102 |
|
| 1103 |
@property |
| 1104 |
def tags(self): |
| 1105 |
if self._values['tags'] is None: |
| 1106 |
return None |
| 1107 |
result = dict((x['name'], x['value']) for x in self._values['tags']) |
| 1108 |
return result |
| 1109 |
|
| 1110 |
@property |
| 1111 |
def https_port(self): |
| 1112 |
return int(self._values['https_port']) |
| 1113 |
|
| 1114 |
@property |
| 1115 |
def is_clustered(self): |
| 1116 |
return flatten_boolean(self._values['is_clustered']) |
| 1117 |
|
| 1118 |
@property |
| 1119 |
def is_license_expired(self): |
| 1120 |
return flatten_boolean(self._values['is_license_expired']) |
| 1121 |
|
| 1122 |
@property |
| 1123 |
def is_virtual(self): |
| 1124 |
return flatten_boolean(self._values['is_virtual']) |
| 1125 |
|
| 1126 |
|
| 1127 |
class ManagedDevicesFactManager(BaseManager): |
| 1128 |
def __init__(self, *args, **kwargs): |
| 1129 |
self.client = kwargs.get('client', None) |
| 1130 |
self.module = kwargs.get('module', None) |
| 1131 |
super(ManagedDevicesFactManager, self).__init__(**kwargs) |
| 1132 |
|
| 1133 |
def exec_module(self): |
| 1134 |
facts = self._exec_module() |
| 1135 |
result = dict(managed_devices=facts) |
| 1136 |
return result |
| 1137 |
|
| 1138 |
def _exec_module(self): |
| 1139 |
results = [] |
| 1140 |
facts = self.read_facts() |
| 1141 |
for item in facts: |
| 1142 |
attrs = item.to_return() |
| 1143 |
results.append(attrs) |
| 1144 |
results = sorted(results, key=lambda k: k['hostname']) |
| 1145 |
return results |
| 1146 |
|
| 1147 |
def read_facts(self): |
| 1148 |
results = [] |
| 1149 |
collection = self.read_collection_from_device() |
| 1150 |
for resource in collection: |
| 1151 |
params = ManagedDevicesParameters(params=resource) |
| 1152 |
results.append(params) |
| 1153 |
return results |
| 1154 |
|
| 1155 |
def read_collection_from_device(self): |
| 1156 |
uri = "https://{0}:{1}/mgmt/shared/resolver/device-groups/cm-bigip-allBigIpDevices/devices".format( |
| 1157 |
self.client.provider['server'], |
| 1158 |
self.client.provider['server_port'], |
| 1159 |
) |
| 1160 |
resp = self.client.api.get(uri) |
| 1161 |
try: |
| 1162 |
response = resp.json() |
| 1163 |
except ValueError as ex: |
| 1164 |
raise F5ModuleError(str(ex)) |
| 1165 |
|
| 1166 |
if 'code' in response and response['code'] == 400: |
| 1167 |
if 'message' in response: |
| 1168 |
raise F5ModuleError(response['message']) |
| 1169 |
else: |
| 1170 |
raise F5ModuleError(resp.content) |
| 1171 |
if 'items' not in response: |
| 1172 |
return [] |
| 1173 |
result = response['items'] |
| 1174 |
return result |
| 1175 |
|
| 1176 |
|
| 1177 |
class PurchasedPoolLicensesParameters(BaseParameters): |
| 1178 |
api_map = { |
| 1179 |
'baseRegKey': 'base_reg_key', |
| 1180 |
'freeDeviceLicenses': 'free_device_licenses', |
| 1181 |
'licenseState': 'license_state', |
| 1182 |
'totalDeviceLicenses': 'total_device_licenses', |
| 1183 |
} |
| 1184 |
|
| 1185 |
returnables = [ |
| 1186 |
'base_reg_key', |
| 1187 |
'dossier', |
| 1188 |
'free_device_licenses', |
| 1189 |
'name', |
| 1190 |
'state', |
| 1191 |
'total_device_licenses', |
| 1192 |
'uuid', |
| 1193 |
|
| 1194 |
|
| 1195 |
'vendor', |
| 1196 |
'licensed_date_time', |
| 1197 |
'licensed_version', |
| 1198 |
'evaluation_start_date_time', |
| 1199 |
'evaluation_end_date_time', |
| 1200 |
'license_end_date_time', |
| 1201 |
'license_start_date_time', |
| 1202 |
'registration_key', |
| 1203 |
] |
| 1204 |
|
| 1205 |
@property |
| 1206 |
def registration_key(self): |
| 1207 |
try: |
| 1208 |
return self._values['license_state']['registrationKey'] |
| 1209 |
except KeyError: |
| 1210 |
return None |
| 1211 |
|
| 1212 |
@property |
| 1213 |
def license_start_date_time(self): |
| 1214 |
try: |
| 1215 |
return self._values['license_state']['licenseStartDateTime'] |
| 1216 |
except KeyError: |
| 1217 |
return None |
| 1218 |
|
| 1219 |
@property |
| 1220 |
def license_end_date_time(self): |
| 1221 |
try: |
| 1222 |
return self._values['license_state']['licenseEndDateTime'] |
| 1223 |
except KeyError: |
| 1224 |
return None |
| 1225 |
|
| 1226 |
@property |
| 1227 |
def evaluation_end_date_time(self): |
| 1228 |
try: |
| 1229 |
return self._values['license_state']['evaluationEndDateTime'] |
| 1230 |
except KeyError: |
| 1231 |
return None |
| 1232 |
|
| 1233 |
@property |
| 1234 |
def evaluation_start_date_time(self): |
| 1235 |
try: |
| 1236 |
return self._values['license_state']['evaluationStartDateTime'] |
| 1237 |
except KeyError: |
| 1238 |
return None |
| 1239 |
|
| 1240 |
@property |
| 1241 |
def licensed_version(self): |
| 1242 |
try: |
| 1243 |
return self._values['license_state']['licensedVersion'] |
| 1244 |
except KeyError: |
| 1245 |
return None |
| 1246 |
|
| 1247 |
@property |
| 1248 |
def licensed_date_time(self): |
| 1249 |
try: |
| 1250 |
return self._values['license_state']['licensedDateTime'] |
| 1251 |
except KeyError: |
| 1252 |
return None |
| 1253 |
|
| 1254 |
@property |
| 1255 |
def vendor(self): |
| 1256 |
try: |
| 1257 |
return self._values['license_state']['vendor'] |
| 1258 |
except KeyError: |
| 1259 |
return None |
| 1260 |
|
| 1261 |
|
| 1262 |
class PurchasedPoolLicensesFactManager(BaseManager): |
| 1263 |
def __init__(self, *args, **kwargs): |
| 1264 |
self.client = kwargs.get('client', None) |
| 1265 |
self.module = kwargs.get('module', None) |
| 1266 |
super(PurchasedPoolLicensesFactManager, self).__init__(**kwargs) |
| 1267 |
|
| 1268 |
def exec_module(self): |
| 1269 |
facts = self._exec_module() |
| 1270 |
result = dict(purchased_pool_licenses=facts) |
| 1271 |
return result |
| 1272 |
|
| 1273 |
def _exec_module(self): |
| 1274 |
results = [] |
| 1275 |
facts = self.read_facts() |
| 1276 |
for item in facts: |
| 1277 |
attrs = item.to_return() |
| 1278 |
results.append(attrs) |
| 1279 |
results = sorted(results, key=lambda k: k['name']) |
| 1280 |
return results |
| 1281 |
|
| 1282 |
def read_facts(self): |
| 1283 |
results = [] |
| 1284 |
collection = self.read_collection_from_device() |
| 1285 |
for resource in collection: |
| 1286 |
params = PurchasedPoolLicensesParameters(params=resource) |
| 1287 |
results.append(params) |
| 1288 |
return results |
| 1289 |
|
| 1290 |
def read_collection_from_device(self): |
| 1291 |
uri = "https://{0}:{1}/mgmt/cm/device/licensing/pool/purchased-pool/licenses".format( |
| 1292 |
self.client.provider['server'], |
| 1293 |
self.client.provider['server_port'], |
| 1294 |
) |
| 1295 |
resp = self.client.api.get(uri) |
| 1296 |
try: |
| 1297 |
response = resp.json() |
| 1298 |
except ValueError as ex: |
| 1299 |
raise F5ModuleError(str(ex)) |
| 1300 |
|
| 1301 |
if 'code' in response and response['code'] == 400: |
| 1302 |
if 'message' in response: |
| 1303 |
raise F5ModuleError(response['message']) |
| 1304 |
else: |
| 1305 |
raise F5ModuleError(resp.content) |
| 1306 |
try: |
| 1307 |
return response['items'] |
| 1308 |
except KeyError: |
| 1309 |
return [] |
| 1310 |
|
| 1311 |
|
| 1312 |
class RegkeyPoolsParameters(BaseParameters): |
| 1313 |
api_map = { |
| 1314 |
|
| 1315 |
} |
| 1316 |
|
| 1317 |
returnables = [ |
| 1318 |
'name', |
| 1319 |
'id', |
| 1320 |
'offerings', |
| 1321 |
'total_offerings', |
| 1322 |
] |
| 1323 |
|
| 1324 |
|
| 1325 |
class RegkeyPoolsOfferingParameters(BaseParameters): |
| 1326 |
api_map = { |
| 1327 |
'regKey': 'registration_key', |
| 1328 |
'licenseState': 'license_state', |
| 1329 |
'status': 'state', |
| 1330 |
} |
| 1331 |
|
| 1332 |
returnables = [ |
| 1333 |
'name', |
| 1334 |
'dossier', |
| 1335 |
'state', |
| 1336 |
|
| 1337 |
|
| 1338 |
'licensed_date_time', |
| 1339 |
'licensed_version', |
| 1340 |
'evaluation_start_date_time', |
| 1341 |
'evaluation_end_date_time', |
| 1342 |
'license_end_date_time', |
| 1343 |
'license_start_date_time', |
| 1344 |
'registration_key', |
| 1345 |
] |
| 1346 |
|
| 1347 |
@property |
| 1348 |
def registration_key(self): |
| 1349 |
try: |
| 1350 |
return self._values['license_state']['registrationKey'] |
| 1351 |
except KeyError: |
| 1352 |
return None |
| 1353 |
|
| 1354 |
@property |
| 1355 |
def license_start_date_time(self): |
| 1356 |
try: |
| 1357 |
return self._values['license_state']['licenseStartDateTime'] |
| 1358 |
except KeyError: |
| 1359 |
return None |
| 1360 |
|
| 1361 |
@property |
| 1362 |
def license_end_date_time(self): |
| 1363 |
try: |
| 1364 |
return self._values['license_state']['licenseEndDateTime'] |
| 1365 |
except KeyError: |
| 1366 |
return None |
| 1367 |
|
| 1368 |
@property |
| 1369 |
def evaluation_end_date_time(self): |
| 1370 |
try: |
| 1371 |
return self._values['license_state']['evaluationEndDateTime'] |
| 1372 |
except KeyError: |
| 1373 |
return None |
| 1374 |
|
| 1375 |
@property |
| 1376 |
def evaluation_start_date_time(self): |
| 1377 |
try: |
| 1378 |
return self._values['license_state']['evaluationStartDateTime'] |
| 1379 |
except KeyError: |
| 1380 |
return None |
| 1381 |
|
| 1382 |
@property |
| 1383 |
def licensed_version(self): |
| 1384 |
try: |
| 1385 |
return self._values['license_state']['licensedVersion'] |
| 1386 |
except KeyError: |
| 1387 |
return None |
| 1388 |
|
| 1389 |
@property |
| 1390 |
def licensed_date_time(self): |
| 1391 |
try: |
| 1392 |
return self._values['license_state']['licensedDateTime'] |
| 1393 |
except KeyError: |
| 1394 |
return None |
| 1395 |
|
| 1396 |
@property |
| 1397 |
def vendor(self): |
| 1398 |
try: |
| 1399 |
return self._values['license_state']['vendor'] |
| 1400 |
except KeyError: |
| 1401 |
return None |
| 1402 |
|
| 1403 |
|
| 1404 |
class RegkeyPoolsFactManager(BaseManager): |
| 1405 |
def __init__(self, *args, **kwargs): |
| 1406 |
self.client = kwargs.get('client', None) |
| 1407 |
self.module = kwargs.get('module', None) |
| 1408 |
super(RegkeyPoolsFactManager, self).__init__(**kwargs) |
| 1409 |
|
| 1410 |
def exec_module(self): |
| 1411 |
facts = self._exec_module() |
| 1412 |
result = dict(regkey_pools=facts) |
| 1413 |
return result |
| 1414 |
|
| 1415 |
def _exec_module(self): |
| 1416 |
results = [] |
| 1417 |
facts = self.read_facts() |
| 1418 |
for item in facts: |
| 1419 |
attrs = item.to_return() |
| 1420 |
results.append(attrs) |
| 1421 |
results = sorted(results, key=lambda k: k['name']) |
| 1422 |
return results |
| 1423 |
|
| 1424 |
def read_facts(self): |
| 1425 |
results = [] |
| 1426 |
collection = self.read_collection_from_device() |
| 1427 |
for resource in collection: |
| 1428 |
params = RegkeyPoolsParameters(params=resource) |
| 1429 |
offerings = self.read_offerings_from_device(resource['id']) |
| 1430 |
params.update({'total_offerings': len(offerings)}) |
| 1431 |
for offering in offerings: |
| 1432 |
params2 = RegkeyPoolsOfferingParameters(params=offering) |
| 1433 |
params.update({'offerings': params2.to_return()}) |
| 1434 |
results.append(params) |
| 1435 |
return results |
| 1436 |
|
| 1437 |
def read_collection_from_device(self): |
| 1438 |
uri = "https://{0}:{1}/mgmt/cm/device/licensing/pool/regkey/licenses".format( |
| 1439 |
self.client.provider['server'], |
| 1440 |
self.client.provider['server_port'], |
| 1441 |
) |
| 1442 |
resp = self.client.api.get(uri) |
| 1443 |
try: |
| 1444 |
response = resp.json() |
| 1445 |
except ValueError as ex: |
| 1446 |
raise F5ModuleError(str(ex)) |
| 1447 |
|
| 1448 |
if 'code' in response and response['code'] == 400: |
| 1449 |
if 'message' in response: |
| 1450 |
raise F5ModuleError(response['message']) |
| 1451 |
else: |
| 1452 |
raise F5ModuleError(resp.content) |
| 1453 |
try: |
| 1454 |
return response['items'] |
| 1455 |
except KeyError: |
| 1456 |
return [] |
| 1457 |
|
| 1458 |
def read_offerings_from_device(self, license): |
| 1459 |
uri = "https://{0}:{1}/mgmt/cm/device/licensing/pool/regkey/licenses/{2}/offerings".format( |
| 1460 |
self.client.provider['server'], |
| 1461 |
self.client.provider['server_port'], |
| 1462 |
license, |
| 1463 |
) |
| 1464 |
resp = self.client.api.get(uri) |
| 1465 |
try: |
| 1466 |
response = resp.json() |
| 1467 |
except ValueError as ex: |
| 1468 |
raise F5ModuleError(str(ex)) |
| 1469 |
|
| 1470 |
if 'code' in response and response['code'] == 400: |
| 1471 |
if 'message' in response: |
| 1472 |
raise F5ModuleError(response['message']) |
| 1473 |
else: |
| 1474 |
raise F5ModuleError(resp.content) |
| 1475 |
try: |
| 1476 |
return response['items'] |
| 1477 |
except KeyError: |
| 1478 |
return [] |
| 1479 |
|
| 1480 |
|
| 1481 |
class SystemInfoParameters(BaseParameters): |
| 1482 |
api_map = { |
| 1483 |
'isSystemSetup': 'is_system_setup', |
| 1484 |
'isAdminPasswordChanged': 'is_admin_password_changed', |
| 1485 |
'isRootPasswordChanged': 'is_root_password_changed' |
| 1486 |
} |
| 1487 |
|
| 1488 |
returnables = [ |
| 1489 |
'base_mac_address', |
| 1490 |
'chassis_serial', |
| 1491 |
'hardware_information', |
| 1492 |
'host_board_part_revision', |
| 1493 |
'host_board_serial', |
| 1494 |
'is_admin_password_changed', |
| 1495 |
'is_root_password_changed', |
| 1496 |
'is_system_setup', |
| 1497 |
'marketing_name', |
| 1498 |
'package_edition', |
| 1499 |
'package_version', |
| 1500 |
'platform', |
| 1501 |
'product_build', |
| 1502 |
'product_build_date', |
| 1503 |
'product_built', |
| 1504 |
'product_changelist', |
| 1505 |
'product_code', |
| 1506 |
'product_information', |
| 1507 |
'product_jobid', |
| 1508 |
'product_version', |
| 1509 |
'switch_board_part_revision', |
| 1510 |
'switch_board_serial', |
| 1511 |
'time', |
| 1512 |
'uptime', |
| 1513 |
] |
| 1514 |
|
| 1515 |
@property |
| 1516 |
def is_admin_password_changed(self): |
| 1517 |
return flatten_boolean(self._values['is_admin_password_changed']) |
| 1518 |
|
| 1519 |
@property |
| 1520 |
def is_root_password_changed(self): |
| 1521 |
return flatten_boolean(self._values['is_root_password_changed']) |
| 1522 |
|
| 1523 |
@property |
| 1524 |
def is_system_setup(self): |
| 1525 |
if self._values['is_system_setup'] is None: |
| 1526 |
return 'no' |
| 1527 |
return flatten_boolean(self._values['is_system_setup']) |
| 1528 |
|
| 1529 |
@property |
| 1530 |
def chassis_serial(self): |
| 1531 |
if self._values['system-info'] is None: |
| 1532 |
return None |
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
if 'bigipChassisSerialNum' not in self._values['system-info'][0]: |
| 1537 |
return None |
| 1538 |
return self._values['system-info'][0]['bigipChassisSerialNum'] |
| 1539 |
|
| 1540 |
@property |
| 1541 |
def switch_board_serial(self): |
| 1542 |
if self._values['system-info'] is None: |
| 1543 |
return None |
| 1544 |
if 'switchBoardSerialNum' not in self._values['system-info'][0]: |
| 1545 |
return None |
| 1546 |
if self._values['system-info'][0]['switchBoardSerialNum'].strip() == '': |
| 1547 |
return None |
| 1548 |
return self._values['system-info'][0]['switchBoardSerialNum'] |
| 1549 |
|
| 1550 |
@property |
| 1551 |
def switch_board_part_revision(self): |
| 1552 |
if self._values['system-info'] is None: |
| 1553 |
return None |
| 1554 |
if 'switchBoardPartRevNum' not in self._values['system-info'][0]: |
| 1555 |
return None |
| 1556 |
if self._values['system-info'][0]['switchBoardPartRevNum'].strip() == '': |
| 1557 |
return None |
| 1558 |
return self._values['system-info'][0]['switchBoardPartRevNum'] |
| 1559 |
|
| 1560 |
@property |
| 1561 |
def platform(self): |
| 1562 |
if self._values['system-info'] is None: |
| 1563 |
return None |
| 1564 |
return self._values['system-info'][0]['platform'] |
| 1565 |
|
| 1566 |
@property |
| 1567 |
def host_board_serial(self): |
| 1568 |
if self._values['system-info'] is None: |
| 1569 |
return None |
| 1570 |
if 'hostBoardSerialNum' not in self._values['system-info'][0]: |
| 1571 |
return None |
| 1572 |
if self._values['system-info'][0]['hostBoardSerialNum'].strip() == '': |
| 1573 |
return None |
| 1574 |
return self._values['system-info'][0]['hostBoardSerialNum'] |
| 1575 |
|
| 1576 |
@property |
| 1577 |
def host_board_part_revision(self): |
| 1578 |
if self._values['system-info'] is None: |
| 1579 |
return None |
| 1580 |
if 'hostBoardPartRevNum' not in self._values['system-info'][0]: |
| 1581 |
return None |
| 1582 |
if self._values['system-info'][0]['hostBoardPartRevNum'].strip() == '': |
| 1583 |
return None |
| 1584 |
return self._values['system-info'][0]['hostBoardPartRevNum'] |
| 1585 |
|
| 1586 |
@property |
| 1587 |
def package_edition(self): |
| 1588 |
return self._values['Edition'] |
| 1589 |
|
| 1590 |
@property |
| 1591 |
def package_version(self): |
| 1592 |
return 'Build {0} - {1}'.format(self._values['Build'], self._values['Date']) |
| 1593 |
|
| 1594 |
@property |
| 1595 |
def product_build(self): |
| 1596 |
return self._values['Build'] |
| 1597 |
|
| 1598 |
@property |
| 1599 |
def product_build_date(self): |
| 1600 |
return self._values['Date'] |
| 1601 |
|
| 1602 |
@property |
| 1603 |
def product_built(self): |
| 1604 |
if 'version_info' not in self._values: |
| 1605 |
return None |
| 1606 |
if 'Built' in self._values['version_info']: |
| 1607 |
return int(self._values['version_info']['Built']) |
| 1608 |
|
| 1609 |
@property |
| 1610 |
def product_changelist(self): |
| 1611 |
if 'version_info' not in self._values: |
| 1612 |
return None |
| 1613 |
if 'Changelist' in self._values['version_info']: |
| 1614 |
return int(self._values['version_info']['Changelist']) |
| 1615 |
|
| 1616 |
@property |
| 1617 |
def product_jobid(self): |
| 1618 |
if 'version_info' not in self._values: |
| 1619 |
return None |
| 1620 |
if 'JobID' in self._values['version_info']: |
| 1621 |
return int(self._values['version_info']['JobID']) |
| 1622 |
|
| 1623 |
@property |
| 1624 |
def product_code(self): |
| 1625 |
return self._values['Product'] |
| 1626 |
|
| 1627 |
@property |
| 1628 |
def product_version(self): |
| 1629 |
return self._values['Version'] |
| 1630 |
|
| 1631 |
@property |
| 1632 |
def hardware_information(self): |
| 1633 |
if self._values['hardware-version'] is None: |
| 1634 |
return None |
| 1635 |
self._transform_name_attribute(self._values['hardware-version']) |
| 1636 |
result = [v for k, v in iteritems(self._values['hardware-version'])] |
| 1637 |
return result |
| 1638 |
|
| 1639 |
def _transform_name_attribute(self, entry): |
| 1640 |
if isinstance(entry, dict): |
| 1641 |
tmp = copy.deepcopy(entry) |
| 1642 |
for k, v in iteritems(tmp): |
| 1643 |
if k == 'tmName': |
| 1644 |
entry['name'] = entry.pop('tmName') |
| 1645 |
self._transform_name_attribute(v) |
| 1646 |
elif isinstance(entry, list): |
| 1647 |
for k in entry: |
| 1648 |
self._transform_name_attribute(k) |
| 1649 |
else: |
| 1650 |
return |
| 1651 |
|
| 1652 |
@property |
| 1653 |
def time(self): |
| 1654 |
if self._values['fullDate'] is None: |
| 1655 |
return None |
| 1656 |
date = datetime.datetime.strptime(self._values['fullDate'], "%Y-%m-%dT%H:%M:%SZ") |
| 1657 |
result = dict( |
| 1658 |
day=date.day, |
| 1659 |
hour=date.hour, |
| 1660 |
minute=date.minute, |
| 1661 |
month=date.month, |
| 1662 |
second=date.second, |
| 1663 |
year=date.year |
| 1664 |
) |
| 1665 |
return result |
| 1666 |
|
| 1667 |
@property |
| 1668 |
def marketing_name(self): |
| 1669 |
if self._values['platform'] is None: |
| 1670 |
return None |
| 1671 |
return self._values['platform'][0]['marketingName'] |
| 1672 |
|
| 1673 |
@property |
| 1674 |
def base_mac_address(self): |
| 1675 |
if self._values['platform'] is None: |
| 1676 |
return None |
| 1677 |
return self._values['platform'][0]['baseMac'] |
| 1678 |
|
| 1679 |
|
| 1680 |
class SystemInfoFactManager(BaseManager): |
| 1681 |
def __init__(self, *args, **kwargs): |
| 1682 |
self.client = kwargs.get('client', None) |
| 1683 |
self.module = kwargs.get('module', None) |
| 1684 |
super(SystemInfoFactManager, self).__init__(**kwargs) |
| 1685 |
|
| 1686 |
def exec_module(self): |
| 1687 |
facts = self._exec_module() |
| 1688 |
result = dict(system_info=facts) |
| 1689 |
return result |
| 1690 |
|
| 1691 |
def _exec_module(self): |
| 1692 |
facts = self.read_facts() |
| 1693 |
results = facts.to_return() |
| 1694 |
return results |
| 1695 |
|
| 1696 |
def read_facts(self): |
| 1697 |
collection = self.read_collection_from_device() |
| 1698 |
params = SystemInfoParameters(params=collection) |
| 1699 |
return params |
| 1700 |
|
| 1701 |
def read_collection_from_device(self): |
| 1702 |
result = dict() |
| 1703 |
tmp = self.read_hardware_info_from_device() |
| 1704 |
if tmp: |
| 1705 |
result.update(tmp) |
| 1706 |
|
| 1707 |
tmp = self.read_system_setup_from_device() |
| 1708 |
if tmp: |
| 1709 |
result.update(tmp) |
| 1710 |
|
| 1711 |
tmp = self.read_clock_info_from_device() |
| 1712 |
if tmp: |
| 1713 |
result.update(tmp) |
| 1714 |
|
| 1715 |
tmp = self.read_version_info_from_device() |
| 1716 |
if tmp: |
| 1717 |
result.update(tmp) |
| 1718 |
|
| 1719 |
if Version(bigiq_version(self.client)) < Version('7.0.0'): |
| 1720 |
tmp = self.read_uptime_info_from_device() |
| 1721 |
if tmp: |
| 1722 |
result.update(tmp) |
| 1723 |
|
| 1724 |
tmp = self.read_version_file_info_from_device() |
| 1725 |
if tmp: |
| 1726 |
result.update(tmp) |
| 1727 |
|
| 1728 |
return result |
| 1729 |
|
| 1730 |
def read_system_setup_from_device(self): |
| 1731 |
uri = "https://{0}:{1}/mgmt/shared/system/setup".format( |
| 1732 |
self.client.provider['server'], |
| 1733 |
self.client.provider['server_port'], |
| 1734 |
) |
| 1735 |
resp = self.client.api.get(uri) |
| 1736 |
try: |
| 1737 |
response = resp.json() |
| 1738 |
except ValueError as ex: |
| 1739 |
raise F5ModuleError(str(ex)) |
| 1740 |
if 'code' in response and response['code'] == 400: |
| 1741 |
if 'message' in response: |
| 1742 |
raise F5ModuleError(response['message']) |
| 1743 |
else: |
| 1744 |
raise F5ModuleError(resp.content) |
| 1745 |
|
| 1746 |
return response |
| 1747 |
|
| 1748 |
def read_version_file_info_from_device(self): |
| 1749 |
uri = "https://{0}:{1}/mgmt/tm/util/bash".format( |
| 1750 |
self.client.provider['server'], |
| 1751 |
self.client.provider['server_port'], |
| 1752 |
) |
| 1753 |
args = dict( |
| 1754 |
command='run', |
| 1755 |
utilCmdArgs='-c "cat /VERSION"' |
| 1756 |
) |
| 1757 |
resp = self.client.api.post(uri, json=args) |
| 1758 |
try: |
| 1759 |
response = resp.json() |
| 1760 |
except ValueError as ex: |
| 1761 |
raise F5ModuleError(str(ex)) |
| 1762 |
if 'code' in response and response['code'] == 400: |
| 1763 |
if 'message' in response: |
| 1764 |
raise F5ModuleError(response['message']) |
| 1765 |
else: |
| 1766 |
raise F5ModuleError(resp.content) |
| 1767 |
try: |
| 1768 |
pattern = r'^(?P<key>(Product|Build|Sequence|BaseBuild|Edition|Date|Built|Changelist|JobID))\:(?P<value>.*)' |
| 1769 |
result = response['commandResult'].strip() |
| 1770 |
except KeyError: |
| 1771 |
return None |
| 1772 |
|
| 1773 |
if 'No such file or directory' in result: |
| 1774 |
return None |
| 1775 |
|
| 1776 |
lines = response['commandResult'].split("\n") |
| 1777 |
result = dict() |
| 1778 |
for line in lines: |
| 1779 |
if not line: |
| 1780 |
continue |
| 1781 |
matches = re.match(pattern, line) |
| 1782 |
if matches: |
| 1783 |
result[matches.group('key')] = matches.group('value').strip() |
| 1784 |
|
| 1785 |
if result: |
| 1786 |
return dict( |
| 1787 |
version_info=result |
| 1788 |
) |
| 1789 |
|
| 1790 |
def read_uptime_info_from_device(self): |
| 1791 |
uri = "https://{0}:{1}/mgmt/tm/util/bash".format( |
| 1792 |
self.client.provider['server'], |
| 1793 |
self.client.provider['server_port'], |
| 1794 |
) |
| 1795 |
args = dict( |
| 1796 |
command='run', |
| 1797 |
utilCmdArgs='-c "cat /proc/uptime"' |
| 1798 |
) |
| 1799 |
resp = self.client.api.post(uri, json=args) |
| 1800 |
try: |
| 1801 |
response = resp.json() |
| 1802 |
except ValueError as ex: |
| 1803 |
raise F5ModuleError(str(ex)) |
| 1804 |
if 'code' in response and response['code'] == 400: |
| 1805 |
if 'message' in response: |
| 1806 |
raise F5ModuleError(response['message']) |
| 1807 |
else: |
| 1808 |
raise F5ModuleError(resp.content) |
| 1809 |
try: |
| 1810 |
parts = response['commandResult'].strip().split(' ') |
| 1811 |
return dict( |
| 1812 |
uptime=math.floor(float(parts[0])) |
| 1813 |
) |
| 1814 |
except KeyError: |
| 1815 |
pass |
| 1816 |
|
| 1817 |
def read_hardware_info_from_device(self): |
| 1818 |
uri = "https://{0}:{1}/mgmt/tm/sys/hardware".format( |
| 1819 |
self.client.provider['server'], |
| 1820 |
self.client.provider['server_port'], |
| 1821 |
) |
| 1822 |
resp = self.client.api.get(uri) |
| 1823 |
try: |
| 1824 |
response = resp.json() |
| 1825 |
except ValueError as ex: |
| 1826 |
raise F5ModuleError(str(ex)) |
| 1827 |
if 'code' in response and response['code'] == 400: |
| 1828 |
if 'message' in response: |
| 1829 |
raise F5ModuleError(response['message']) |
| 1830 |
else: |
| 1831 |
raise F5ModuleError(resp.content) |
| 1832 |
result = parseStats(response) |
| 1833 |
return result |
| 1834 |
|
| 1835 |
def read_clock_info_from_device(self): |
| 1836 |
"""Parses clock info from the REST API |
| 1837 |
|
| 1838 |
The clock stat returned from the REST API (at the time of 13.1.0.7) |
| 1839 |
is similar to the following. |
| 1840 |
|
| 1841 |
{ |
| 1842 |
"kind": "tm:sys:clock:clockstats", |
| 1843 |
"selfLink": "https://localhost/mgmt/tm/sys/clock?ver=13.1.0.4", |
| 1844 |
"entries": { |
| 1845 |
"https://localhost/mgmt/tm/sys/clock/0": { |
| 1846 |
"nestedStats": { |
| 1847 |
"entries": { |
| 1848 |
"fullDate": { |
| 1849 |
"description": "2018-06-05T13:38:33Z" |
| 1850 |
} |
| 1851 |
} |
| 1852 |
} |
| 1853 |
} |
| 1854 |
} |
| 1855 |
} |
| 1856 |
|
| 1857 |
Parsing this data using the ``parseStats`` method, yields a list of |
| 1858 |
the clock stats in a format resembling that below. |
| 1859 |
|
| 1860 |
[{'fullDate': '2018-06-05T13:41:05Z'}] |
| 1861 |
|
| 1862 |
Therefore, this method cherry-picks the first entry from this list |
| 1863 |
and returns it. There can be no other items in this list. |
| 1864 |
|
| 1865 |
Returns: |
| 1866 |
A dict mapping keys to the corresponding clock stats. For |
| 1867 |
example: |
| 1868 |
|
| 1869 |
{'fullDate': '2018-06-05T13:41:05Z'} |
| 1870 |
|
| 1871 |
There should never not be a clock stat, unless by chance it |
| 1872 |
is removed from the API in the future, or changed to a different |
| 1873 |
API endpoint. |
| 1874 |
|
| 1875 |
Raises: |
| 1876 |
F5ModuleError: A non-successful HTTP code was returned or a JSON |
| 1877 |
response was not found. |
| 1878 |
""" |
| 1879 |
uri = "https://{0}:{1}/mgmt/tm/sys/clock".format( |
| 1880 |
self.client.provider['server'], |
| 1881 |
self.client.provider['server_port'], |
| 1882 |
) |
| 1883 |
resp = self.client.api.get(uri) |
| 1884 |
try: |
| 1885 |
response = resp.json() |
| 1886 |
except ValueError as ex: |
| 1887 |
raise F5ModuleError(str(ex)) |
| 1888 |
if 'code' in response and response['code'] == 400: |
| 1889 |
if 'message' in response: |
| 1890 |
raise F5ModuleError(response['message']) |
| 1891 |
else: |
| 1892 |
raise F5ModuleError(resp.content) |
| 1893 |
result = parseStats(response) |
| 1894 |
if result is None: |
| 1895 |
return None |
| 1896 |
return result[0] |
| 1897 |
|
| 1898 |
def read_version_info_from_device(self): |
| 1899 |
"""Parses version info from the REST API |
| 1900 |
|
| 1901 |
The version stat returned from the REST API (at the time of 13.1.0.7) |
| 1902 |
is similar to the following. |
| 1903 |
|
| 1904 |
{ |
| 1905 |
"kind": "tm:sys:version:versionstats", |
| 1906 |
"selfLink": "https://localhost/mgmt/tm/sys/version?ver=13.1.0.4", |
| 1907 |
"entries": { |
| 1908 |
"https://localhost/mgmt/tm/sys/version/0": { |
| 1909 |
"nestedStats": { |
| 1910 |
"entries": { |
| 1911 |
"Build": { |
| 1912 |
"description": "0.0.6" |
| 1913 |
}, |
| 1914 |
"Date": { |
| 1915 |
"description": "Tue Mar 13 20:10:42 PDT 2018" |
| 1916 |
}, |
| 1917 |
"Edition": { |
| 1918 |
"description": "Point Release 4" |
| 1919 |
}, |
| 1920 |
"Product": { |
| 1921 |
"description": "BIG-IP" |
| 1922 |
}, |
| 1923 |
"Title": { |
| 1924 |
"description": "Main Package" |
| 1925 |
}, |
| 1926 |
"Version": { |
| 1927 |
"description": "13.1.0.4" |
| 1928 |
} |
| 1929 |
} |
| 1930 |
} |
| 1931 |
} |
| 1932 |
} |
| 1933 |
} |
| 1934 |
|
| 1935 |
Parsing this data using the ``parseStats`` method, yields a list of |
| 1936 |
the clock stats in a format resembling that below. |
| 1937 |
|
| 1938 |
[{'Build': '0.0.6', 'Date': 'Tue Mar 13 20:10:42 PDT 2018', |
| 1939 |
'Edition': 'Point Release 4', 'Product': 'BIG-IP', 'Title': 'Main Package', |
| 1940 |
'Version': '13.1.0.4'}] |
| 1941 |
|
| 1942 |
Therefore, this method cherry-picks the first entry from this list |
| 1943 |
and returns it. There can be no other items in this list. |
| 1944 |
|
| 1945 |
Returns: |
| 1946 |
A dict mapping keys to the corresponding clock stats. For |
| 1947 |
example: |
| 1948 |
|
| 1949 |
{'Build': '0.0.6', 'Date': 'Tue Mar 13 20:10:42 PDT 2018', |
| 1950 |
'Edition': 'Point Release 4', 'Product': 'BIG-IP', 'Title': 'Main Package', |
| 1951 |
'Version': '13.1.0.4'} |
| 1952 |
|
| 1953 |
There should never not be a version stat, unless by chance it |
| 1954 |
is removed from the API in the future, or changed to a different |
| 1955 |
API endpoint. |
| 1956 |
|
| 1957 |
Raises: |
| 1958 |
F5ModuleError: A non-successful HTTP code was returned or a JSON |
| 1959 |
response was not found. |
| 1960 |
""" |
| 1961 |
uri = "https://{0}:{1}/mgmt/tm/sys/version".format( |
| 1962 |
self.client.provider['server'], |
| 1963 |
self.client.provider['server_port'], |
| 1964 |
) |
| 1965 |
resp = self.client.api.get(uri) |
| 1966 |
try: |
| 1967 |
response = resp.json() |
| 1968 |
except ValueError as ex: |
| 1969 |
raise F5ModuleError(str(ex)) |
| 1970 |
if 'code' in response and response['code'] == 400: |
| 1971 |
if 'message' in response: |
| 1972 |
raise F5ModuleError(response['message']) |
| 1973 |
else: |
| 1974 |
raise F5ModuleError(resp.content) |
| 1975 |
result = parseStats(response) |
| 1976 |
if result is None: |
| 1977 |
return None |
| 1978 |
return result[0] |
| 1979 |
|
| 1980 |
|
| 1981 |
class VlansParameters(BaseParameters): |
| 1982 |
api_map = { |
| 1983 |
'autoLasthop': 'auto_lasthop', |
| 1984 |
'cmpHash': 'cmp_hash_algorithm', |
| 1985 |
'failsafeAction': 'failsafe_action', |
| 1986 |
'failsafe': 'failsafe_enabled', |
| 1987 |
'failsafeTimeout': 'failsafe_timeout', |
| 1988 |
'ifIndex': 'if_index', |
| 1989 |
'learning': 'learning_mode', |
| 1990 |
'interfacesReference': 'interfaces', |
| 1991 |
'sourceChecking': 'source_check_enabled', |
| 1992 |
'fullPath': 'full_path' |
| 1993 |
} |
| 1994 |
|
| 1995 |
returnables = [ |
| 1996 |
'full_path', |
| 1997 |
'name', |
| 1998 |
'auto_lasthop', |
| 1999 |
'cmp_hash_algorithm', |
| 2000 |
'description', |
| 2001 |
'failsafe_action', |
| 2002 |
'failsafe_enabled', |
| 2003 |
'failsafe_timeout', |
| 2004 |
'if_index', |
| 2005 |
'learning_mode', |
| 2006 |
'interfaces', |
| 2007 |
'mtu', |
| 2008 |
'sflow_poll_interval', |
| 2009 |
'sflow_poll_interval_global', |
| 2010 |
'sflow_sampling_rate', |
| 2011 |
'sflow_sampling_rate_global', |
| 2012 |
'source_check_enabled', |
| 2013 |
'true_mac_address', |
| 2014 |
'tag', |
| 2015 |
] |
| 2016 |
|
| 2017 |
@property |
| 2018 |
def interfaces(self): |
| 2019 |
if self._values['interfaces'] is None: |
| 2020 |
return None |
| 2021 |
if 'items' not in self._values['interfaces']: |
| 2022 |
return None |
| 2023 |
result = [] |
| 2024 |
for item in self._values['interfaces']['items']: |
| 2025 |
tmp = dict( |
| 2026 |
name=item['name'], |
| 2027 |
full_path=item['fullPath'] |
| 2028 |
) |
| 2029 |
if 'tagged' in item: |
| 2030 |
tmp['tagged'] = 'yes' |
| 2031 |
else: |
| 2032 |
tmp['tagged'] = 'no' |
| 2033 |
result.append(tmp) |
| 2034 |
return result |
| 2035 |
|
| 2036 |
@property |
| 2037 |
def sflow_poll_interval(self): |
| 2038 |
return int(self._values['sflow']['pollInterval']) |
| 2039 |
|
| 2040 |
@property |
| 2041 |
def sflow_poll_interval_global(self): |
| 2042 |
return flatten_boolean(self._values['sflow']['pollIntervalGlobal']) |
| 2043 |
|
| 2044 |
@property |
| 2045 |
def sflow_sampling_rate(self): |
| 2046 |
return int(self._values['sflow']['samplingRate']) |
| 2047 |
|
| 2048 |
@property |
| 2049 |
def sflow_sampling_rate_global(self): |
| 2050 |
return flatten_boolean(self._values['sflow']['samplingRateGlobal']) |
| 2051 |
|
| 2052 |
@property |
| 2053 |
def source_check_state(self): |
| 2054 |
return flatten_boolean(self._values['source_check_state']) |
| 2055 |
|
| 2056 |
@property |
| 2057 |
def true_mac_address(self): |
| 2058 |
if self._values['stats']['macTrue'] in [None, 'none']: |
| 2059 |
return None |
| 2060 |
return self._values['stats']['macTrue'] |
| 2061 |
|
| 2062 |
@property |
| 2063 |
def tag(self): |
| 2064 |
return self._values['stats']['id'] |
| 2065 |
|
| 2066 |
@property |
| 2067 |
def failsafe_enabled(self): |
| 2068 |
return flatten_boolean(self._values['failsafe_enabled']) |
| 2069 |
|
| 2070 |
|
| 2071 |
class VlansFactManager(BaseManager): |
| 2072 |
def __init__(self, *args, **kwargs): |
| 2073 |
self.client = kwargs.get('client', None) |
| 2074 |
self.module = kwargs.get('module', None) |
| 2075 |
super(VlansFactManager, self).__init__(**kwargs) |
| 2076 |
|
| 2077 |
def exec_module(self): |
| 2078 |
facts = self._exec_module() |
| 2079 |
result = dict(vlans=facts) |
| 2080 |
return result |
| 2081 |
|
| 2082 |
def _exec_module(self): |
| 2083 |
results = [] |
| 2084 |
facts = self.read_facts() |
| 2085 |
for item in facts: |
| 2086 |
attrs = item.to_return() |
| 2087 |
results.append(attrs) |
| 2088 |
results = sorted(results, key=lambda k: k['full_path']) |
| 2089 |
return results |
| 2090 |
|
| 2091 |
def read_facts(self): |
| 2092 |
results = [] |
| 2093 |
collection = self.read_collection_from_device() |
| 2094 |
for resource in collection: |
| 2095 |
resource.update(self.read_stats(resource['fullPath'])) |
| 2096 |
params = VlansParameters(params=resource) |
| 2097 |
results.append(params) |
| 2098 |
return results |
| 2099 |
|
| 2100 |
def read_stats(self, resource): |
| 2101 |
uri = "https://{0}:{1}/mgmt/tm/net/vlan/{2}/stats".format( |
| 2102 |
self.client.provider['server'], |
| 2103 |
self.client.provider['server_port'], |
| 2104 |
transform_name(name=resource) |
| 2105 |
|
| 2106 |
) |
| 2107 |
resp = self.client.api.get(uri) |
| 2108 |
try: |
| 2109 |
response = resp.json() |
| 2110 |
except ValueError as ex: |
| 2111 |
raise F5ModuleError(str(ex)) |
| 2112 |
if 'code' in response and response['code'] == 400: |
| 2113 |
if 'message' in response: |
| 2114 |
raise F5ModuleError(response['message']) |
| 2115 |
else: |
| 2116 |
raise F5ModuleError(resp.content) |
| 2117 |
result = parseStats(response) |
| 2118 |
return result |
| 2119 |
|
| 2120 |
def read_collection_from_device(self): |
| 2121 |
uri = "https://{0}:{1}/mgmt/tm/net/vlan/?expandSubcollections=true".format( |
| 2122 |
self.client.provider['server'], |
| 2123 |
self.client.provider['server_port'], |
| 2124 |
) |
| 2125 |
resp = self.client.api.get(uri) |
| 2126 |
try: |
| 2127 |
response = resp.json() |
| 2128 |
except ValueError as ex: |
| 2129 |
raise F5ModuleError(str(ex)) |
| 2130 |
|
| 2131 |
if 'code' in response and response['code'] == 400: |
| 2132 |
if 'message' in response: |
| 2133 |
raise F5ModuleError(response['message']) |
| 2134 |
else: |
| 2135 |
raise F5ModuleError(resp.content) |
| 2136 |
if 'items' not in response: |
| 2137 |
return [] |
| 2138 |
result = response['items'] |
| 2139 |
return result |
| 2140 |
|
| 2141 |
|
| 2142 |
class ModuleManager(object): |
| 2143 |
def __init__(self, *args, **kwargs): |
| 2144 |
self.module = kwargs.get('module', None) |
| 2145 |
self.client = kwargs.get('client', None) |
| 2146 |
self.kwargs = kwargs |
| 2147 |
self.want = Parameters(params=self.module.params) |
| 2148 |
self.managers = { |
| 2149 |
'applications': dict( |
| 2150 |
manager=ApplicationsFactManager, |
| 2151 |
client=F5RestClient, |
| 2152 |
), |
| 2153 |
'managed-devices': dict( |
| 2154 |
manager=ManagedDevicesFactManager, |
| 2155 |
client=F5RestClient, |
| 2156 |
), |
| 2157 |
'purchased-pool-licenses': dict( |
| 2158 |
manager=PurchasedPoolLicensesFactManager, |
| 2159 |
client=F5RestClient, |
| 2160 |
), |
| 2161 |
'regkey-pools': dict( |
| 2162 |
manager=RegkeyPoolsFactManager, |
| 2163 |
client=F5RestClient, |
| 2164 |
), |
| 2165 |
'system-info': dict( |
| 2166 |
manager=SystemInfoFactManager, |
| 2167 |
client=F5RestClient, |
| 2168 |
), |
| 2169 |
'vlans': dict( |
| 2170 |
manager=VlansFactManager, |
| 2171 |
client=F5RestClient, |
| 2172 |
), |
| 2173 |
} |
| 2174 |
|
| 2175 |
def exec_module(self): |
| 2176 |
self.handle_all_keyword() |
| 2177 |
res = self.check_valid_gather_subset(self.want.gather_subset) |
| 2178 |
if res: |
| 2179 |
invalid = ','.join(res) |
| 2180 |
raise F5ModuleError( |
| 2181 |
"The specified 'gather_subset' options are invalid: {0}".format(invalid) |
| 2182 |
) |
| 2183 |
result = self.filter_excluded_facts() |
| 2184 |
|
| 2185 |
managers = [] |
| 2186 |
for name in result: |
| 2187 |
manager = self.get_manager(name) |
| 2188 |
if manager: |
| 2189 |
managers.append(manager) |
| 2190 |
|
| 2191 |
if not managers: |
| 2192 |
result = dict( |
| 2193 |
changed=False |
| 2194 |
) |
| 2195 |
return result |
| 2196 |
|
| 2197 |
result = self.execute_managers(managers) |
| 2198 |
if result: |
| 2199 |
result['changed'] = True |
| 2200 |
else: |
| 2201 |
result['changed'] = False |
| 2202 |
return result |
| 2203 |
|
| 2204 |
def filter_excluded_facts(self): |
| 2205 |
|
| 2206 |
exclude = [x[1:] for x in self.want.gather_subset if x[0] == '!'] |
| 2207 |
include = [x for x in self.want.gather_subset if x[0] != '!'] |
| 2208 |
result = [x for x in include if x not in exclude] |
| 2209 |
return result |
| 2210 |
|
| 2211 |
def handle_all_keyword(self): |
| 2212 |
if 'all' not in self.want.gather_subset: |
| 2213 |
return |
| 2214 |
managers = list(self.managers.keys()) + self.want.gather_subset |
| 2215 |
managers.remove('all') |
| 2216 |
self.want.update({'gather_subset': managers}) |
| 2217 |
|
| 2218 |
def check_valid_gather_subset(self, includes): |
| 2219 |
"""Check that the specified subset is valid |
| 2220 |
|
| 2221 |
The ``gather_subset`` parameter is specified as a "raw" field which means that |
| 2222 |
any Python type could technically be provided |
| 2223 |
|
| 2224 |
:param includes: |
| 2225 |
:return: |
| 2226 |
""" |
| 2227 |
keys = self.managers.keys() |
| 2228 |
result = [] |
| 2229 |
for x in includes: |
| 2230 |
if x not in keys: |
| 2231 |
if x[0] == '!': |
| 2232 |
if x[1:] not in keys: |
| 2233 |
result.append(x) |
| 2234 |
else: |
| 2235 |
result.append(x) |
| 2236 |
return result |
| 2237 |
|
| 2238 |
def execute_managers(self, managers): |
| 2239 |
results = dict() |
| 2240 |
for manager in managers: |
| 2241 |
result = manager.exec_module() |
| 2242 |
results.update(result) |
| 2243 |
return results |
| 2244 |
|
| 2245 |
def get_manager(self, which): |
| 2246 |
result = {} |
| 2247 |
info = self.managers.get(which, None) |
| 2248 |
if not info: |
| 2249 |
return result |
| 2250 |
kwargs = dict() |
| 2251 |
kwargs.update(self.kwargs) |
| 2252 |
|
| 2253 |
manager = info.get('manager', None) |
| 2254 |
client = info.get('client', None) |
| 2255 |
kwargs['client'] = client(**self.module.params) |
| 2256 |
result = manager(**kwargs) |
| 2257 |
return result |
| 2258 |
|
| 2259 |
|
| 2260 |
class ArgumentSpec(object): |
| 2261 |
def __init__(self): |
| 2262 |
self.supports_check_mode = True |
| 2263 |
argument_spec = dict( |
| 2264 |
gather_subset=dict( |
| 2265 |
type='list', |
| 2266 |
elements='str', |
| 2267 |
required=True, |
| 2268 |
choices=[ |
| 2269 |
|
| 2270 |
'all', |
| 2271 |
|
| 2272 |
|
| 2273 |
'applications', |
| 2274 |
'managed-devices', |
| 2275 |
'purchased-pool-licenses', |
| 2276 |
'regkey-pools', |
| 2277 |
'system-info', |
| 2278 |
'vlans', |
| 2279 |
|
| 2280 |
|
| 2281 |
'!all', |
| 2282 |
|
| 2283 |
|
| 2284 |
'!applications', |
| 2285 |
'!managed-devices', |
| 2286 |
'!purchased-pool-licenses', |
| 2287 |
'!regkey-pools', |
| 2288 |
'!system-info', |
| 2289 |
'!vlans', |
| 2290 |
] |
| 2291 |
), |
| 2292 |
) |
| 2293 |
self.argument_spec = {} |
| 2294 |
self.argument_spec.update(f5_argument_spec) |
| 2295 |
self.argument_spec.update(argument_spec) |
| 2296 |
|
| 2297 |
|
| 2298 |
def main(): |
| 2299 |
spec = ArgumentSpec() |
| 2300 |
|
| 2301 |
module = AnsibleModule( |
| 2302 |
argument_spec=spec.argument_spec, |
| 2303 |
supports_check_mode=spec.supports_check_mode |
| 2304 |
) |
| 2305 |
|
| 2306 |
if not HAS_PACKAGING: |
| 2307 |
module.fail_json( |
| 2308 |
msg=missing_required_lib('packaging'), |
| 2309 |
exception=PACKAGING_IMPORT_ERROR |
| 2310 |
) |
| 2311 |
|
| 2312 |
try: |
| 2313 |
mm = ModuleManager(module=module) |
| 2314 |
results = mm.exec_module() |
| 2315 |
|
| 2316 |
ansible_facts = dict() |
| 2317 |
|
| 2318 |
for key, value in iteritems(results): |
| 2319 |
key = 'ansible_net_%s' % key |
| 2320 |
ansible_facts[key] = value |
| 2321 |
|
| 2322 |
module.exit_json(ansible_facts=ansible_facts, **results) |
| 2323 |
except F5ModuleError as ex: |
| 2324 |
module.fail_json(msg=str(ex)) |
| 2325 |
|
| 2326 |
|
| 2327 |
if __name__ == '__main__': |
| 2328 |
main() |