Automation

Scripting How-To: Update from "route limit" to "prefix limit"

By Elevate posted 08-10-2015 12:32

  

Update From "route limit" to "prefix limit"

 

For SLAX version 1.0 and higher, you can use the max-prefix script to move from "route limit" (deprecated) to "prefix limit" (introduced in Junos OS Release 8.x). You can effectively update a hundred boxes with a small change using a commit script, which converts [...maximum-routes] to [...maximum-prefixes].

 

This is important for routes learned from multiple paths, especially for route reflectors.

 

Source Code and GitHub Links


The source code below is also available from the following GitHub locations:

Example Configuration

 

01	[BEFORE]
02	logical-routers {
03	    foo {
04	        routing-options {
05	            rib inet.0 {
06	                maximum-routes 1033 log-only;
07	                    ## Warning: 'maximum-routes' is deprecated
08	            }
09	        }
10	    }
11	}
12	routing-options {
13	    rib inet.1 {
14	        maximum-routes 1041 log-only;
15	            ## Warning: 'maximum-routes' is deprecated
16	    }
17	}
18	 
19	 
20	[AFTER]
21	logical-routers {
22	    foo {
23	        routing-options {
24	            rib inet.0 {
25	                maximum-prefixes 1033 log-only;
26	            }
27	        }
28	    }
29	}
30	routing-options {
31	    rib inet.1 {
32	        maximum-prefixes 1041 log-only;
33	    }
34	}

 

Example Output

 

01	Add a commit script that performs the change (even deletes itself). It also uses the 'refresh' feature to install the script
02	 
03	[edit]
04	user@cli# set system sripts commit file max-prefix.slax source srv:cs/max-prefix.slax refresh
05	refreshing 'max-prefix.slax' from 'srv:cs/max-prefix.slax'
06	max-prefix.slax 100% 1010  1.0KB/s  00:00
07	 
08	[edit]
09	user@cli# commit
10	[edit logical-routers foo routing-options rib inet.0 undocumented maximum-routes]
11	  warning: Updating 'maximum-routes' to 'maximum-prefixes'
12	[edit routing-options rib inet.1 undocumented maximum-routes]
13	  warning: Updating 'maximum-routes' to 'maximum-prefixes'
14	[edit]
15	  warning: Removing script: max-prefix.slax
16	commit complete

 

SLAX Script Contents

 

01	version 1.0;
02	 
03	ns junos = "http://xml.juniper.net/junos/*/junos";
04	ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
05	ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
06	 
07	import "../import/junos.xsl";
08	 
09	var $script-name = "max-prefix.slax";
10	 
11	match configuration {
12	    for-each (.//maximum-routes) {
13	    var $content = {
14	        <maximum-prefixes> {
15	        copy-of *;
16	        }
17	        <maximum-routes delete="delete">;
18	        }
19	        var $message = "Updating 'maximum-routes' to 'maximum-prefixes'";
20	        call jcs:emit-change($dot = .., $message, $content);
21	    }
22	 
23	    var $base = <system> {
24	    <scripts> {
25	        <commit> {
26	        <file delete="delete"> {
27	            <name> $script-name;
28	        }
29	        }
30	    }
31	    }
32	 
33	    var $script-statement = system/scripts/op[name == $script-name];
34	 
35	    var $content = {
36	    if ($script-statement/@group) {
37	        <groups> {
38	        <name> $script-statement/@group;
39	        copy-of $base;
40	        }
41	    } else {
42	        copy-of $base;
43	    }
44	    }
45	 
46	    var $message = "Removing script: " _ $script-name;
47	    call jcs:emit-change($dot = ., $message, $content);
48	}

 

XML Script Contents

 

01	<?xml version="1.0"?>
02	<script>
03	  <title>max-prefix.slax</title>
04	  <author>phil</author>
05	  <synopsis>
06	    Move from "route limit" (deprecated) to "prefix limit"
07	  </synopsis>
08	  <coe>commit</coe>
09	  <type>logical-routers</type>
10	 
11	  <description>
12	Update a hundred boxes with a small change can be effectively done via a
13	commit script, which converts [...maximum-routes] to [...maximum-prefixes].
14	Important for routes learned from multiple paths, especially for route reflectors
15	 
16	  </description>
17	 
18	  <keyword>maximum-routes</keyword>
19	  <keyword>maximum-prefixes</keyword>
20	  <keyword>deprecated</keyword>
21	  <example>
22	    <title>Example</title>
23	    <description>This is a simple example of how the script is invoked</description>
24	    <config>example-1.conf</config>
25	    <output>example-1.output</output>
26	  </example>
27	 
28	  <xhtml:script xmlns:xhtml="http://www.w3.org/1999/xhtml"
29	                src="../../../../../web/leaf.js"
30	            type="text/javascript"/>
31	</script>

 


#JUNOScriptorium
#commitscript
#ScriptingHow-To
#How-To
#Slax
0 comments
0 views

Permalink