| 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: bigip_interface |
| 13 |
short_description: Module to manage BIG-IP physical interfaces. |
| 14 |
description: |
| 15 |
- Module to manage BIG-IP physical interfaces. |
| 16 |
version_added: "1.0.0" |
| 17 |
options: |
| 18 |
name: |
| 19 |
description: |
| 20 |
- Specifies the name of the interface to manage. |
| 21 |
type: str |
| 22 |
required: True |
| 23 |
description: |
| 24 |
description: |
| 25 |
- User defined description. |
| 26 |
type: str |
| 27 |
enabled: |
| 28 |
description: |
| 29 |
- Specifies the current status of the interface. |
| 30 |
- When C(true), enables the interface to pass traffic. |
| 31 |
- When C(false), disables the interface from passing traffic. |
| 32 |
type: bool |
| 33 |
bundle: |
| 34 |
description: |
| 35 |
- Enables or disables bundle capability. |
| 36 |
- This option is only supported on select hardware platforms and interfaces. |
| 37 |
- "Attempting to enable this option on a C(VE) or any other unsupported platform/interface |
| 38 |
will result in module run failure." |
| 39 |
type: str |
| 40 |
choices: |
| 41 |
- enabled |
| 42 |
- disabled |
| 43 |
- not-supported |
| 44 |
bundle_speed: |
| 45 |
description: |
| 46 |
- Sets the bundle speed, which is applicable only when the bundle is C(true). |
| 47 |
- This option is only supported on selected hardware platforms and interfaces. |
| 48 |
- "Attempting to enable this option on a C(VE) or any other unsupported platform/interface |
| 49 |
will result in module run failure." |
| 50 |
type: str |
| 51 |
choices: |
| 52 |
- 100G |
| 53 |
- 40G |
| 54 |
- not-supported |
| 55 |
force_gigabit_fiber: |
| 56 |
description: |
| 57 |
- Enables or disables forcing of gigabit fiber media. |
| 58 |
- When C(true) for a gigabit fiber interface, the media setting will be forced, and no auto-negotiation will be |
| 59 |
performed. |
| 60 |
- When C(false) auto-negotiation will be performed with just a single gigabit fiber option advertised. |
| 61 |
type: bool |
| 62 |
prefer_port: |
| 63 |
description: |
| 64 |
- Indicates which side of a combo port the interface uses, if both sides have the potential for an external link. |
| 65 |
- The default value for a combo port is sfp. Do not use this option for non-combo ports. |
| 66 |
type: str |
| 67 |
choices: |
| 68 |
- sfp |
| 69 |
- fixed |
| 70 |
media_fixed: |
| 71 |
description: |
| 72 |
- "Specifies the settings for a fixed (non-pluggable) interface." |
| 73 |
- Use this option only with a combo port to specify the media type for the fixed interface, |
| 74 |
when it is not the preferred port. |
| 75 |
type: str |
| 76 |
choices: |
| 77 |
- 100000-FD |
| 78 |
- 100000LR4-FD |
| 79 |
- 10000LR-FD |
| 80 |
- 10000T-FD |
| 81 |
- 1000SX-FD |
| 82 |
- 100TX-FD |
| 83 |
- 10T-HD |
| 84 |
- 20000-FD |
| 85 |
- 40000LR4-FD |
| 86 |
- 100000AR4-FD |
| 87 |
- 100000SR4-FD |
| 88 |
- 10000SFPCU-FD |
| 89 |
- 1000CX-FD |
| 90 |
- 1000T-FD |
| 91 |
- 100TX-HD |
| 92 |
- 12000-FD |
| 93 |
- 21000-FD |
| 94 |
- 40000SR4-FD |
| 95 |
- 100000CR4-FD |
| 96 |
- 10000ER-FD |
| 97 |
- 10000SR-FD |
| 98 |
- 1000LX-FD |
| 99 |
- 1000T-HD |
| 100 |
- 10T-FD |
| 101 |
- 16000-FD |
| 102 |
- 40000-FD |
| 103 |
- 42000-FD |
| 104 |
- auto |
| 105 |
- no-phy |
| 106 |
media_sfp: |
| 107 |
description: |
| 108 |
- "Specifies the settings for an SFP (pluggable) interface." |
| 109 |
- Use this option only with a combo port to specify the media type for the SFP interface, |
| 110 |
when it is not the preferred port. |
| 111 |
type: str |
| 112 |
choices: |
| 113 |
- 100000-FD |
| 114 |
- 100000LR4-FD |
| 115 |
- 10000LR-FD |
| 116 |
- 10000T-FD |
| 117 |
- 1000SX-FD |
| 118 |
- 100TX-FD |
| 119 |
- 10T-HD |
| 120 |
- 20000-FD |
| 121 |
- 40000LR4-FD |
| 122 |
- 100000AR4-FD |
| 123 |
- 100000SR4-FD |
| 124 |
- 10000SFPCU-FD |
| 125 |
- 1000CX-FD |
| 126 |
- 1000T-FD |
| 127 |
- 100TX-HD |
| 128 |
- 12000-FD |
| 129 |
- 21000-FD |
| 130 |
- 40000SR4-FD |
| 131 |
- 100000CR4-FD |
| 132 |
- 10000ER-FD |
| 133 |
- 10000SR-FD |
| 134 |
- 1000LX-FD |
| 135 |
- 1000T-HD |
| 136 |
- 10T-FD |
| 137 |
- 16000-FD |
| 138 |
- 40000-FD |
| 139 |
- 42000-FD |
| 140 |
- auto |
| 141 |
- no-phy |
| 142 |
flow_control: |
| 143 |
description: |
| 144 |
- Specifies how the system controls the sending of PAUSE frames. |
| 145 |
- When C(tx-rx), the interface honors pause frames from its partner, |
| 146 |
and also generates pause frames when necessary. |
| 147 |
- When C(tx), the interface ignores pause frames from its partner, and generates pause frames when necessary. |
| 148 |
- When C(rx), the interface honors pause frames from its partner, but does not generate pause frames. |
| 149 |
- When (none), the flow control is disabled on the interface. |
| 150 |
type: str |
| 151 |
choices: |
| 152 |
- none |
| 153 |
- rx |
| 154 |
- tx |
| 155 |
- tx-rx |
| 156 |
forward_error_correction: |
| 157 |
description: |
| 158 |
- "Enables or disables IEEE 802.3bm Clause 91 Reed-Solomon Forward Error Correction on 100G interfaces. Not valid |
| 159 |
for LR4 media." |
| 160 |
- This option is only supported on selected hardware platforms and interfaces. |
| 161 |
- "Attempting to enable this option on a C(VE) or any other unsupported platform/interface |
| 162 |
will result in module run failure." |
| 163 |
type: str |
| 164 |
choices: |
| 165 |
- enabled |
| 166 |
- disabled |
| 167 |
- not-supported |
| 168 |
- auto |
| 169 |
port_fwd_mode: |
| 170 |
description: |
| 171 |
- Specifies the operation mode. |
| 172 |
type: str |
| 173 |
choices: |
| 174 |
- l3 |
| 175 |
- passive |
| 176 |
- virtual-wire |
| 177 |
lldp_admin: |
| 178 |
description: |
| 179 |
- Specifies LLDP settings on an interface level. |
| 180 |
- When C(disabled), the interface neither transmits (sends) LLDP messages to nor receives LLDP messages |
| 181 |
from neighboring devices. |
| 182 |
- When C(txonly), the interface transmits LLDP messages to neighbor devices, but does not receive LLDP messages |
| 183 |
from neighbor devices. |
| 184 |
- When C(rxonly), the interface receives LLDP messages from neighbor devices, but does not transmit LLDP messages |
| 185 |
to neighbor devices. |
| 186 |
- When C(txrx), the interface transmits LLDP messages to and receives LLDP messages from neighboring devices. |
| 187 |
type: str |
| 188 |
choices: |
| 189 |
- disable |
| 190 |
- rxonly |
| 191 |
- txonly |
| 192 |
- txrx |
| 193 |
lldp_tlvmap: |
| 194 |
description: |
| 195 |
- Specifies the content of an LLDP message being sent or received. |
| 196 |
- "Each LLDP attribute specified with this setting is optional and is in the form of Type, Length, Value |
| 197 |
(TLV)." |
| 198 |
- "The three mandatory TLVs not taken into account when calculating this value are: C(Chassis ID), C(Port ID), |
| 199 |
and C(TTL)." |
| 200 |
- The optional attributes that are available have a specific TLV numeric value mapped to them. |
| 201 |
- The C(Port Description) attribute has a TLV value of C(8). |
| 202 |
- The C(System Name) attribute has a TLV value of C(16). |
| 203 |
- The C(System Description) attribute has a TLV value of C(32). |
| 204 |
- The C(System Capabilities) attribute has a TLV value of C(64). |
| 205 |
- The C(Management Address) attribute has a TLV value of C(128). |
| 206 |
- The C(Port VLAN ID) attribute has a TLV value of C(256). |
| 207 |
- The C(VLAN Name) attribute has a TLV value of C(512). |
| 208 |
- The C(Port and Protocol VLAN ID) attribute has a TLV value of C(1024). |
| 209 |
- The C(Protocol Identity) attribute has a TLV value of C(2048). |
| 210 |
- "The C(MAC/PHY Config Status) attribute has a TLV value of C(4096)." |
| 211 |
- The C(Link Aggregation) attribute has a TLV value of C(8192). |
| 212 |
- The C(Max Frame Size) attribute has a TLV value of C(32768). |
| 213 |
- The C(Product Model) attribute has a TLV value of C(65536). |
| 214 |
- The C(lldp_tlvmap) is a numeric value that is a sum of all TLV values of selected attributes. |
| 215 |
- Setting C(lldp_tlvmap) to C(0) will remove all attributes from the interface. |
| 216 |
- Setting C(lldp_tlvmap) to C(114680) will add all attributes to the interface. |
| 217 |
type: int |
| 218 |
stp: |
| 219 |
description: |
| 220 |
- Enables or disables STP. |
| 221 |
type: bool |
| 222 |
stp_auto_edge_port: |
| 223 |
description: |
| 224 |
- Sets STP automatic edge port detection for the interface. |
| 225 |
- "When C(true), the system monitors the interface for incoming STP, RSTP, or MSTP packets. If no such packets are |
| 226 |
received for a sufficient period of time (about three seconds), the interface is automatically given edge port |
| 227 |
status." |
| 228 |
- When C(false), the system never gives the interface edge port status automatically. Any STP setting set on a |
| 229 |
per-interface basis applies to all spanning tree instances. |
| 230 |
type: bool |
| 231 |
stp_edge_port: |
| 232 |
description: |
| 233 |
- Specifies whether the interface connects to an end station instead of another spanning tree bridge. |
| 234 |
type: bool |
| 235 |
stp_link_type: |
| 236 |
description: |
| 237 |
- Specifies the STP link type for the interface. |
| 238 |
type: str |
| 239 |
choices: |
| 240 |
- auto |
| 241 |
- p2p |
| 242 |
- shared |
| 243 |
sflow: |
| 244 |
description: |
| 245 |
- Specifies sFlow settings for the interface. |
| 246 |
suboptions: |
| 247 |
poll_interval: |
| 248 |
description: |
| 249 |
- Specifies the maximum interval between two pollings, in seconds. |
| 250 |
- For this setting to take effect, C(poll_interval_global) must be set to C(false). |
| 251 |
- The valid range is 0 - 4294967295. |
| 252 |
type: int |
| 253 |
poll_interval_global: |
| 254 |
description: |
| 255 |
- Specifies whether the global interface C(poll_interval) setting overrides the object-level |
| 256 |
C(poll_interval) setting. |
| 257 |
- When C(true)) the C(poll_interval) setting does not take effect. |
| 258 |
type: bool |
| 259 |
type: dict |
| 260 |
extends_documentation_fragment: f5networks.f5_modules.f5 |
| 261 |
author: |
| 262 |
- Wojciech Wypior (@wojtek0806) |
| 263 |
''' |
| 264 |
|
| 265 |
EXAMPLES = r''' |
| 266 |
- name: Update Interface Settings |
| 267 |
bigip_interface: |
| 268 |
name: 1.1 |
| 269 |
stp: true |
| 270 |
stp_auto_edge_port: false |
| 271 |
stp_edge_port: true |
| 272 |
stp_link_type: shared |
| 273 |
description: my description |
| 274 |
flow_control: tx |
| 275 |
lldp_admin: txrx |
| 276 |
lldp_tlvmap: 8 |
| 277 |
force_gigabit_fiber: false |
| 278 |
sflow: |
| 279 |
- poll_interval: 10 |
| 280 |
- poll_interval_global: false |
| 281 |
provider: |
| 282 |
password: secret |
| 283 |
server: lb.mydomain.com |
| 284 |
user: admin |
| 285 |
delegate_to: localhost |
| 286 |
|
| 287 |
- name: Disable Interface |
| 288 |
bigip_interface: |
| 289 |
name: 1.1 |
| 290 |
enabled: false |
| 291 |
provider: |
| 292 |
password: secret |
| 293 |
server: lb.mydomain.com |
| 294 |
user: admin |
| 295 |
delegate_to: localhost |
| 296 |
|
| 297 |
- name: Change sflow interface settings |
| 298 |
bigip_interface: |
| 299 |
name: 1.1 |
| 300 |
sflow: |
| 301 |
- poll_interval: 0 |
| 302 |
- poll_interval_global: true |
| 303 |
provider: |
| 304 |
password: secret |
| 305 |
server: lb.mydomain.com |
| 306 |
user: admin |
| 307 |
delegate_to: localhost |
| 308 |
''' |
| 309 |
|
| 310 |
RETURN = r''' |
| 311 |
description: |
| 312 |
description: User defined description. |
| 313 |
returned: changed |
| 314 |
type: str |
| 315 |
sample: my description |
| 316 |
enabled: |
| 317 |
description: The current status of the interface. |
| 318 |
returned: changed |
| 319 |
type: bool |
| 320 |
sample: true |
| 321 |
bundle: |
| 322 |
description: Enables or disables bundle capability. |
| 323 |
returned: changed |
| 324 |
type: str |
| 325 |
sample: not-supported |
| 326 |
bundle_speed: |
| 327 |
description: The bundle speed. |
| 328 |
returned: changed |
| 329 |
type: str |
| 330 |
sample: 100G |
| 331 |
force_gigabit_fiber: |
| 332 |
description: Enables or disables forcing of gigabit fiber media. |
| 333 |
returned: changed |
| 334 |
type: bool |
| 335 |
sample: true |
| 336 |
prefer_port: |
| 337 |
description: The side of a combo port the interface uses. |
| 338 |
returned: changed |
| 339 |
type: str |
| 340 |
sample: fixed |
| 341 |
media_fixed: |
| 342 |
description: The settings for a fixed interface. |
| 343 |
returned: changed |
| 344 |
type: str |
| 345 |
sample: 100000-FD |
| 346 |
media_sfp: |
| 347 |
description: The settings for a SFP interface. |
| 348 |
returned: changed |
| 349 |
type: str |
| 350 |
sample: 100000-FD |
| 351 |
flow_control: |
| 352 |
description: Specifies how the system controls the sending of PAUSE frames. |
| 353 |
returned: changed |
| 354 |
type: str |
| 355 |
sample: tx |
| 356 |
forward_error_correction: |
| 357 |
description: Enables or disables Forward Error Correction. |
| 358 |
returned: changed |
| 359 |
type: str |
| 360 |
sample: auto |
| 361 |
port_fwd_mode: |
| 362 |
description: The operation mode. |
| 363 |
returned: changed |
| 364 |
type: str |
| 365 |
sample: passive |
| 366 |
lldp_admin: |
| 367 |
description: The LLDP settings on an interface level. |
| 368 |
returned: changed |
| 369 |
type: str |
| 370 |
sample: txrx |
| 371 |
lldp_tlvmap: |
| 372 |
description: The content of an LLDP message being sent or received. |
| 373 |
returned: changed |
| 374 |
type: int |
| 375 |
sample: 136 |
| 376 |
stp: |
| 377 |
description: Enables or disables STP. |
| 378 |
returned: changed |
| 379 |
type: bool |
| 380 |
sample: false |
| 381 |
stp_auto_edge_port: |
| 382 |
description: Sets STP automatic edge port detection for the interface. |
| 383 |
returned: changed |
| 384 |
type: bool |
| 385 |
sample: true |
| 386 |
stp_edge_port: |
| 387 |
description: Specifies whether the interface connects to an end station instead of another spanning tree bridge. |
| 388 |
returned: changed |
| 389 |
type: bool |
| 390 |
sample: false |
| 391 |
stp_link_type: |
| 392 |
description: The STP link type for the interface. |
| 393 |
returned: changed |
| 394 |
type: str |
| 395 |
sample: shared |
| 396 |
sflow: |
| 397 |
description: Specifies sFlow settings for the interface. |
| 398 |
type: complex |
| 399 |
returned: changed |
| 400 |
contains: |
| 401 |
poll_interval_global: |
| 402 |
description: The global sFlow settings override. |
| 403 |
returned: changed |
| 404 |
type: bool |
| 405 |
sample: true |
| 406 |
poll_interval: |
| 407 |
description: The maximum interval in seconds between two pollings. |
| 408 |
returned: changed |
| 409 |
type: int |
| 410 |
sample: 128 |
| 411 |
sample: hash/dictionary of values |
| 412 |
''' |
| 413 |
|
| 414 |
import copy |
| 415 |
from datetime import datetime |
| 416 |
|
| 417 |
from ansible.module_utils.basic import AnsibleModule |
| 418 |
|
| 419 |
from ..module_utils.bigip import F5RestClient |
| 420 |
from ..module_utils.common import ( |
| 421 |
F5ModuleError, AnsibleF5Parameters, f5_argument_spec, flatten_boolean, |
| 422 |
transform_name |
| 423 |
) |
| 424 |
from ..module_utils.compare import cmp_str_with_none |
| 425 |
from ..module_utils.icontrol import tmos_version |
| 426 |
from ..module_utils.teem import send_teem |
| 427 |
|
| 428 |
|
| 429 |
class Parameters(AnsibleF5Parameters): |
| 430 |
api_map = { |
| 431 |
'bundleSpeed': 'bundle_speed', |
| 432 |
'flowControl': 'flow_control', |
| 433 |
'forceGigabitFiber': 'force_gigabit_fiber', |
| 434 |
'forwardErrorCorrection': 'forward_error_correction', |
| 435 |
'lldpAdmin': 'lldp_admin', |
| 436 |
'lldpTlvmap': 'lldp_tlvmap', |
| 437 |
'mediaFixed': 'media_fixed', |
| 438 |
'mediaSfp': 'media_sfp', |
| 439 |
'portFwdMode': 'port_fwd_mode', |
| 440 |
'preferPort': 'prefer_port', |
| 441 |
'stpAutoEdgePort': 'stp_auto_edge_port', |
| 442 |
'stpEdgePort': 'stp_edge_port', |
| 443 |
'stpLinkType': 'stp_link_type', |
| 444 |
} |
| 445 |
|
| 446 |
api_attributes = [ |
| 447 |
'bundle', |
| 448 |
'bundleSpeed', |
| 449 |
'description', |
| 450 |
'enabled', |
| 451 |
'disabled', |
| 452 |
'flowControl', |
| 453 |
'forceGigabitFiber', |
| 454 |
'forwardErrorCorrection', |
| 455 |
'lldpAdmin', |
| 456 |
'lldpTlvmap', |
| 457 |
'mediaFixed', |
| 458 |
'mediaSfp', |
| 459 |
'portFwdMode', |
| 460 |
'preferPort', |
| 461 |
'stp', |
| 462 |
'stpAutoEdgePort', |
| 463 |
'stpEdgePort', |
| 464 |
'stpLinkType', |
| 465 |
'sflow', |
| 466 |
] |
| 467 |
|
| 468 |
returnables = [ |
| 469 |
'description', |
| 470 |
'enabled', |
| 471 |
'disabled', |
| 472 |
'bundle', |
| 473 |
'bundle_speed', |
| 474 |
'force_gigabit_fiber', |
| 475 |
'prefer_port', |
| 476 |
'media_fixed', |
| 477 |
'media_sfp', |
| 478 |
'flow_control', |
| 479 |
'forward_error_correction', |
| 480 |
'port_fwd_mode', |
| 481 |
'lldp_tlvmap', |
| 482 |
'lldp_admin', |
| 483 |
'stp', |
| 484 |
'stp_auto_edge_port', |
| 485 |
'stp_edge_port', |
| 486 |
'stp_link_type', |
| 487 |
'sflow_interval', |
| 488 |
'sflow_global', |
| 489 |
] |
| 490 |
|
| 491 |
updatables = [ |
| 492 |
'description', |
| 493 |
'enabled', |
| 494 |
'disabled', |
| 495 |
'bundle', |
| 496 |
'bundle_speed', |
| 497 |
'force_gigabit_fiber', |
| 498 |
'prefer_port', |
| 499 |
'media_fixed', |
| 500 |
'media_sfp', |
| 501 |
'flow_control', |
| 502 |
'forward_error_correction', |
| 503 |
'port_fwd_mode', |
| 504 |
'lldp_tlvmap', |
| 505 |
'lldp_admin', |
| 506 |
'stp', |
| 507 |
'stp_auto_edge_port', |
| 508 |
'stp_edge_port', |
| 509 |
'stp_link_type', |
| 510 |
'sflow_interval', |
| 511 |
'sflow_global', |
| 512 |
] |
| 513 |
|
| 514 |
|
| 515 |
class ApiParameters(Parameters): |
| 516 |
@property |
| 517 |
def sflow_interval(self): |
| 518 |
if self._values['sflow'] is None: |
| 519 |
return None |
| 520 |
return self._values['sflow']['pollInterval'] |
| 521 |
|
| 522 |
@property |
| 523 |
def sflow_global(self): |
| 524 |
if self._values['sflow'] is None: |
| 525 |
return None |
| 526 |
return self._values['sflow']['pollIntervalGlobal'] |
| 527 |
|
| 528 |
|
| 529 |
class ModuleParameters(Parameters): |
| 530 |
@property |
| 531 |
def enabled(self): |
| 532 |
result = flatten_boolean(self._values['enabled']) |
| 533 |
if result == 'yes': |
| 534 |
return True |
| 535 |
|
| 536 |
@property |
| 537 |
def disabled(self): |
| 538 |
result = flatten_boolean(self._values['enabled']) |
| 539 |
if result == 'no': |
| 540 |
return True |
| 541 |
|
| 542 |
@property |
| 543 |
def lldp_tlvmap(self): |
| 544 |
if self._values['lldp_tlvmap'] is None: |
| 545 |
return None |
| 546 |
if self._values['lldp_tlvmap'] == 0: |
| 547 |
return self._values['lldp_tlvmap'] |
| 548 |
if 8 <= self._values['lldp_tlvmap'] <= 114680: |
| 549 |
return self._values['lldp_tlvmap'] |
| 550 |
raise F5ModuleError( |
| 551 |
"TLV value {0} is out of valid range of: 8 - 114680." |
| 552 |
) |
| 553 |
|
| 554 |
@property |
| 555 |
def force_gigabit_fiber(self): |
| 556 |
result = flatten_boolean(self._values['force_gigabit_fiber']) |
| 557 |
if result == 'yes': |
| 558 |
return 'enabled' |
| 559 |
if result == 'no': |
| 560 |
return 'disabled' |
| 561 |
|
| 562 |
@property |
| 563 |
def stp(self): |
| 564 |
result = flatten_boolean(self._values['stp']) |
| 565 |
if result == 'yes': |
| 566 |
return 'enabled' |
| 567 |
if result == 'no': |
| 568 |
return 'disabled' |
| 569 |
|
| 570 |
@property |
| 571 |
def stp_auto_edge_port(self): |
| 572 |
result = flatten_boolean(self._values['stp_auto_edge_port']) |
| 573 |
if result == 'yes': |
| 574 |
return 'enabled' |
| 575 |
if result == 'no': |
| 576 |
return 'disabled' |
| 577 |
|
| 578 |
@property |
| 579 |
def stp_edge_port(self): |
| 580 |
result = flatten_boolean(self._values['stp_edge_port']) |
| 581 |
if result == 'yes': |
| 582 |
return 'true' |
| 583 |
if result == 'no': |
| 584 |
return 'false' |
| 585 |
|
| 586 |
@property |
| 587 |
def sflow_interval(self): |
| 588 |
if self._values['sflow'] is None: |
| 589 |
return None |
| 590 |
if self._values['sflow']['poll_interval'] is None: |
| 591 |
return None |
| 592 |
if 0 <= self._values['sflow']['poll_interval'] <= 4294967295: |
| 593 |
return self._values['sflow']['poll_interval'] |
| 594 |
raise F5ModuleError( |
| 595 |
"Valid 'poll_interval' must be in range 0 - 4294967295." |
| 596 |
) |
| 597 |
|
| 598 |
@property |
| 599 |
def sflow_global(self): |
| 600 |
if self._values['sflow'] is None: |
| 601 |
return None |
| 602 |
result = flatten_boolean(self._values['sflow']['poll_interval_global']) |
| 603 |
return result |
| 604 |
|
| 605 |
|
| 606 |
class Changes(Parameters): |
| 607 |
def to_return(self): |
| 608 |
result = {} |
| 609 |
try: |
| 610 |
for returnable in self.returnables: |
| 611 |
result[returnable] = getattr(self, returnable) |
| 612 |
result = self._filter_params(result) |
| 613 |
except Exception: |
| 614 |
raise |
| 615 |
return result |
| 616 |
|
| 617 |
|
| 618 |
class UsableChanges(Changes): |
| 619 |
@property |
| 620 |
def sflow(self): |
| 621 |
to_filter = dict( |
| 622 |
pollInterval=self._values['sflow_interval'], |
| 623 |
pollIntervalGlobal=self._values['sflow_global'], |
| 624 |
) |
| 625 |
result = self._filter_params(to_filter) |
| 626 |
if result: |
| 627 |
return result |
| 628 |
|
| 629 |
|
| 630 |
class ReportableChanges(Changes): |
| 631 |
returnables = [ |
| 632 |
'description', |
| 633 |
'enabled', |
| 634 |
'bundle', |
| 635 |
'bundle_speed', |
| 636 |
'force_gigabit_fiber', |
| 637 |
'prefer_port', |
| 638 |
'media_fixed', |
| 639 |
'media_sfp', |
| 640 |
'flow_control', |
| 641 |
'forward_error_correction', |
| 642 |
'port_fwd_mode', |
| 643 |
'lldp_tlvmap', |
| 644 |
'lldp_admin', |
| 645 |
'stp', |
| 646 |
'stp_auto_edge_port', |
| 647 |
'stp_edge_port', |
| 648 |
'stp_link_type', |
| 649 |
'sflow', |
| 650 |
] |
| 651 |
|
| 652 |
@property |
| 653 |
def enabled(self): |
| 654 |
enabled = self._values.get('enabled', None) |
| 655 |
disabled = self._values.get('disabled', None) |
| 656 |
if enabled: |
| 657 |
return 'yes' |
| 658 |
if disabled: |
| 659 |
return 'no' |
| 660 |
|
| 661 |
@property |
| 662 |
def stp(self): |
| 663 |
result = flatten_boolean(self._values['stp']) |
| 664 |
return result |
| 665 |
|
| 666 |
@property |
| 667 |
def stp_auto_edge_port(self): |
| 668 |
result = flatten_boolean(self._values['stp_auto_edge_port']) |
| 669 |
return result |
| 670 |
|
| 671 |
@property |
| 672 |
def stp_edge_port(self): |
| 673 |
result = flatten_boolean(self._values['stp_edge_port']) |
| 674 |
return result |
| 675 |
|
| 676 |
@property |
| 677 |
def sflow(self): |
| 678 |
to_filter = dict( |
| 679 |
poll_interval=self._values['sflow_interval'], |
| 680 |
poll_interval_global=self._values['sflow_global'], |
| 681 |
) |
| 682 |
result = self._filter_params(to_filter) |
| 683 |
if result: |
| 684 |
return result |
| 685 |
|
| 686 |
|
| 687 |
class Difference(object): |
| 688 |
def __init__(self, want, have=None): |
| 689 |
self.want = want |
| 690 |
self.have = have |
| 691 |
|
| 692 |
def compare(self, param): |
| 693 |
try: |
| 694 |
result = getattr(self, param) |
| 695 |
return result |
| 696 |
except AttributeError: |
| 697 |
return self.__default(param) |
| 698 |
|
| 699 |
def __default(self, param): |
| 700 |
attr1 = getattr(self.want, param) |
| 701 |
try: |
| 702 |
attr2 = getattr(self.have, param) |
| 703 |
if attr1 != attr2: |
| 704 |
return attr1 |
| 705 |
except AttributeError: |
| 706 |
return attr1 |
| 707 |
|
| 708 |
@property |
| 709 |
def description(self): |
| 710 |
result = cmp_str_with_none(self.want.description, self.have.description) |
| 711 |
return result |
| 712 |
|
| 713 |
|
| 714 |
class ModuleManager(object): |
| 715 |
def __init__(self, *args, **kwargs): |
| 716 |
self.module = kwargs.get('module', None) |
| 717 |
self.client = F5RestClient(**self.module.params) |
| 718 |
self.want = ModuleParameters(params=self.module.params) |
| 719 |
self.have = ApiParameters() |
| 720 |
self.changes = UsableChanges() |
| 721 |
|
| 722 |
def _update_changed_options(self): |
| 723 |
diff = Difference(self.want, self.have) |
| 724 |
updatables = Parameters.updatables |
| 725 |
changed = dict() |
| 726 |
for k in updatables: |
| 727 |
change = diff.compare(k) |
| 728 |
if change is None: |
| 729 |
continue |
| 730 |
else: |
| 731 |
if isinstance(change, dict): |
| 732 |
changed.update(change) |
| 733 |
else: |
| 734 |
changed[k] = change |
| 735 |
if changed: |
| 736 |
self.changes = UsableChanges(params=changed) |
| 737 |
return True |
| 738 |
return False |
| 739 |
|
| 740 |
def _announce_deprecations(self, result): |
| 741 |
warnings = result.pop('__warnings', []) |
| 742 |
for warning in warnings: |
| 743 |
self.client.module.deprecate( |
| 744 |
msg=warning['msg'], |
| 745 |
version=warning['version'] |
| 746 |
) |
| 747 |
|
| 748 |
def exec_module(self): |
| 749 |
start = datetime.now().isoformat() |
| 750 |
version = tmos_version(self.client) |
| 751 |
result = dict() |
| 752 |
|
| 753 |
changed = self.present() |
| 754 |
|
| 755 |
reportable = ReportableChanges(params=self.changes.to_return()) |
| 756 |
changes = reportable.to_return() |
| 757 |
result.update(**changes) |
| 758 |
result.update(dict(changed=changed)) |
| 759 |
self._announce_deprecations(result) |
| 760 |
send_teem(start, self.client, self.module, version) |
| 761 |
return result |
| 762 |
|
| 763 |
def present(self): |
| 764 |
if self.exists(): |
| 765 |
return self.update() |
| 766 |
else: |
| 767 |
raise F5ModuleError( |
| 768 |
"The specified interface: {0} does not exist.".format(self.want.name) |
| 769 |
) |
| 770 |
|
| 771 |
def should_update(self): |
| 772 |
result = self._update_changed_options() |
| 773 |
if result: |
| 774 |
return True |
| 775 |
return False |
| 776 |
|
| 777 |
def update(self): |
| 778 |
self.have = self.read_current_from_device() |
| 779 |
if not self.should_update(): |
| 780 |
return False |
| 781 |
if self.module.check_mode: |
| 782 |
return True |
| 783 |
self.update_on_device() |
| 784 |
return True |
| 785 |
|
| 786 |
def exists(self): |
| 787 |
uri = "https://{0}:{1}/mgmt/tm/net/interface/{2}".format( |
| 788 |
self.client.provider['server'], |
| 789 |
self.client.provider['server_port'], |
| 790 |
transform_name(name=self.want.name) |
| 791 |
) |
| 792 |
resp = self.client.api.get(uri) |
| 793 |
try: |
| 794 |
response = resp.json() |
| 795 |
except ValueError as ex: |
| 796 |
raise F5ModuleError(str(ex)) |
| 797 |
|
| 798 |
if resp.status == 404 or 'code' in response and response['code'] == 404: |
| 799 |
return False |
| 800 |
if resp.status in [200, 201] or 'code' in response and response['code'] in [200, 201]: |
| 801 |
return True |
| 802 |
|
| 803 |
errors = [401, 403, 409, 500, 501, 502, 503, 504] |
| 804 |
|
| 805 |
if resp.status in errors or 'code' in response and response['code'] in errors: |
| 806 |
if 'message' in response: |
| 807 |
raise F5ModuleError(response['message']) |
| 808 |
else: |
| 809 |
raise F5ModuleError(resp.content) |
| 810 |
|
| 811 |
def update_on_device(self): |
| 812 |
params = self.changes.api_params() |
| 813 |
uri = "https://{0}:{1}/mgmt/tm/net/interface/{2}".format( |
| 814 |
self.client.provider['server'], |
| 815 |
self.client.provider['server_port'], |
| 816 |
transform_name(name=self.want.name) |
| 817 |
) |
| 818 |
resp = self.client.api.patch(uri, json=params) |
| 819 |
try: |
| 820 |
response = resp.json() |
| 821 |
except ValueError as ex: |
| 822 |
raise F5ModuleError(str(ex)) |
| 823 |
|
| 824 |
if resp.status in [200, 201] or 'code' in response and response['code'] in [200, 201]: |
| 825 |
return True |
| 826 |
raise F5ModuleError(resp.content) |
| 827 |
|
| 828 |
def read_current_from_device(self): |
| 829 |
uri = "https://{0}:{1}/mgmt/tm/net/interface/{2}".format( |
| 830 |
self.client.provider['server'], |
| 831 |
self.client.provider['server_port'], |
| 832 |
transform_name(name=self.want.name) |
| 833 |
) |
| 834 |
resp = self.client.api.get(uri) |
| 835 |
try: |
| 836 |
response = resp.json() |
| 837 |
except ValueError as ex: |
| 838 |
raise F5ModuleError(str(ex)) |
| 839 |
|
| 840 |
if resp.status in [200, 201] or 'code' in response and response['code'] in [200, 201]: |
| 841 |
return ApiParameters(params=response) |
| 842 |
raise F5ModuleError(resp.content) |
| 843 |
|
| 844 |
|
| 845 |
class ArgumentSpec(object): |
| 846 |
def __init__(self): |
| 847 |
self.supports_check_mode = True |
| 848 |
self.choices = [ |
| 849 |
'100000-FD', '100000LR4-FD', '10000LR-FD', '10000T-FD', '1000SX-FD', '100TX-FD', '10T-HD', '20000-FD', |
| 850 |
'40000LR4-FD', '100000AR4-FD', '100000SR4-FD', '10000SFPCU-FD', '1000CX-FD', '1000T-FD', '100TX-HD', |
| 851 |
'12000-FD', '21000-FD', '40000SR4-FD', '100000CR4-FD', '10000ER-FD', '10000SR-FD', '1000LX-FD', '1000T-HD', |
| 852 |
'10T-FD', '16000-FD', '40000-FD', '42000-FD', 'auto', 'no-phy' |
| 853 |
] |
| 854 |
self.bundle = ['disabled', 'enabled', 'not-supported'] |
| 855 |
self.fec = copy.copy(self.bundle) |
| 856 |
self.fec.append('auto') |
| 857 |
argument_spec = dict( |
| 858 |
name=dict( |
| 859 |
required=True |
| 860 |
), |
| 861 |
description=dict(), |
| 862 |
enabled=dict( |
| 863 |
type='bool' |
| 864 |
), |
| 865 |
bundle=dict(choices=self.bundle), |
| 866 |
bundle_speed=dict( |
| 867 |
choices=[ |
| 868 |
'100G', '40G', 'not-supported' |
| 869 |
] |
| 870 |
), |
| 871 |
force_gigabit_fiber=dict(type='bool'), |
| 872 |
prefer_port=dict( |
| 873 |
choices=[ |
| 874 |
'fixed', 'sfp' |
| 875 |
] |
| 876 |
), |
| 877 |
media_fixed=dict(choices=self.choices), |
| 878 |
media_sfp=dict(choices=self.choices), |
| 879 |
flow_control=dict( |
| 880 |
choices=[ |
| 881 |
'none', 'rx', 'tx', 'tx-rx' |
| 882 |
] |
| 883 |
), |
| 884 |
forward_error_correction=dict(choices=self.fec), |
| 885 |
port_fwd_mode=dict( |
| 886 |
choices=[ |
| 887 |
'l3', 'passive', 'virtual-wire' |
| 888 |
] |
| 889 |
), |
| 890 |
lldp_tlvmap=dict(type='int'), |
| 891 |
lldp_admin=dict( |
| 892 |
choices=[ |
| 893 |
'disable', 'rxonly', 'txonly', 'txrx' |
| 894 |
] |
| 895 |
), |
| 896 |
stp=dict(type='bool'), |
| 897 |
stp_auto_edge_port=dict(type='bool'), |
| 898 |
stp_edge_port=dict(type='bool'), |
| 899 |
stp_link_type=dict( |
| 900 |
choices=['auto', 'p2p', 'shared'] |
| 901 |
), |
| 902 |
sflow=dict( |
| 903 |
type='dict', |
| 904 |
options=dict( |
| 905 |
poll_interval=dict(type='int'), |
| 906 |
poll_interval_global=dict(type='bool'), |
| 907 |
) |
| 908 |
) |
| 909 |
) |
| 910 |
self.argument_spec = {} |
| 911 |
self.argument_spec.update(f5_argument_spec) |
| 912 |
self.argument_spec.update(argument_spec) |
| 913 |
|
| 914 |
|
| 915 |
def main(): |
| 916 |
spec = ArgumentSpec() |
| 917 |
|
| 918 |
module = AnsibleModule( |
| 919 |
argument_spec=spec.argument_spec, |
| 920 |
supports_check_mode=spec.supports_check_mode, |
| 921 |
) |
| 922 |
|
| 923 |
try: |
| 924 |
mm = ModuleManager(module=module) |
| 925 |
results = mm.exec_module() |
| 926 |
module.exit_json(**results) |
| 927 |
except F5ModuleError as ex: |
| 928 |
module.fail_json(msg=str(ex)) |
| 929 |
|
| 930 |
|
| 931 |
if __name__ == '__main__': |
| 932 |
main() |