| 1 |
from jnpr.junos.exception import ConnectNotMasterError |
| 2 |
from jnpr.junos.exception import RpcError |
| 3 |
|
| 4 |
|
| 5 |
def provides_facts(): |
| 6 |
""" |
| 7 |
Returns a dictionary keyed on the facts provided by this module. The value |
| 8 |
of each key is the doc string describing the fact. |
| 9 |
""" |
| 10 |
return { |
| 11 |
"RE_hw_mi": "(Routing Engine hardware multi-instance) A boolean " |
| 12 |
"indicating if this is a multi-chassis system.", |
| 13 |
"serialnumber": "A string containing the serial number of the " |
| 14 |
"device's chassis. If there is no chassis serial " |
| 15 |
"number, the serial number of the backplane or " |
| 16 |
"midplane is returned.", |
| 17 |
} |
| 18 |
|
| 19 |
|
| 20 |
def get_facts(device): |
| 21 |
""" |
| 22 |
Gathers facts from the <get-chassis-inventory/> RPC. |
| 23 |
""" |
| 24 |
rsp = device.rpc.get_chassis_inventory(normalize=True) |
| 25 |
if rsp.tag == "error": |
| 26 |
raise RpcError() |
| 27 |
|
| 28 |
if ( |
| 29 |
rsp.tag == "output" |
| 30 |
and rsp.text.find("can only be used on the master routing engine") != -1 |
| 31 |
): |
| 32 |
# An error; due to the fact that this RPC can only be executed on the |
| 33 |
# master Routing Engine |
| 34 |
raise ConnectNotMasterError() |
| 35 |
|
| 36 |
RE_hw_mi = False |
| 37 |
if rsp.tag == "multi-routing-engine-results": |
| 38 |
RE_hw_mi = True |
| 39 |
|
| 40 |
serialnumber = ( |
| 41 |
rsp.findtext(".//chassis[1]/serial-number") |
| 42 |
or rsp.findtext('.//chassis-module[name="Backplane"]/serial-number') |
| 43 |
or rsp.findtext('.//chassis-module[name="Midplane"]/serial-number') |
| 44 |
) |
| 45 |
|
| 46 |
return { |
| 47 |
"RE_hw_mi": RE_hw_mi, |
| 48 |
"serialnumber": serialnumber, |
| 49 |
} |