| 1 |
from jnpr.junos.exception import RpcError |
| 2 |
|
| 3 |
|
| 4 |
def provides_facts(): |
| 5 |
""" |
| 6 |
Returns a dictionary keyed on the facts provided by this module. The value |
| 7 |
of each key is the doc string describing the fact. |
| 8 |
""" |
| 9 |
return { |
| 10 |
"switch_style": "A string which indicates the Ethernet " |
| 11 |
"switching syntax style supported by the device. " |
| 12 |
"Possible values are: 'BRIDGE_DOMAIN', 'VLAN', " |
| 13 |
"'VLAN_L2NG', or 'NONE'.", |
| 14 |
} |
| 15 |
|
| 16 |
|
| 17 |
def get_facts(device): |
| 18 |
""" |
| 19 |
Gathers facts about the Ethernet switching configuration syntax style. |
| 20 |
""" |
| 21 |
switch_style = None |
| 22 |
|
| 23 |
try: |
| 24 |
# RPC if VLAN style (Older EX, QFX, and SRX) |
| 25 |
# or if VLAN_L2NG (aka ELS) style (Newer EX and QFX) |
| 26 |
rsp = device.rpc.get_ethernet_switching_table_information(summary=True) |
| 27 |
if rsp.tag == "l2ng-l2ald-rtb-macdb": |
| 28 |
switch_style = "VLAN_L2NG" |
| 29 |
elif rsp.tag == "ethernet-switching-table-information": |
| 30 |
switch_style = "VLAN" |
| 31 |
except RpcError: |
| 32 |
pass |
| 33 |
|
| 34 |
if switch_style is None: |
| 35 |
try: |
| 36 |
# CLI command for MX style. Using the CLI command instead of the |
| 37 |
# RPC because PTX lies. It returns <l2ald-rtb-mac-count> for the |
| 38 |
# RPC, but doesn't really support bridging. It raises an RPC |
| 39 |
# error for the CLI command (via <command> RPC), so we use |
| 40 |
# the CLI command to make sure the device really does support |
| 41 |
# bridge domains. In this case, an RpcError is raised with a |
| 42 |
# bad_element of 'bridge'. |
| 43 |
# |
| 44 |
# However, on the backup RE for devices that really do support |
| 45 |
# bridge domains, we get an RpcError stating: |
| 46 |
# 'the l2-learning subsystem is not running' |
| 47 |
rsp = device.rpc.cli( |
| 48 |
"show bridge mac-table count", format="xml", normalize=True |
| 49 |
) |
| 50 |
if rsp.tag == "l2ald-rtb-mac-count": |
| 51 |
switch_style = "BRIDGE_DOMAIN" |
| 52 |
else: |
| 53 |
switch_style = "NONE" |
| 54 |
except RpcError as err: |
| 55 |
# Probably a PTX. |
| 56 |
if err.rpc_error["bad_element"] == "bridge": |
| 57 |
switch_style = "NONE" |
| 58 |
# Probably a non-master RE on an MX. |
| 59 |
elif err.rpc_error["message"] == "the l2-learning subsystem is not running": |
| 60 |
switch_style = "BRIDGE_DOMAIN" |
| 61 |
|
| 62 |
return { |
| 63 |
"switch_style": switch_style, |
| 64 |
} |