Debian Codegraph @

lib/jnpr/junos/ofacts/srx_cluster.py

raw
1 def facts_srx_cluster(junos, facts):
2 # we should check the 'cluster status' on redundancy group 0 to see who is
3 # master. we use a try/except block for cases when SRX is not clustered
4
5 try:
6 cluster_st = junos.rpc.get_chassis_cluster_status(redundancy_group="0")
7 if "error" == cluster_st.tag:
8 facts["srx_cluster"] = False
9 return
10
11 primary = cluster_st.xpath('.//redundancy-group-status[.="primary"]')[0]
12
13 node = primary.xpath("preceding-sibling::device-name[1]")[0].text.replace(
14 "node", "RE"
15 )
16
17 if not facts.get("master"):
18 facts["master"] = node
19 elif node not in facts["master"]:
20 facts["master"].append(node)
21
22 facts["srx_cluster"] = True
23
24 except:
25 # this device doesn't support SRX chassis clustering; i.e.
26 # since we arbitrarily execute the RPC on all devices, if we
27 # hit this exception we just ignore, A-OK, yo!
28 pass