Junos Automation (Scripting)
Highlighted
Junos Automation (Scripting)

Node information : primary or secondary

‎01-29-2018 04:51 AM

Hi,

I have been struggling to get the node information (primary or secondary) from the device I am currently logged into. If we run 'show version | display xml' command from cli , it  gives information for both the nodes, along with that  it has a <banner> tag which says its primary:node1 , but how do we get the similar information using pyEZ rpc methods.

 

> show version | display xml

<rpc-reply xmlns:junos="http://xml.juniper.net/junos/12.1X47/junos">
    <multi-routing-engine-results>
        <multi-routing-engine-item>

        <re-name>node0</re-name>

                          ................

                          ................

        </multi-routing-engine-item>
        <multi-routing-engine-item>
            <re-name>node1</re-name>

                          ................

                          ................

        </multi-routing-engine-item>
    </multi-routing-engine-results>
    <cli>
        <banner>{primary:node1}</banner>
    </cli>
</rpc-reply>

 

Thanks in advance,

Prabir

3 REPLIES 3
Highlighted
Junos Automation (Scripting)

Re: Node information : primary or secondary

‎01-29-2018 06:52 AM

Any help would be appreciated on this . Actually,  we have been advised to check cpu idle % by running 'show chassis routing-engine' before running any other commands which generates a huge output such as 'show routes all' or 'show configurations'.  But, show chassis routing-engine shows infomation for both the nodes and I am unable to get node information by any means.

Thanks,

Prabir

Highlighted
Junos Automation (Scripting)

Re: Node information : primary or secondary

‎02-28-2019 12:51 PM

A bit late to the show but, depends on what information you are wanting about the nodes.  For chassis-cluster information like Redundancy-Group status, use the RPC functions to pull "get-chassis-cluster-status".  For hardware info, "get-chassis-inventory" etc.

 

Cory C.

Highlighted
Junos Automation (Scripting)

Re: Node information : primary or secondary

‎03-25-2019 09:21 AM

Hello Prabir.

 

Even more late reply. Based on suggestion from Cory C. (councilm) you can use RPC function "get-chassis-cluster-status" to get the status of the nodes. The redundancy group 0 is used for control plane status (RE group).

 

Find sample Python code below (also in ZIP file):

mat@ubuntu-autom:~/python$ cat srx-node-info.py
#!/usr/bin/python3
# import needed libraries
import sys
from getpass import getpass
from jnpr.junos import Device
#from jnpr.junos.exception import RpcError
#from lxml import etree

# Get device details from user
hostname = input("Device hostname: ")
username = input("Device username: ")
password = getpass("Device password: ")

# create new device instance
dev=Device(host=hostname, user=username, passwd=password)
#open connection to device
dev.open()
# get information about cluster status for redundancy group 0 (RE group) via RPC as XML structrure
# CLI command "show cluster status redundancy-group 0"
cluster_info=dev.rpc.get_chassis_cluster_status(redundancy_group="0")
# we can print raw text output of CLI command "show cluster status redundancy-group 0" if needed
#print(etree.tostring(dev.rpc.get_chassis_cluster_status({'format':'text'}, redundancy_group="0"), encoding='unicode'))

# create empty list variable for cluster node status
node_status=[]
# iterize through redundancy group 0 status on both nodes
# first is node0 status, followed by node1 status .. this is all the time
for node in cluster_info.iter("redundancy-group-status"):
    node_status.append(node.text)
#    primary_node is node0
if node_status[0] == "primary":
    print("Node 0 is primary.")
    primary_node=0
#    primary_node is node1
elif node_status[1] == "primary":
    print("Node 1 is primary.")
    primary_node=1
# none of the nodes is primary
else:
    print("None of the nodes is primary. Check your cluster")
    primary_node=2

# do something using variable "primary_node" below here
# more Python code goes here

# close connection to device
dev.close()

 

The primary node ID is stored in variable "primary_node" which  can be used in further RPC calls or other functions.

 

We are picking only element "<redundancy-group-status>" from the XML reply of RPC function. Whole output is like this :

labroot@vSRX-node0> show chassis cluster status redundancy-group 0 | display xml
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/18.4R1/junos">
    <chassis-cluster-status>
        <cluster-id>1</cluster-id>
        <redundancy-group>
            <cluster-id>1</cluster-id>
            <redundancy-group-id>0</redundancy-group-id>
            <redundancy-group-failover-count>1</redundancy-group-failover-count>
            <device-stats>
                <device-name>node0</device-name>
                <device-priority>250</device-priority>
                <redundancy-group-status>primary</redundancy-group-status>
                <preempt>no</preempt>
                <failover-mode>no</failover-mode>
                <monitor-failures>None</monitor-failures>
                <device-name>node1</device-name>
                <device-priority>50</device-priority>
                <redundancy-group-status>secondary</redundancy-group-status>
                <preempt>no</preempt>
                <failover-mode>no</failover-mode>
                <monitor-failures>None</monitor-failures>
            </device-stats>
        </redundancy-group>
    </chassis-cluster-status>
    <cli>
        <banner>{primary:node0}</banner>
    </cli>
</rpc-reply>

 

The output from my lab vSRX3 chassis cluster is following:

 

mat@ubuntu-autom:~/python$ ./srx-node-info.py
Device hostname: SRX1
Device username: labroot
Device password:
Node 0 is primary.
mat@ubuntu-autom:~/python$


Device output:
labroot@vSRX-node0> show chassis cluster status redundancy-group 0 | find "Redundancy group"

Redundancy group: 0 , Failover count: 1
node0  250      primary              no      no       None
node1  50       secondary            no      no       None

{primary:node0}
labroot@vSRX-node0>

However not all RPC function calls can provide ouput only from node 0 or node 1 like CLI commands can. There is no parameter for node ID in RPC call. See examples:

 

labroot@vSRX-node0> show chassis routing-engine node 0 | display xml rpc
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/18.4R1/junos">
    <rpc>
        <get-route-engine-information>
        </get-route-engine-information>
    </rpc>
    <cli>
        <banner>{primary:node0}</banner>
    </cli>
</rpc-reply>

labroot@vSRX-node0> show security flow session node 0 | display xml rpc
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/18.4R1/junos">
    <rpc>
        <get-flow-session-information>
        </get-flow-session-information>
    </rpc>
    <cli>
        <banner>{primary:node0}</banner>
    </cli>
</rpc-reply>

Note: 

Test remote machine Ubuntu 18.04.1 LTS  (VM),  Python 3.6.7, PyEZ 2.2.0

Test firewall cluster:   vSRX 3.0 18.4R1.8 on ESXi

 

Hope this helps a bit.  Let us know if we can help further.

 

 

 

Regards
Luděk Matoušek
JNCIS-ENT, JNCIS-SP, JNCIP-SEC, JNCIA-DevOps

Attachments

Feedback