Junos
Junos

Re: JUNOSCRIPT: jcs:empty and inheritence

‎07-05-2010 06:52 AM

It could look like this:

 

for-each( interfaces/interface[ starts-with( name, "ge-") ]/unit[ name == "99"][ jcs:empty( @junos:group ) ] )

 

So, in this case one predicate is applied to the<interface> node, requiring that it start with "ge-", then two predicates are attached to the chid <unit> node, requiring that it be "99" as well as have no junos:group attribute.

3 REPLIES 3
Highlighted
Junos

JUNOSCRIPT: jcs:empty and inheritence

‎03-13-2010 10:06 AM

I have a script that currently checks to see if configuration exists before adding config:

 

var $policer_name = $top/interfaces/interface[name == $phyifname]/unit[name == $unit]/bandwidth;
if (not(jcs:empty($policer_name))) {}

 

How can I apply the same test, but ONLY test true if the config is empty regardless of inheritence?  With what I have above, if I apply a group that sets a policer on the interface, but it is not configured on the interface, it tests false.  I want to say:

 

"If a policer is configured on the interface explicitly, and not only via 'apply-groups', then do foo"

 

Is there a way to accomplish this?

Junos

Re: JUNOSCRIPT: jcs:empty and inheritence

‎03-15-2010 09:26 AM

First things first, you mentioned policers but the bandwidth statement only affects the speed reported to SNMP, it doesn't actually rate-limit AFAIK, you need to apply an actual policer for that:

 

http://www.juniper.net/techpubs/en_US/junos10.1/information-products/topic-collections/config-guide-...

 

Going back to the overall question about how to check for configuration without including inherited statements, it depends on how you retrieved the configuration in the first place. When you called <get-configuration>, did you specify inherit="inherit" as an attribute, or commit-scripts="view"? If not then you are working with the pre-inheritance configuration and do not have to do anything. If you are working with the post-inheritance configuration though, what you can do is add the groups="groups" attribute to <get-configuration>, which causes all inherited items to have a junos:group attribute applied with the name of the configuration group from which it was inherited. If, on the other hand, this is a commit script then the configuration provided will be post-inheritance and will already contain the junos:group attributes.

 

Then, you could do a location path like this:

 

var $policer_name = $top/interfaces/interface[name == $phyifname]/unit[name == $unit]/bandwidth[ not( @junos:group )];
Junos

Re: JUNOSCRIPT: jcs:empty and inheritence

‎07-03-2010 02:30 PM

Could I use something like this in a foreach that is already matching on a value (ie, unit=99)

 

 

     for-each (interfaces/interface[starts-with(name, "ge-")]/unit[name==99]) {

 

 

What would I want the syntax look like to say "for each interface that begins with ge- and ( unit=99 and unit=99 is NOT inherited )?