| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright: (c) 2024, Anvitha Jain (@anvjain) <[email protected]> |
| 5 |
|
| 6 |
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 7 |
|
| 8 |
from __future__ import absolute_import, division, print_function |
| 9 |
|
| 10 |
__metaclass__ = type |
| 11 |
|
| 12 |
ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "community"} |
| 13 |
|
| 14 |
DOCUMENTATION = r""" |
| 15 |
--- |
| 16 |
module: ndo_interface_setting |
| 17 |
short_description: Manage Interface Policy Groups on Cisco Nexus Dashboard Orchestrator (NDO). |
| 18 |
description: |
| 19 |
- Manage Interface Policy Groups on Cisco Nexus Dashboard Orchestrator (NDO). |
| 20 |
- This module is only supported on ND v3.1 (NDO v4.3) and later. |
| 21 |
author: |
| 22 |
- Anvitha Jain (@anvjain) |
| 23 |
options: |
| 24 |
template: |
| 25 |
description: |
| 26 |
- The name of the template. |
| 27 |
- The template must be a fabric policy template. |
| 28 |
type: str |
| 29 |
required: true |
| 30 |
name: |
| 31 |
description: |
| 32 |
- The name of the interface policy group. |
| 33 |
type: str |
| 34 |
aliases: [ interface_policy_group, interface_setting ] |
| 35 |
uuid: |
| 36 |
description: |
| 37 |
- The UUID of the interface policy group. |
| 38 |
- This parameter is required when the O(name) attribute needs to be updated. |
| 39 |
type: str |
| 40 |
aliases: [ interface_policy_group_uuid, interface_setting_uuid ] |
| 41 |
description: |
| 42 |
description: |
| 43 |
- The description of the interface policy group. |
| 44 |
type: str |
| 45 |
interface_type: |
| 46 |
description: |
| 47 |
- The type of the interface policy group. |
| 48 |
- This parameter is required when interface policy group needs to be created or updated. |
| 49 |
type: str |
| 50 |
choices: [ physical, port_channel ] |
| 51 |
speed: |
| 52 |
description: |
| 53 |
- The port speed for the port(s) associated with the interface policy group. |
| 54 |
- The default value is C(inherit). |
| 55 |
type: str |
| 56 |
choices: [ 100M, 1G, 10G, 25G, 40G, 50G, 100G, 200G, 400G, inherit ] |
| 57 |
auto_negotiation: |
| 58 |
description: |
| 59 |
- The auto negotiation state of the port(s) in the interface policy group. |
| 60 |
- The default value is C(on). |
| 61 |
type: str |
| 62 |
choices: [ 'on', 'off', on_enforce ] |
| 63 |
vlan_scope: |
| 64 |
description: |
| 65 |
- The scope of the VLAN encapsulation of the port(s) in the interface policy group. |
| 66 |
- The default value is C(global). |
| 67 |
type: str |
| 68 |
choices: [ global, port_local ] |
| 69 |
cdp_admin_state: |
| 70 |
description: |
| 71 |
- The CDP admin state enables Cisco Discovery Protocol (CDP) on the interface. |
| 72 |
- The default value is C(disabled). |
| 73 |
type: str |
| 74 |
choices: [ enabled, disabled ] |
| 75 |
domains: |
| 76 |
description: |
| 77 |
- The domains with which you want to associate this interface policy. |
| 78 |
- The domains must be defined in the same fabric policy template. |
| 79 |
- The old O(domains) will be replaced by the new entries during an update. |
| 80 |
- Providing an empty list will remove the O(domains) from the interface policy. |
| 81 |
type: list |
| 82 |
elements: str |
| 83 |
port_channel_mode: |
| 84 |
description: |
| 85 |
- The port channel mode of the interface policy group. |
| 86 |
- The default value is C(static_channel_mode_on). |
| 87 |
- The value is available only when the interface_type is C(port_channel). |
| 88 |
type: str |
| 89 |
choices: [ static_channel_mode_on, lacp_passive, lacp_active, mac_pinning, mac_pinning_physical_nic_load, use_explicit_failover_order ] |
| 90 |
min_links: |
| 91 |
description: |
| 92 |
- The minimum number of active links in a port-channel of the interface policy group. |
| 93 |
- The default value is 1. |
| 94 |
- The value must be between 1 and 16. |
| 95 |
- The value is available only when the interface_type is C(port_channel). |
| 96 |
type: int |
| 97 |
max_links: |
| 98 |
description: |
| 99 |
- The maximum number of links in a port-channel of the interface policy group. |
| 100 |
- The default value is 16. |
| 101 |
- The value must be between 1 and 64. |
| 102 |
- The value is available only when the interface_type is C(port_channel). |
| 103 |
type: int |
| 104 |
controls: |
| 105 |
description: |
| 106 |
- The port-channel control flags of the interface policy group. |
| 107 |
- The default value is C(fast_sel_hot_stdby), C(graceful_conv), C(susp_individual). |
| 108 |
- The value is available only when the interface_type is C(port_channel). |
| 109 |
- Providing an empty list will remove the O(controls) from the interface policy. |
| 110 |
- The old O(controls) will be replaced by the new entries during an update. |
| 111 |
type: list |
| 112 |
elements: str |
| 113 |
choices: [ fast_sel_hot_stdby, graceful_conv, susp_individual, load_defer, symmetric_hash ] |
| 114 |
load_balance_hashing: |
| 115 |
description: |
| 116 |
- The IP header information used by the port-channel load balance hashing algorithm of the interface policy group. |
| 117 |
- The value is available only when the interface_type is C(port_channel). |
| 118 |
type: str |
| 119 |
choices: [ destination_ip, layer_4_destination_ip, layer_4_source_ip, source_ip ] |
| 120 |
synce: |
| 121 |
description: |
| 122 |
- The syncE policy assigned to the interface policy group. |
| 123 |
- The syncE policy must be defined in the same fabric policy template. |
| 124 |
type: str |
| 125 |
link_level_debounce_interval: |
| 126 |
description: |
| 127 |
- The debounce interval of the link level in milliseconds. |
| 128 |
- The default value is 100. |
| 129 |
- The value must be an integer between 0 and 5000. |
| 130 |
type: int |
| 131 |
link_level_bring_up_delay: |
| 132 |
description: |
| 133 |
- The time in milliseconds that the decision feedback equalizer (DFE) tuning is delayed when a port is coming up. |
| 134 |
- The default value is 0. |
| 135 |
- The value must be an integer between 0 and 10000. |
| 136 |
type: int |
| 137 |
link_level_fec: |
| 138 |
description: |
| 139 |
- The type of Forwarding Error Correction (FEC) used by the port(s) in the interface policy group. |
| 140 |
- The default value is C(inherit). |
| 141 |
type: str |
| 142 |
choices: [ inherit, cl74_fc_fec, cl91_rs_fec, cons16_rs_fec, ieee_rs_fec, kp_fec, disable_fec ] |
| 143 |
l2_interface_qinq: |
| 144 |
description: |
| 145 |
- The QinQ state for the port(s) in the interface policy group to define how to map double-tagged VLAN traffic. |
| 146 |
- The default value is C(disabled). |
| 147 |
type: str |
| 148 |
choices: [ core_port, double_q_tag_port, edge_port, disabled ] |
| 149 |
l2_interface_reflective_relay: |
| 150 |
description: |
| 151 |
- Enables or disables reflective relay (802.1Qbg) to forward traffic back to the destination or target. |
| 152 |
- The term Virtual Ethernet Port Aggregator (VEPA) is also used to describe 802.1Qbg functionality. |
| 153 |
- The default value is C(disabled). |
| 154 |
type: str |
| 155 |
choices: [ enabled, disabled ] |
| 156 |
lldp: |
| 157 |
description: |
| 158 |
- The Link Layer Discovery Protocol (LLDP) configuration of the interface policy group. |
| 159 |
type: dict |
| 160 |
suboptions: |
| 161 |
status: |
| 162 |
description: |
| 163 |
- The state of LLDP on the interface. |
| 164 |
- The default value is C(enabled). |
| 165 |
type: str |
| 166 |
choices: [ enabled, disabled ] |
| 167 |
transmit_state: |
| 168 |
description: |
| 169 |
- The transmit state allows LLDP packets to be sent from the interface. |
| 170 |
- The default value is C(enabled). |
| 171 |
type: str |
| 172 |
choices: [ enabled, disabled ] |
| 173 |
receive_state: |
| 174 |
description: |
| 175 |
- The receive state allows LLDP packets to be received by the interface. |
| 176 |
- The default value is C(enabled). |
| 177 |
type: str |
| 178 |
choices: [ enabled, disabled ] |
| 179 |
stp_bpdu_filter: |
| 180 |
description: |
| 181 |
- Enabling the Bridge Protocol Data Unit (BPDU) filter prevents any BPDUs on the port(s) |
| 182 |
- in the interface policy group by filtering the BPDUs. |
| 183 |
- Disabling the BPDU filter allows BPDUs to be received on the port. |
| 184 |
- The default value is C(disabled). |
| 185 |
type: str |
| 186 |
choices: [ enabled, disabled ] |
| 187 |
stp_bpdu_guard: |
| 188 |
description: |
| 189 |
- Enabling the STP BPDU guard shutdown the port(s) by placing them in 'error-disable' mode when BPDUs are received. |
| 190 |
- Disabling the STP BPDU guard allows BPDUs to be received on the port. |
| 191 |
- The default value is C(disabled). |
| 192 |
type: str |
| 193 |
choices: [ enabled, disabled ] |
| 194 |
llfc_transmit_state: |
| 195 |
description: |
| 196 |
- The LLFC transmit state allows Link Level Flow Control (LLFC) packets to be sent from the interface. |
| 197 |
- The default value is C(disabled). |
| 198 |
type: str |
| 199 |
choices: [ enabled, disabled ] |
| 200 |
llfc_receive_state: |
| 201 |
description: |
| 202 |
- The LLFC receive state allows LLFC packets to be received by the interface. |
| 203 |
- The default value is C(disabled). |
| 204 |
type: str |
| 205 |
choices: [ enabled, disabled ] |
| 206 |
mcp: |
| 207 |
description: |
| 208 |
- The MisCabling Protocol (MCP) settings. |
| 209 |
type: dict |
| 210 |
suboptions: |
| 211 |
admin_state: |
| 212 |
description: |
| 213 |
- The MCP admin state enables MisCabling Protocol (MCP) on the interface. |
| 214 |
- The default value is C(enabled). |
| 215 |
type: str |
| 216 |
choices: [ enabled, disabled ] |
| 217 |
strict_mode: |
| 218 |
description: |
| 219 |
- The MCP strict mode. |
| 220 |
- The value is available only when the MCP admin_state is C(enabled). |
| 221 |
- The default value is C(off). |
| 222 |
type: str |
| 223 |
choices: [ 'on', 'off' ] |
| 224 |
aliases: [ mcp_mode ] |
| 225 |
initial_delay_time: |
| 226 |
description: |
| 227 |
- The MCP initial delay time in seconds. |
| 228 |
- The default value is 180. |
| 229 |
- The value must be between 0 and 1800. |
| 230 |
- The value is available only when the MCP strict_mode is C(on). |
| 231 |
type: int |
| 232 |
transmission_frequency_sec: |
| 233 |
description: |
| 234 |
- The MCP transmission frequency in seconds. |
| 235 |
- The default value is 2. |
| 236 |
- The value must be between 0 and 300. |
| 237 |
- The value is available only when the MCP strict_mode is C(on). |
| 238 |
type: int |
| 239 |
transmission_frequency_msec: |
| 240 |
description: |
| 241 |
- The MCP transmission frequency in milliseconds. |
| 242 |
- The default value is 0. |
| 243 |
- The value must be between 0 and 999. |
| 244 |
- The value is available only when the MCP strict_mode is C(on). |
| 245 |
type: int |
| 246 |
grace_period_sec: |
| 247 |
description: |
| 248 |
- The MCP grace period in seconds. |
| 249 |
- The default value is 3. |
| 250 |
- The value must be between 0 and 300. |
| 251 |
- The value is available only when the MCP strict_mode is C(on). |
| 252 |
type: int |
| 253 |
grace_period_msec: |
| 254 |
description: |
| 255 |
- The MCP grace period in milliseconds. |
| 256 |
- The default value is 0. |
| 257 |
- The value must be between 0 and 999. |
| 258 |
- The value is available only when the MCP strict_mode is C(on). |
| 259 |
type: int |
| 260 |
pfc_admin_state: |
| 261 |
description: |
| 262 |
- The Priority Flow Control (PFC) admin state. |
| 263 |
- The default value is C(auto). |
| 264 |
type: str |
| 265 |
choices: [ 'on', 'off', auto ] |
| 266 |
access_macsec_policy: |
| 267 |
description: |
| 268 |
- The access MACsec policy. |
| 269 |
- The value is available only when the mcp_admin_state is C(enabled). |
| 270 |
- The MACsec policy must be defined in the same fabric policy template. |
| 271 |
type: str |
| 272 |
state: |
| 273 |
description: |
| 274 |
- Use C(absent) for removing. |
| 275 |
- Use C(query) for listing an object or multiple objects. |
| 276 |
- Use C(present) for creating or updating. |
| 277 |
type: str |
| 278 |
choices: [ absent, query, present ] |
| 279 |
default: query |
| 280 |
notes: |
| 281 |
- The O(template) must exist before using this module in your playbook. |
| 282 |
Use M(cisco.mso.ndo_template) to create the Tenant template. |
| 283 |
- The O(access_macsec_policy) must exist before using this module in your playbook. |
| 284 |
Use M(cisco.mso.ndo_macsec_policy) to create the MACsec policy. |
| 285 |
- The O(domains) must exist before using this module in your playbook. |
| 286 |
Use M(cisco.mso.ndo_physical_domain) or M(cisco.mso.ndo_l3_domain) to create the domain. |
| 287 |
- The O(synce) must exist before using this module in your playbook. |
| 288 |
Use M(cisco.mso.ndo_synce_interface_policy) to create the syncE policy. |
| 289 |
seealso: |
| 290 |
- module: cisco.mso.ndo_template |
| 291 |
- module: cisco.mso.ndo_macsec_policy |
| 292 |
extends_documentation_fragment: cisco.mso.modules |
| 293 |
""" |
| 294 |
|
| 295 |
EXAMPLES = r""" |
| 296 |
- name: Create an Interface policy group of interface_type physical |
| 297 |
cisco.mso.ndo_interface_setting: |
| 298 |
host: mso_host |
| 299 |
username: admin |
| 300 |
password: SomeSecretPassword |
| 301 |
template: ansible_test_template |
| 302 |
name: ansible_test_interface_policy_group_physical |
| 303 |
description: "Interface Policy Group for Ansible Test" |
| 304 |
interface_type: physical |
| 305 |
state: present |
| 306 |
|
| 307 |
- name: Create an Interface policy group of interface_type port_channel |
| 308 |
cisco.mso.ndo_interface_setting: |
| 309 |
host: mso_host |
| 310 |
username: admin |
| 311 |
password: SomeSecretPassword |
| 312 |
template: ansible_test_template |
| 313 |
name: ansible_test_interface_policy_group_port_channel |
| 314 |
description: "Interface Policy Group for Ansible Test" |
| 315 |
interface_type: port_channel |
| 316 |
state: present |
| 317 |
|
| 318 |
- name: Create an Interface policy group with all attributes |
| 319 |
cisco.mso.ndo_interface_setting: |
| 320 |
host: mso_host |
| 321 |
username: admin |
| 322 |
password: SomeSecretPassword |
| 323 |
template: ansible_test_template |
| 324 |
name: ansible_test_interface_policy_group_all |
| 325 |
description: "Interface Policy Group for Ansible Test" |
| 326 |
interface_type: port_channel |
| 327 |
speed: 1G |
| 328 |
auto_negotiation: on_enforce |
| 329 |
vlan_scope: port_local |
| 330 |
cdp_admin_state: enabled |
| 331 |
port_channel_mode: lacp_active |
| 332 |
min_links: 1 |
| 333 |
max_links: 16 |
| 334 |
controls: ["fast_sel_hot_stdby", "graceful_conv", "susp_individual"] |
| 335 |
load_balance_hashing: destination_ip |
| 336 |
synce: ansible_test_sync_e |
| 337 |
link_level_debounce_interval: 100 |
| 338 |
link_level_bring_up_delay: 0 |
| 339 |
link_level_fec: ieee_rs_fec |
| 340 |
l2_interface_qinq: edge_port |
| 341 |
l2_interface_reflective_relay: enabled |
| 342 |
lldp: |
| 343 |
status: enabled |
| 344 |
transmit_state: enabled |
| 345 |
receive_state: enabled |
| 346 |
domains: |
| 347 |
- ansible_test_domain1 |
| 348 |
- ansible_test_domain2 |
| 349 |
stp_bpdu_filter: enabled |
| 350 |
stp_bpdu_guard: enabled |
| 351 |
llfc_transmit_state: enabled |
| 352 |
llfc_receive_state: enabled |
| 353 |
mcp: |
| 354 |
admin_state: enabled |
| 355 |
strict_mode: 'on' |
| 356 |
initial_delay_time: 180 |
| 357 |
transmission_frequency_sec: 2 |
| 358 |
transmission_frequency_msec: 10 |
| 359 |
grace_period_sec: 3 |
| 360 |
grace_period_msec: 10 |
| 361 |
pfc_admin_state: 'on' |
| 362 |
state: present |
| 363 |
|
| 364 |
- name: Query all Interface policy groups |
| 365 |
cisco.mso.ndo_interface_setting: |
| 366 |
host: mso_host |
| 367 |
username: admin |
| 368 |
password: SomeSecretPassword |
| 369 |
template: ansible_test_template |
| 370 |
state: query |
| 371 |
register: query_all |
| 372 |
|
| 373 |
- name: Query a specific Interface policy group with name |
| 374 |
cisco.mso.ndo_interface_setting: |
| 375 |
host: mso_host |
| 376 |
username: admin |
| 377 |
password: SomeSecretPassword |
| 378 |
template: ansible_test_template |
| 379 |
name: ansible_test_interface_policy_group_physical |
| 380 |
state: query |
| 381 |
register: query_one_name |
| 382 |
|
| 383 |
- name: Query a specific Interface policy group with UUID |
| 384 |
cisco.mso.ndo_interface_setting: |
| 385 |
host: mso_host |
| 386 |
username: admin |
| 387 |
password: SomeSecretPassword |
| 388 |
template: ansible_test_template |
| 389 |
uuid: "{{ query_one_name.current.uuid }}" |
| 390 |
state: query |
| 391 |
register: query_one_uuid |
| 392 |
|
| 393 |
- name: Delete an Interface policy group with name |
| 394 |
cisco.mso.ndo_interface_setting: |
| 395 |
host: mso_host |
| 396 |
username: admin |
| 397 |
password: SomeSecretPassword |
| 398 |
template: ansible_test_template |
| 399 |
name: ansible_test_interface_policy_group_physical |
| 400 |
state: absent |
| 401 |
|
| 402 |
- name: Delete an Interface policy group with UUID |
| 403 |
cisco.mso.ndo_interface_setting: |
| 404 |
host: mso_host |
| 405 |
username: admin |
| 406 |
password: SomeSecretPassword |
| 407 |
template: ansible_test_template |
| 408 |
uuid: "{{ query_one_name.current.uuid }}" |
| 409 |
state: absent |
| 410 |
""" |
| 411 |
|
| 412 |
RETURN = r""" |
| 413 |
""" |
| 414 |
|
| 415 |
|
| 416 |
from ansible.module_utils.basic import AnsibleModule |
| 417 |
from ansible_collections.cisco.mso.plugins.module_utils.mso import MSOModule, mso_argument_spec |
| 418 |
from ansible_collections.cisco.mso.plugins.module_utils.template import MSOTemplate, KVPair |
| 419 |
from ansible_collections.cisco.mso.plugins.module_utils.constants import ( |
| 420 |
PORT_CHANNEL_MODE_MAP, |
| 421 |
CONTROL_MAP, |
| 422 |
LINK_LEVEL_FEC_MAP, |
| 423 |
L2_INTERFACE_QINQ_MAP, |
| 424 |
LOAD_BALANCE_HASHING_MAP, |
| 425 |
) |
| 426 |
import copy |
| 427 |
|
| 428 |
|
| 429 |
def main(): |
| 430 |
argument_spec = mso_argument_spec() |
| 431 |
argument_spec.update( |
| 432 |
dict( |
| 433 |
template=dict(type="str", required=True), |
| 434 |
name=dict(type="str", aliases=["interface_policy_group", "interface_setting"]), |
| 435 |
uuid=dict(type="str", aliases=["interface_policy_group_uuid", "interface_setting_uuid"]), |
| 436 |
description=dict(type="str"), |
| 437 |
interface_type=dict(type="str", choices=["physical", "port_channel"]), |
| 438 |
speed=dict(type="str", choices=["100M", "1G", "10G", "25G", "40G", "50G", "100G", "200G", "400G", "inherit"]), |
| 439 |
auto_negotiation=dict(type="str", choices=["on", "off", "on_enforce"]), |
| 440 |
vlan_scope=dict(type="str", choices=["global", "port_local"]), |
| 441 |
cdp_admin_state=dict(type="str", choices=["enabled", "disabled"]), |
| 442 |
lldp=dict( |
| 443 |
type="dict", |
| 444 |
options=dict( |
| 445 |
status=dict(type="str", choices=["enabled", "disabled"]), |
| 446 |
transmit_state=dict(type="str", choices=["enabled", "disabled"]), |
| 447 |
receive_state=dict(type="str", choices=["enabled", "disabled"]), |
| 448 |
), |
| 449 |
), |
| 450 |
domains=dict(type="list", elements="str"), |
| 451 |
port_channel_mode=dict(type="str", choices=list(PORT_CHANNEL_MODE_MAP)), |
| 452 |
min_links=dict(type="int"), |
| 453 |
max_links=dict(type="int"), |
| 454 |
controls=dict(type="list", elements="str", choices=list(CONTROL_MAP)), |
| 455 |
load_balance_hashing=dict(type="str", choices=list(LOAD_BALANCE_HASHING_MAP)), |
| 456 |
synce=dict(type="str"), |
| 457 |
link_level_debounce_interval=dict(type="int"), |
| 458 |
link_level_bring_up_delay=dict(type="int"), |
| 459 |
link_level_fec=dict(type="str", choices=list(LINK_LEVEL_FEC_MAP)), |
| 460 |
l2_interface_qinq=dict(type="str", choices=list(L2_INTERFACE_QINQ_MAP)), |
| 461 |
l2_interface_reflective_relay=dict(type="str", choices=["enabled", "disabled"]), |
| 462 |
stp_bpdu_filter=dict(type="str", choices=["enabled", "disabled"]), |
| 463 |
stp_bpdu_guard=dict(type="str", choices=["enabled", "disabled"]), |
| 464 |
llfc_transmit_state=dict(type="str", choices=["enabled", "disabled"]), |
| 465 |
llfc_receive_state=dict(type="str", choices=["enabled", "disabled"]), |
| 466 |
mcp=dict( |
| 467 |
type="dict", |
| 468 |
options=dict( |
| 469 |
admin_state=dict(type="str", choices=["enabled", "disabled"]), |
| 470 |
strict_mode=dict(type="str", choices=["on", "off"], aliases=["mcp_mode"]), |
| 471 |
initial_delay_time=dict(type="int"), |
| 472 |
transmission_frequency_sec=dict(type="int"), |
| 473 |
transmission_frequency_msec=dict(type="int"), |
| 474 |
grace_period_sec=dict(type="int"), |
| 475 |
grace_period_msec=dict(type="int"), |
| 476 |
), |
| 477 |
), |
| 478 |
pfc_admin_state=dict(type="str", choices=["on", "off", "auto"]), |
| 479 |
access_macsec_policy=dict(type="str"), |
| 480 |
state=dict(type="str", choices=["absent", "query", "present"], default="query"), |
| 481 |
) |
| 482 |
) |
| 483 |
|
| 484 |
module = AnsibleModule( |
| 485 |
argument_spec=argument_spec, |
| 486 |
supports_check_mode=True, |
| 487 |
required_if=[ |
| 488 |
["state", "present", ["name", "uuid"], True], |
| 489 |
["state", "absent", ["name", "uuid"], True], |
| 490 |
], |
| 491 |
) |
| 492 |
|
| 493 |
mso = MSOModule(module) |
| 494 |
|
| 495 |
template = module.params.get("template") |
| 496 |
name = module.params.get("name") |
| 497 |
uuid = module.params.get("uuid") |
| 498 |
description = module.params.get("description") |
| 499 |
interface_type = module.params.get("interface_type") |
| 500 |
if interface_type == "port_channel": |
| 501 |
interface_type = "portchannel" |
| 502 |
speed = module.params.get("speed") |
| 503 |
auto_negotiation = module.params.get("auto_negotiation") |
| 504 |
if auto_negotiation == "on_enforce": |
| 505 |
auto_negotiation = "on-enforce" |
| 506 |
vlan_scope = module.params.get("vlan_scope") |
| 507 |
if vlan_scope == "port_local": |
| 508 |
vlan_scope = "portlocal" |
| 509 |
cdp_admin_state = module.params.get("cdp_admin_state") |
| 510 |
lldp = module.params.get("lldp") |
| 511 |
domains = module.params.get("domains") |
| 512 |
port_channel_mode = PORT_CHANNEL_MODE_MAP.get(module.params.get("port_channel_mode")) |
| 513 |
min_links = module.params.get("min_links") |
| 514 |
max_links = module.params.get("max_links") |
| 515 |
controls = module.params.get("controls") |
| 516 |
if controls: |
| 517 |
controls = [CONTROL_MAP.get(v) for v in controls] |
| 518 |
load_balance_hashing = LOAD_BALANCE_HASHING_MAP.get(module.params.get("load_balance_hashing")) |
| 519 |
synce = module.params.get("synce") |
| 520 |
link_level_debounce_interval = module.params.get("link_level_debounce_interval") |
| 521 |
link_level_bring_up_delay = module.params.get("link_level_bring_up_delay") |
| 522 |
link_level_fec = LINK_LEVEL_FEC_MAP.get(module.params.get("link_level_fec")) |
| 523 |
l2_interface_qinq = L2_INTERFACE_QINQ_MAP.get(module.params.get("l2_interface_qinq")) |
| 524 |
l2_interface_reflective_relay = module.params.get("l2_interface_reflective_relay") |
| 525 |
stp_bpdu_filter = module.params.get("stp_bpdu_filter") |
| 526 |
stp_bpdu_guard = module.params.get("stp_bpdu_guard") |
| 527 |
llfc_transmit_state = module.params.get("llfc_transmit_state") |
| 528 |
llfc_receive_state = module.params.get("llfc_receive_state") |
| 529 |
mcp = module.params.get("mcp") |
| 530 |
pfc_admin_state = module.params.get("pfc_admin_state") |
| 531 |
access_macsec_policy = module.params.get("access_macsec_policy") |
| 532 |
state = module.params.get("state") |
| 533 |
|
| 534 |
ops = [] |
| 535 |
match = None |
| 536 |
interface_path = None |
| 537 |
|
| 538 |
mso_template = MSOTemplate(mso, "fabric_policy", template) |
| 539 |
mso_template.validate_template("fabricPolicy") |
| 540 |
|
| 541 |
object_description = "Interface Policy Groups" |
| 542 |
|
| 543 |
template_info = mso_template.template.get("fabricPolicyTemplate", {}).get("template", {}) |
| 544 |
|
| 545 |
existing_interface_policies = template_info.get("interfacePolicyGroups", []) |
| 546 |
|
| 547 |
if state in ["query", "absent"] and existing_interface_policies == []: |
| 548 |
mso.exit_json() |
| 549 |
elif state == "query" and not (name or uuid): |
| 550 |
for interface in existing_interface_policies: |
| 551 |
map_interface_settings_ref_name(mso_template, template_info, interface, "uuid") |
| 552 |
mso.existing = existing_interface_policies |
| 553 |
elif existing_interface_policies and (name or uuid): |
| 554 |
match = mso_template.get_object_by_key_value_pairs( |
| 555 |
object_description, existing_interface_policies, [KVPair("uuid", uuid) if uuid else KVPair("name", name)] |
| 556 |
) |
| 557 |
if match: |
| 558 |
interface_path = "/fabricPolicyTemplate/template/interfacePolicyGroups/{0}".format(match.index) |
| 559 |
mso.existing = mso.previous = copy.deepcopy(map_interface_settings_ref_name(mso_template, template_info, match.details, "uuid")) |
| 560 |
|
| 561 |
if state == "present": |
| 562 |
if uuid and not mso.existing: |
| 563 |
mso.fail_json(msg="{0} with the UUID: '{1}' not found".format(object_description, uuid)) |
| 564 |
|
| 565 |
if mso.existing and match: |
| 566 |
proposed_payload = copy.deepcopy(match.details) |
| 567 |
|
| 568 |
if name and mso.existing.get("name") != name: |
| 569 |
ops.append(dict(op="replace", path=interface_path + "/name", value=name)) |
| 570 |
proposed_payload["name"] = name |
| 571 |
|
| 572 |
if description is not None and mso.existing.get("description") != description: |
| 573 |
ops.append(dict(op="replace", path=interface_path + "/description", value=description)) |
| 574 |
proposed_payload["description"] = description |
| 575 |
|
| 576 |
if interface_type and mso.existing.get("type") != interface_type: |
| 577 |
mso.fail_json(msg="Interface type cannot be changed.") |
| 578 |
|
| 579 |
if domains == []: |
| 580 |
ops.append(dict(op="remove", path=interface_path + "/domains")) |
| 581 |
proposed_payload.pop("domains", None) |
| 582 |
elif domains: |
| 583 |
domain_uuid_list, domain_uuid_name_list = validate_domains(mso, domains, template, template_info) |
| 584 |
if set(domain_uuid_list) != set(mso.existing.get("domains", [])): |
| 585 |
ops.append(dict(op="replace", path=interface_path + "/domains", value=domain_uuid_list)) |
| 586 |
proposed_payload["domains"] = domain_uuid_list |
| 587 |
|
| 588 |
if synce: |
| 589 |
existing_sync_e = validate_sync_e(mso, synce, template, template_info) |
| 590 |
if existing_sync_e[synce] != mso.existing.get("syncEthPolicy"): |
| 591 |
ops.append(dict(op="replace", path=interface_path + "/syncEthPolicy", value=existing_sync_e[synce])) |
| 592 |
proposed_payload["syncEthPolicy"] = existing_sync_e[synce] |
| 593 |
|
| 594 |
if access_macsec_policy: |
| 595 |
existing_access_macsec_policy = validate_macsec_policy(mso, access_macsec_policy, template, template_info) |
| 596 |
if existing_access_macsec_policy[access_macsec_policy] != mso.existing.get("accessMACsecPolicy"): |
| 597 |
ops.append(dict(op="replace", path=interface_path + "/accessMACsecPolicy", value=existing_access_macsec_policy[access_macsec_policy])) |
| 598 |
proposed_payload["accessMACsecPolicy"] = existing_access_macsec_policy[access_macsec_policy] |
| 599 |
|
| 600 |
if cdp_admin_state and mso.existing.get("cdp", {}).get("adminState") != cdp_admin_state: |
| 601 |
ops.append(dict(op="replace", path=interface_path + "/cdp/adminState", value=cdp_admin_state)) |
| 602 |
proposed_payload["cdp"]["adminState"] = cdp_admin_state |
| 603 |
|
| 604 |
if pfc_admin_state and mso.existing.get("pfc", {}).get("adminState") != pfc_admin_state: |
| 605 |
ops.append(dict(op="replace", path=interface_path + "/pfc/adminState", value=pfc_admin_state)) |
| 606 |
proposed_payload["pfc"]["adminState"] = pfc_admin_state |
| 607 |
|
| 608 |
if llfc_transmit_state and mso.existing.get("llfc", {}).get("transmitState") != llfc_transmit_state: |
| 609 |
ops.append(dict(op="replace", path=interface_path + "/llfc/transmitState", value=llfc_transmit_state)) |
| 610 |
proposed_payload["llfc"]["transmitState"] = llfc_transmit_state |
| 611 |
|
| 612 |
if llfc_receive_state and mso.existing.get("llfc", {}).get("receiveState") != llfc_receive_state: |
| 613 |
ops.append(dict(op="replace", path=interface_path + "/llfc/receiveState", value=llfc_receive_state)) |
| 614 |
proposed_payload["llfc"]["receiveState"] = llfc_receive_state |
| 615 |
|
| 616 |
if stp_bpdu_filter and mso.existing.get("stp", {}).get("bpduFilterEnabled") != stp_bpdu_filter: |
| 617 |
ops.append(dict(op="replace", path=interface_path + "/stp/bpduFilterEnabled", value=stp_bpdu_filter)) |
| 618 |
proposed_payload["stp"]["bpduFilterEnabled"] = stp_bpdu_filter |
| 619 |
|
| 620 |
if stp_bpdu_guard and mso.existing.get("stp", {}).get("bpduGuardEnabled") != stp_bpdu_guard: |
| 621 |
ops.append(dict(op="replace", path=interface_path + "/stp/bpduGuardEnabled", value=stp_bpdu_guard)) |
| 622 |
proposed_payload["stp"]["bpduGuardEnabled"] = stp_bpdu_guard |
| 623 |
|
| 624 |
if l2_interface_qinq and mso.existing.get("l2Interface", {}).get("qinq") != l2_interface_qinq: |
| 625 |
ops.append(dict(op="replace", path=interface_path + "/l2Interface/qinq", value=l2_interface_qinq)) |
| 626 |
proposed_payload["l2Interface"]["qinq"] = l2_interface_qinq |
| 627 |
|
| 628 |
if l2_interface_reflective_relay and mso.existing.get("l2Interface", {}).get("reflectiveRelay") != l2_interface_reflective_relay: |
| 629 |
ops.append(dict(op="replace", path=interface_path + "/l2Interface/reflectiveRelay", value=l2_interface_reflective_relay)) |
| 630 |
proposed_payload["l2Interface"]["reflectiveRelay"] = l2_interface_reflective_relay |
| 631 |
|
| 632 |
if vlan_scope and mso.existing.get("l2Interface", {}).get("vlanScope") != vlan_scope: |
| 633 |
ops.append(dict(op="replace", path=interface_path + "/l2Interface/vlanScope", value=vlan_scope)) |
| 634 |
proposed_payload["l2Interface"]["vlanScope"] = vlan_scope |
| 635 |
|
| 636 |
if lldp: |
| 637 |
validate_lldp(mso, lldp) |
| 638 |
if lldp["receive_state"] and mso.existing.get("lldp", {}).get("receiveState") != lldp["receive_state"]: |
| 639 |
ops.append(dict(op="replace", path=interface_path + "/lldp/receiveState", value=lldp["receive_state"])) |
| 640 |
proposed_payload["lldp"]["receiveState"] = lldp["receive_state"] |
| 641 |
if lldp["transmit_state"] and mso.existing.get("lldp", {}).get("transmitState") != lldp["transmit_state"]: |
| 642 |
ops.append(dict(op="replace", path=interface_path + "/lldp/transmitState", value=lldp["transmit_state"])) |
| 643 |
proposed_payload["lldp"]["transmitState"] = lldp["transmit_state"] |
| 644 |
|
| 645 |
if link_level_debounce_interval and mso.existing.get("linkLevel", {}).get("debounceInterval") != link_level_debounce_interval: |
| 646 |
ops.append(dict(op="replace", path=interface_path + "/linkLevel/debounceInterval", value=link_level_debounce_interval)) |
| 647 |
proposed_payload["linkLevel"]["debounceInterval"] = link_level_debounce_interval |
| 648 |
|
| 649 |
if link_level_bring_up_delay and mso.existing.get("linkLevel", {}).get("bringUpDelay") != link_level_bring_up_delay: |
| 650 |
ops.append(dict(op="replace", path=interface_path + "/linkLevel/bringUpDelay", value=link_level_bring_up_delay)) |
| 651 |
proposed_payload["linkLevel"]["bringUpDelay"] = link_level_bring_up_delay |
| 652 |
|
| 653 |
if link_level_fec and mso.existing.get("linkLevel", {}).get("fec") != link_level_fec: |
| 654 |
ops.append(dict(op="replace", path=interface_path + "/linkLevel/fec", value=link_level_fec)) |
| 655 |
proposed_payload["linkLevel"]["fec"] = link_level_fec |
| 656 |
|
| 657 |
if speed and mso.existing.get("linkLevel", {}).get("speed") != speed: |
| 658 |
ops.append(dict(op="replace", path=interface_path + "/linkLevel/speed", value=speed)) |
| 659 |
proposed_payload["linkLevel"]["speed"] = speed |
| 660 |
|
| 661 |
if auto_negotiation and mso.existing.get("linkLevel", {}).get("autoNegotiation") != auto_negotiation: |
| 662 |
ops.append(dict(op="replace", path=interface_path + "/linkLevel/autoNegotiation", value=auto_negotiation)) |
| 663 |
proposed_payload["linkLevel"]["autoNegotiation"] = auto_negotiation |
| 664 |
|
| 665 |
if mcp: |
| 666 |
if mcp["admin_state"] and mso.existing.get("mcp", {}).get("adminState") != mcp["admin_state"]: |
| 667 |
ops.append(dict(op="replace", path=interface_path + "/mcp/adminState", value=mcp["admin_state"])) |
| 668 |
proposed_payload["mcp"]["adminState"] = mcp["admin_state"] |
| 669 |
if mcp["strict_mode"] and mso.existing.get("mcp", {}).get("mcpMode") != mcp["strict_mode"]: |
| 670 |
ops.append(dict(op="replace", path=interface_path + "/mcp/mcpMode", value=mcp["strict_mode"])) |
| 671 |
proposed_payload["mcp"]["mcpMode"] = mcp["strict_mode"] |
| 672 |
if mcp["initial_delay_time"] and mso.existing.get("mcp", {}).get("initialDelayTime") != mcp["initial_delay_time"]: |
| 673 |
ops.append(dict(op="replace", path=interface_path + "/mcp/initialDelayTime", value=mcp["initial_delay_time"])) |
| 674 |
proposed_payload["mcp"]["initialDelayTime"] = mcp["initial_delay_time"] |
| 675 |
if mcp["transmission_frequency_sec"] and mso.existing.get("mcp", {}).get("txFreq") != mcp["transmission_frequency_sec"]: |
| 676 |
ops.append(dict(op="replace", path=interface_path + "/mcp/txFreq", value=mcp["transmission_frequency_sec"])) |
| 677 |
proposed_payload["mcp"]["txFreq"] = mcp["transmission_frequency_sec"] |
| 678 |
if mcp["transmission_frequency_msec"] and mso.existing.get("mcp", {}).get("txFreqMsec") != mcp["transmission_frequency_msec"]: |
| 679 |
ops.append(dict(op="replace", path=interface_path + "/mcp/txFreqMsec", value=mcp["transmission_frequency_msec"])) |
| 680 |
proposed_payload["mcp"]["txFreqMsec"] = mcp["transmission_frequency_msec"] |
| 681 |
if mcp["grace_period_sec"] and mso.existing.get("mcp", {}).get("gracePeriod") != mcp["grace_period_sec"]: |
| 682 |
ops.append(dict(op="replace", path=interface_path + "/mcp/gracePeriod", value=mcp["grace_period_sec"])) |
| 683 |
proposed_payload["mcp"]["gracePeriod"] = mcp["grace_period_sec"] |
| 684 |
if mcp["grace_period_msec"] and mso.existing.get("mcp", {}).get("gracePeriodMsec") != mcp["grace_period_msec"]: |
| 685 |
ops.append(dict(op="replace", path=interface_path + "/mcp/gracePeriodMsec", value=mcp["grace_period_msec"])) |
| 686 |
proposed_payload["mcp"]["gracePeriodMsec"] = mcp["grace_period_msec"] |
| 687 |
|
| 688 |
if port_channel_mode and mso.existing.get("portChannelPolicy", {}).get("mode") != port_channel_mode: |
| 689 |
ops.append(dict(op="replace", path=interface_path + "/portChannelPolicy/mode", value=port_channel_mode)) |
| 690 |
proposed_payload["portChannelPolicy"]["mode"] = port_channel_mode |
| 691 |
|
| 692 |
if min_links and mso.existing.get("portChannelPolicy", {}).get("minLinks") != min_links: |
| 693 |
ops.append(dict(op="replace", path=interface_path + "/portChannelPolicy/minLinks", value=min_links)) |
| 694 |
proposed_payload["portChannelPolicy"]["minLinks"] = min_links |
| 695 |
|
| 696 |
if max_links and mso.existing.get("portChannelPolicy", {}).get("maxLinks") != max_links: |
| 697 |
ops.append(dict(op="replace", path=interface_path + "/portChannelPolicy/maxLinks", value=max_links)) |
| 698 |
proposed_payload["portChannelPolicy"]["maxLinks"] = max_links |
| 699 |
|
| 700 |
if load_balance_hashing and mso.existing.get("portChannelPolicy", {}).get("hashFields") != load_balance_hashing: |
| 701 |
ops.append(dict(op="replace", path=interface_path + "/portChannelPolicy/hashFields", value=load_balance_hashing)) |
| 702 |
proposed_payload["portChannelPolicy"]["hashFields"] = load_balance_hashing |
| 703 |
|
| 704 |
if controls and mso.existing.get("portChannelPolicy", {}).get("control") != controls: |
| 705 |
ops.append(dict(op="replace", path=interface_path + "/portChannelPolicy/control", value=controls)) |
| 706 |
proposed_payload["portChannelPolicy"]["control"] = controls |
| 707 |
elif controls == []: |
| 708 |
ops.append(dict(op="remove", path=interface_path + "/portChannelPolicy/control")) |
| 709 |
mso.existing.pop("controls", None) |
| 710 |
|
| 711 |
mso.sanitize(map_interface_settings_ref_name(mso_template, template_info, proposed_payload, "uuid"), collate=True) |
| 712 |
|
| 713 |
else: |
| 714 |
if not interface_type: |
| 715 |
mso.fail_json(msg="Error: Missing required argument 'interface_type' for creating an Interface Policy Group.") |
| 716 |
payload = { |
| 717 |
"name": name, |
| 718 |
"type": interface_type, |
| 719 |
"templateId": mso_template.template.get("templateId"), |
| 720 |
"schemaId": mso_template.template.get("schemaId"), |
| 721 |
"llfc": {}, |
| 722 |
"stp": {}, |
| 723 |
"l2Interface": {}, |
| 724 |
"lldp": {}, |
| 725 |
"linkLevel": {}, |
| 726 |
"mcp": {}, |
| 727 |
"portChannelPolicy": {}, |
| 728 |
} |
| 729 |
|
| 730 |
if description: |
| 731 |
payload["description"] = description |
| 732 |
|
| 733 |
if domains: |
| 734 |
payload["domains"], domain_uuid_name_list = validate_domains(mso, domains, template, template_info) |
| 735 |
|
| 736 |
if synce: |
| 737 |
existing_sync_e = validate_sync_e(mso, synce, template, template_info) |
| 738 |
payload["syncEthPolicy"] = existing_sync_e[synce] |
| 739 |
|
| 740 |
if access_macsec_policy: |
| 741 |
existing_access_macsec_policy = validate_macsec_policy(mso, access_macsec_policy, template, template_info) |
| 742 |
payload["accessMACsecPolicy"] = existing_access_macsec_policy[access_macsec_policy] |
| 743 |
|
| 744 |
if cdp_admin_state: |
| 745 |
payload["cdp"] = {"adminState": cdp_admin_state} |
| 746 |
|
| 747 |
if pfc_admin_state: |
| 748 |
payload["pfc"] = {"adminState": pfc_admin_state} |
| 749 |
|
| 750 |
if llfc_transmit_state: |
| 751 |
payload["llfc"]["transmitState"] = llfc_transmit_state |
| 752 |
if llfc_receive_state: |
| 753 |
payload["llfc"]["receiveState"] = llfc_receive_state |
| 754 |
|
| 755 |
if stp_bpdu_filter: |
| 756 |
payload["stp"]["bpduFilterEnabled"] = stp_bpdu_filter |
| 757 |
if stp_bpdu_guard: |
| 758 |
payload["stp"]["bpduGuardEnabled"] = stp_bpdu_guard |
| 759 |
|
| 760 |
if l2_interface_qinq: |
| 761 |
payload["l2Interface"]["qinq"] = l2_interface_qinq |
| 762 |
if l2_interface_reflective_relay: |
| 763 |
payload["l2Interface"]["reflectiveRelay"] = l2_interface_reflective_relay |
| 764 |
if vlan_scope: |
| 765 |
payload["l2Interface"]["vlanScope"] = vlan_scope |
| 766 |
|
| 767 |
if lldp: |
| 768 |
validate_lldp(mso, lldp) |
| 769 |
payload["lldp"]["receiveState"] = lldp["receive_state"] |
| 770 |
payload["lldp"]["transmitState"] = lldp["transmit_state"] |
| 771 |
|
| 772 |
if link_level_debounce_interval: |
| 773 |
payload["linkLevel"]["debounceInterval"] = link_level_debounce_interval |
| 774 |
if link_level_bring_up_delay: |
| 775 |
payload["linkLevel"]["bringUpDelay"] = link_level_bring_up_delay |
| 776 |
if link_level_fec: |
| 777 |
payload["linkLevel"]["fec"] = link_level_fec |
| 778 |
if speed: |
| 779 |
payload["linkLevel"]["speed"] = speed |
| 780 |
if auto_negotiation: |
| 781 |
payload["linkLevel"]["autoNegotiation"] = auto_negotiation |
| 782 |
|
| 783 |
if mcp: |
| 784 |
if mcp["admin_state"]: |
| 785 |
payload["mcp"]["adminState"] = mcp["admin_state"] |
| 786 |
if mcp["strict_mode"]: |
| 787 |
payload["mcp"]["mcpMode"] = mcp["strict_mode"] |
| 788 |
if mcp["initial_delay_time"]: |
| 789 |
payload["mcp"]["initialDelayTime"] = mcp["initial_delay_time"] |
| 790 |
if mcp["transmission_frequency_sec"]: |
| 791 |
payload["mcp"]["txFreq"] = mcp["transmission_frequency_sec"] |
| 792 |
if mcp["transmission_frequency_msec"]: |
| 793 |
payload["mcp"]["txFreqMsec"] = mcp["transmission_frequency_msec"] |
| 794 |
if mcp["grace_period_sec"]: |
| 795 |
payload["mcp"]["gracePeriod"] = mcp["grace_period_sec"] |
| 796 |
if mcp["grace_period_msec"]: |
| 797 |
payload["mcp"]["gracePeriodMsec"] = mcp["grace_period_msec"] |
| 798 |
|
| 799 |
if port_channel_mode: |
| 800 |
payload["portChannelPolicy"]["mode"] = port_channel_mode |
| 801 |
if min_links: |
| 802 |
payload["portChannelPolicy"]["minLinks"] = min_links |
| 803 |
if max_links: |
| 804 |
payload["portChannelPolicy"]["maxLinks"] = max_links |
| 805 |
if load_balance_hashing: |
| 806 |
payload["portChannelPolicy"]["hashFields"] = load_balance_hashing |
| 807 |
if controls: |
| 808 |
payload["portChannelPolicy"]["control"] = controls |
| 809 |
|
| 810 |
ops.append(dict(op="add", path="/fabricPolicyTemplate/template/interfacePolicyGroups/-", value=copy.deepcopy(payload))) |
| 811 |
mso.sanitize(map_interface_settings_ref_name(mso_template, template_info, payload, "uuid")) |
| 812 |
|
| 813 |
mso.existing = mso.proposed |
| 814 |
|
| 815 |
elif state == "absent": |
| 816 |
if match: |
| 817 |
ops.append(dict(op="remove", path=interface_path)) |
| 818 |
|
| 819 |
if not module.check_mode and ops: |
| 820 |
response = mso.request(mso_template.template_path, method="PATCH", data=ops) |
| 821 |
interface_policies = response.get("fabricPolicyTemplate", {}).get("template", {}).get("interfacePolicyGroups", []) |
| 822 |
match = mso_template.get_object_by_key_value_pairs(object_description, interface_policies, [KVPair("uuid", uuid) if uuid else KVPair("name", name)]) |
| 823 |
if match: |
| 824 |
mso.existing = map_interface_settings_ref_name(mso_template, template_info, match.details, "uuid") # When the state is present |
| 825 |
else: |
| 826 |
mso.existing = {} # When the state is absent |
| 827 |
elif module.check_mode and state != "query": # When the state is present/absent with check mode |
| 828 |
mso.existing = map_interface_settings_ref_name(mso_template, template_info, mso.proposed, "uuid") if state == "present" else {} |
| 829 |
|
| 830 |
mso.exit_json() |
| 831 |
|
| 832 |
|
| 833 |
def map_interface_settings_ref_name(mso_template, template_info, interface_settings, domain_input_type="name"): |
| 834 |
if interface_settings.get("accessMACsecPolicy"): |
| 835 |
interface_settings["accessMACsecPolicyName"] = validate_macsec_policy( |
| 836 |
mso_template.mso, interface_settings.get("accessMACsecPolicy"), mso_template, template_info |
| 837 |
).get(interface_settings["accessMACsecPolicy"]) |
| 838 |
|
| 839 |
if interface_settings.get("syncEthPolicy"): |
| 840 |
interface_settings["syncEthPolicyName"] = validate_sync_e(mso_template.mso, interface_settings.get("syncEthPolicy"), mso_template, template_info).get( |
| 841 |
interface_settings["syncEthPolicy"] |
| 842 |
) |
| 843 |
|
| 844 |
if interface_settings.get("domains"): |
| 845 |
domain_uuid_list, interface_settings["domainsName"] = validate_domains( |
| 846 |
mso_template.mso, interface_settings.get("domains"), mso_template.template_name, template_info, domain_input_type |
| 847 |
) |
| 848 |
return interface_settings |
| 849 |
|
| 850 |
|
| 851 |
def validate_domains(mso, domains, template, template_info, input_type="name"): |
| 852 |
domain_uuid_list = [] |
| 853 |
domain_uuid_name_list = dict() |
| 854 |
# Combine physical and L3 domains into a single dictionary |
| 855 |
existing_domains = dict() |
| 856 |
|
| 857 |
for domain in template_info.get("domains", []): |
| 858 |
existing_domains[domain["name"]] = domain["uuid"] |
| 859 |
existing_domains[domain["uuid"]] = domain["name"] |
| 860 |
|
| 861 |
for domain in template_info.get("l3Domains", []): |
| 862 |
existing_domains[domain["name"]] = domain["uuid"] |
| 863 |
existing_domains[domain["uuid"]] = domain["name"] |
| 864 |
|
| 865 |
for domain in domains: |
| 866 |
if domain in existing_domains: |
| 867 |
if input_type == "name": |
| 868 |
domain_uuid_list.append(existing_domains[domain]) |
| 869 |
domain_uuid_name_list[domain] = existing_domains[domain] |
| 870 |
else: |
| 871 |
domain_uuid_list.append(domain) |
| 872 |
domain_uuid_name_list[existing_domains[domain]] = domain |
| 873 |
else: |
| 874 |
mso.fail_json(msg="Domain '{0}' not found in the template '{1}'.".format(domain, template)) |
| 875 |
return domain_uuid_list, domain_uuid_name_list |
| 876 |
|
| 877 |
|
| 878 |
def validate_macsec_policy(mso, access_macsec_policy, template, template_info): |
| 879 |
existing_access_macsec_policy = dict() |
| 880 |
for macsec_policy in template_info.get("macsecPolicies", []): |
| 881 |
existing_access_macsec_policy[macsec_policy["name"]] = macsec_policy["uuid"] |
| 882 |
existing_access_macsec_policy[macsec_policy["uuid"]] = macsec_policy["name"] |
| 883 |
if access_macsec_policy not in existing_access_macsec_policy: |
| 884 |
mso.fail_json(msg="Access MACsec policy '{0}' not found in the template '{1}'.".format(access_macsec_policy, template)) |
| 885 |
return existing_access_macsec_policy |
| 886 |
|
| 887 |
|
| 888 |
def validate_sync_e(mso, synce, template, template_info): |
| 889 |
existing_sync_e = dict() |
| 890 |
for synceth_intf_policy in template_info.get("syncEthIntfPolicies", []): |
| 891 |
existing_sync_e[synceth_intf_policy["name"]] = synceth_intf_policy["uuid"] |
| 892 |
existing_sync_e[synceth_intf_policy["uuid"]] = synceth_intf_policy["name"] |
| 893 |
if synce not in existing_sync_e: |
| 894 |
mso.fail_json(msg="SyncE policy '{0}' not found in the template '{1}'.".format(synce, template)) |
| 895 |
return existing_sync_e |
| 896 |
|
| 897 |
|
| 898 |
def validate_lldp(mso, lldp): |
| 899 |
if lldp["status"] == "disabled" and not (lldp["receive_state"] == "disabled" and lldp["transmit_state"] == "disabled"): |
| 900 |
mso.fail_json(msg="LLDP receive_state and transmit_state must be 'disabled' when LLDP status is disabled.") |
| 901 |
|
| 902 |
|
| 903 |
if __name__ == "__main__": |
| 904 |
main() |