| 1 |
from jnpr.junos.exception import ConnectNotMasterError |
| 2 |
from jnpr.junos.exception import RpcError |
| 3 |
|
| 4 |
|
| 5 |
def facts_chassis(junos, facts): |
| 6 |
""" |
| 7 |
The following facts are assigned: |
| 8 |
facts['2RE'] : designates if the device can support two RE, not that it |
| 9 |
has them |
| 10 |
facts['RE_hw_mi'] : designates if the device is |
| 11 |
multi-instance-routing-engine |
| 12 |
facts['model'] : product model |
| 13 |
facts['serialnumber'] : serial number |
| 14 |
|
| 15 |
NOTES: |
| 16 |
(1) if in a 2RE system, this routine will only load the information |
| 17 |
from the first chassis item. |
| 18 |
(2) hostname, domain, and fqdn are retrieved from configuration data; |
| 19 |
inherited configs are checked. |
| 20 |
""" |
| 21 |
# Set default values. |
| 22 |
facts["2RE"] = False |
| 23 |
facts["RE_hw_mi"] = False |
| 24 |
facts["model"] = "UNKNOWN" |
| 25 |
facts["serialnumber"] = "UNKNOWN" |
| 26 |
|
| 27 |
rsp = junos.rpc.get_chassis_inventory() |
| 28 |
if rsp.tag == "error": |
| 29 |
raise RuntimeError() |
| 30 |
|
| 31 |
if rsp.tag == "output": |
| 32 |
# this means that there was an error; due to the |
| 33 |
# fact that this connection is not on the master |
| 34 |
# @@@ need to validate on VC-member |
| 35 |
raise ConnectNotMasterError(junos) |
| 36 |
|
| 37 |
if rsp.tag == "multi-routing-engine-results": |
| 38 |
facts["2RE"] = True |
| 39 |
facts["RE_hw_mi"] = True |
| 40 |
else: |
| 41 |
facts["2RE"] = False |
| 42 |
|
| 43 |
facts["model"] = rsp.findtext(".//chassis[1]/description", "UNKNOWN") |
| 44 |
facts["serialnumber"] = ( |
| 45 |
rsp.findtext(".//chassis[1]/serial-number") |
| 46 |
or rsp.findtext('.//chassis-module[name="Backplane"]/serial-number') |
| 47 |
or rsp.findtext('.//chassis-module[name="Midplane"]/serial-number', "UNKNOWN") |
| 48 |
) |
| 49 |
|
| 50 |
if facts["model"] == "UNKNOWN" or facts["serialnumber"] == "UNKNOWN": |
| 51 |
raise RpcError() |