|
| 1 | +class Rule: |
| 2 | + id = "207" |
| 3 | + description = "Verify fabric replication and spine roles." |
| 4 | + severity = "HIGH" |
| 5 | + |
| 6 | + @classmethod |
| 7 | + def check_role(cls, inventory): |
| 8 | + """ |
| 9 | + Check if any switch in the topology has the role |
| 10 | + 'border_gateway_spine' or 'border_gateway'. |
| 11 | + Returns True if at least one such switch exists, |
| 12 | + otherwise False. |
| 13 | + Also sets a class-level variable with the |
| 14 | + serial_number of the first matching switch. |
| 15 | + """ |
| 16 | + topology = inventory.get("vxlan", {}).get("topology", {}) |
| 17 | + switches = topology.get("switches") |
| 18 | + if not switches: |
| 19 | + return False |
| 20 | + for switch in switches: |
| 21 | + if switch.get("role") in ( |
| 22 | + "border_gateway_spine", "border_gateway" |
| 23 | + ): |
| 24 | + cls.matching_serial_number = switch.get("serial_number") |
| 25 | + cls.matching_role = switch.get("role") |
| 26 | + return True |
| 27 | + return False |
| 28 | + |
| 29 | + @classmethod |
| 30 | + def check_ipv6_underlay(cls, inventory): |
| 31 | + """ |
| 32 | + Check if IPv6 underlay is enabled in the VXLAN configuration. |
| 33 | + Returns True if enabled, otherwise False. |
| 34 | + """ |
| 35 | + return ( |
| 36 | + inventory.get("vxlan", {}) |
| 37 | + .get("underlay", {}) |
| 38 | + .get("general", {}) |
| 39 | + .get("enable_ipv6_underlay") is True |
| 40 | + ) |
| 41 | + |
| 42 | + @classmethod |
| 43 | + def match(cls, inventory): |
| 44 | + """ |
| 45 | + Main validation method. |
| 46 | + Checks if the combination of: |
| 47 | + - border_gateway_spine or border_gateway role present, |
| 48 | + - IPv6 underlay enabled, |
| 49 | + - replication_mode set to 'ingress' |
| 50 | + is present in the inventory. |
| 51 | + If so, appends a descriptive error message to the results list. |
| 52 | + Returns the list of validation errors (empty if none). |
| 53 | + """ |
| 54 | + results = [] |
| 55 | + fabric_replication = False |
| 56 | + border_gateway_role = cls.check_role(inventory) |
| 57 | + ipv6_underlay = cls.check_ipv6_underlay(inventory) |
| 58 | + |
| 59 | + # Retrieve the replication_mode value if present |
| 60 | + if inventory.get("vxlan", None): |
| 61 | + if inventory["vxlan"].get("underlay", None): |
| 62 | + if inventory["vxlan"].get("underlay").get("general", None): |
| 63 | + fabric_replication = ( |
| 64 | + inventory["vxlan"]["underlay"]["general"].get( |
| 65 | + "replication_mode", False |
| 66 | + ) |
| 67 | + ) |
| 68 | + |
| 69 | + # Validate the combination and add an error if the rule is violated |
| 70 | + if border_gateway_role and ipv6_underlay and ( |
| 71 | + fabric_replication == "ingress" |
| 72 | + ): |
| 73 | + results.append( |
| 74 | + f"The switch {cls.matching_serial_number} is set to " |
| 75 | + f"{cls.matching_role} role." |
| 76 | + ) |
| 77 | + results.append( |
| 78 | + "For replication_mode to be set to " |
| 79 | + "ingress and ipv6 underlay enabled, " |
| 80 | + "switches.role must NOT be set to " |
| 81 | + "border_gateway_spine or border_gateway." |
| 82 | + ) |
| 83 | + |
| 84 | + return results |
0 commit comments