Junos Automation (Scripting)
Junos Automation (Scripting)

Extract Juniper info (QoS, Class of Service, Shaping..)

‎10-28-2019 02:59 AM

Good morning,

 

For work needs, I have to extract the QoS (quality of service) configured in more than 500 Juniper devices. I would like to know if it is possible to extract this information through a script that automates the process.

 

If possible, if someone has a base or body of programming from which to work to create the script and can facilitate it, I would greatly appreciate it, since I am currently doing team-by-team work, one by one one.

 

A cordial greeting,

3 REPLIES 3
Junos Automation (Scripting)

Re: Extract Juniper info (QoS, Class of Service, Shaping..)

‎10-28-2019 03:09 AM

Hi adrimnez,

 

We'd shared some script/ideas here, please check and update if it helps you as well:

https://forums.juniper.net/t5/Junos-Automation-Scripting/pushing-a-statement-to-1500-srx-devices/td-...

 

Hope this helps.

 

Regards,
-r.

--------------------------------------------------

If this solves your problem, please mark this post as "Accepted Solution."
Kudos are always appreciated Smiley Happy.

Junos Automation (Scripting)

Re: Extract Juniper info (QoS, Class of Service, Shaping..)

‎10-28-2019 03:53 AM

I do not know if what you tell me is what I really need, I am not going to configure, it would simply be a script that identifies with some credentials, and extracts the information from the following commands for example:

 

show configuration class-of-service interfaces

show configuration class-of-service interfaces ge-6/0/23 | display set
show configuration class-of-service schedulers | display set


Thx for your help.

 

Regards,

Junos Automation (Scripting)

Re: Extract Juniper info (QoS, Class of Service, Shaping..)

[ Edited ]
‎10-28-2019 05:40 AM

Hi adrimnez,

 

Just have a server/host downloaded with PyEZ and you can use a script something like the following:

 

from jnpr.junos import Device
from lxml import etree

f=open("devices_for_COS.txt","r")
#print (f"IPs are: {IPs}")
for line in f:
	line=line.rstrip()
	print (line)
	print ("##########################################################")
	dev = Device(host=line,user='labroot',passwd='lab123')
	dev.open()
	filter = etree.XML('<configuration><class-of-service/></configuration>')
	data = dev.rpc.get_config(filter_xml=filter,options={'format':'text'})
	print (etree.tostring(data, encoding='unicode', pretty_print=True))
	dev.close()

Here devices_for_COS.txt is a text file containing IP addresses of your 500 devices, one IP in each line.  Sample content of devices.txt will be:

10.85.168.61

10.85.161.166

 

Sample Output looks like this:

C:\Python27\Scripts>python get_COS_config.py
10.85.168.61
##########################################################
<configuration-text>
## Last changed: 2019-10-28 12:05:30 UTC
class-of-service {
    shared-buffer {
        ingress {
            percent 100;
            buffer-partition lossless {
                percent 5;
            }
            buffer-partition lossy {
                percent 95;
            }
            buffer-partition lossless-headroom {
                percent 0;
            }
        }
        egress {
            percent 100;
            buffer-partition lossless {
                percent 5;
            }
            buffer-partition lossy {
                percent 85;
            }
            buffer-partition multicast {
                percent 10;
            }
        }
    }
    forwarding-classes {
        class strange11 queue-num 11;
        class strange10 queue-num 10;
    }
    traceoptions {
        file cosd.txt size 10m files 10;
        flag all;
    }
}
</configuration-text>

10.85.161.166
##########################################################

 

If you'll give this to someone new to Python/PyEZ, please check these out:

https://www.juniper.net/documentation/en_US/junos-pyez/topics/task/installation/junos-pyez-server-in...

https://www.juniper.net/documentation/en_US/junos-pyez/topics/task/program/junos-pyez-connection-met...

https://www.juniper.net/documentation/en_US/junos-pyez/topics/task/program/junos-pyez-program-config...

 

This should have everything you need, at least for this requirement if not more Smiley Happy.

 

Hope this helps.

Regards,
-r.

--------------------------------------------------

If this solves your problem, please mark this post as "Accepted Solution."
Kudos are always appreciated Smiley Happy.