Hey, there’s a shell under those covers in Junos

Recently, okay today, a customer asked me about dealing with a persnickety problem in Junos.  She wanted to modify how bpdu-block was working on her EX switch.  The initial configuration was that it was enabled on all interfaces and she wanted to selectively disable it on a few ports.  One thing that Junos is not great at (yet) is interface range type commands.

The configuration for this particular command is as follows:

ethernet-switching-options {
     bpdu-block {
     disable-timeout timeout;
     interface (all | [interface-name]);
}

Essentially, you can either specify that bpdu-block is turned on for every interface, or for individual interfaces. There is no interface-range parameter here (yes, it’s something that Juniper needs to work on). If you want to enable it on say ge-0/0/0 through ge-0/0/4 and then on ge-0/0/15 through ge-0/0/23 you’ve got to add each interface into the config manually.

This is a giant pain point. But it can easily be solved with some good ole unix trickery and the formidable “load” command in Junos.

Here’s how to do it.

First we need to get a list of interfaces:

root@EX2200-24T>show interfaces terse | match eth-switch | save interfaces.txt

This creates a file “interfaces.txt” in your home directory on the filesystem.

Next we need to get into the shell.

root@EX2200-24T>start shell

Now we’ll use vi to manipulate the file.

root@EX2200-24T:RE:0% vi interfaces.txt

Use the vi commands below to replace the pattern “up down eth-switch” with a semicolon.

:%s/up    down eth-switch//g
:%s/.0/.0;/g

Now my file looks like this:

ge-0/0/1.0;
ge-0/0/2.0;
ge-0/0/3.0;
ge-0/0/4.0;
ge-0/0/5.0;
ge-0/0/6.0;
ge-0/0/7.0;
ge-0/0/8.0;
ge-0/0/9.0;
ge-0/0/10.0;
ge-0/0/11.0;
ge-0/0/12.0;
ge-0/0/13.0;
ge-0/0/14.0;
ge-0/0/15.0;
ge-0/0/16.0;
ge-0/0/17.0;
ge-0/0/18.0;
ge-0/0/19.0;
ge-0/0/20.0;
ge-0/0/21.0;
ge-0/0/22.0;
ge-0/0/23.0;

Now I need to add the word “interface” before each interface name:

:%s/ge/interface ge/g

Now my file looks like this:

interface ge-0/0/0.0;
interface ge-0/0/1.0;
interface ge-0/0/2.0;
interface ge-0/0/3.0;
interface ge-0/0/4.0;
interface ge-0/0/5.0;
interface ge-0/0/6.0;
interface ge-0/0/7.0;
interface ge-0/0/8.0;
interface ge-0/0/9.0;
interface ge-0/0/10.0;
interface ge-0/0/11.0;
interface ge-0/0/12.0;
interface ge-0/0/13.0;
interface ge-0/0/14.0;
interface ge-0/0/15.0;
interface ge-0/0/16.0;
interface ge-0/0/17.0;
interface ge-0/0/18.0;
interface ge-0/0/19.0;
interface ge-0/0/20.0;
interface ge-0/0/21.0;
interface ge-0/0/22.0;
interface ge-0/0/23.0;

Save the file with the key sequence “^esc-w-q”

Then exit the shell and get into edit mode on your EX switch.

root@EX2200-24T:RE:0%exit

root@EX2200-24T>edit

[edit]
root@EX2200-24T# edit ethernet-switching-options bpdu-block

Use the “load” command to load your file into the current hierarchy of the config.

[edit ethernet-switching-options bpdu-block]
root@EX2200-24T# load merge relative interfaces.txt
load complete

[edit ethernet-switching-options bpdu-block]
root@EX2200-24T# show
bpdu-block {
     interface ge-0/0/0.0;
     interface ge-0/0/1.0;
     interface ge-0/0/2.0;
     interface ge-0/0/3.0;
     interface ge-0/0/4.0;
     interface ge-0/0/5.0;
     interface ge-0/0/6.0;
     interface ge-0/0/7.0;
     interface ge-0/0/8.0;
     interface ge-0/0/9.0;
     interface ge-0/0/10.0;
     interface ge-0/0/11.0;
     interface ge-0/0/12.0;
     interface ge-0/0/13.0;
     interface ge-0/0/14.0;
     interface ge-0/0/15.0;
     interface ge-0/0/16.0;
     interface ge-0/0/17.0;
     interface ge-0/0/18.0;
     interface ge-0/0/19.0;
     interface ge-0/0/20.0;
     interface ge-0/0/21.0;
     interface ge-0/0/22.0;
     interface ge-0/0/23.0;
     disable-timeout 10;
}

Run commit – I like to run a commit check first – and you’re done.

[edit ethernet-switching-options]
root@EX2200-24T# commit check
configuration check succeeds

[edit ethernet-switching-options]
root@EX2200-24T# commit
commit complete

I find this type of file manipulation useful on many occasions. I love the fact that there is a full-blown shell built into Junos. It opens up so many possibilities in terms of assisting me when I’m doing configurations.

And this is a good example of why Unix skills help you to be a better network engineer.

2 thoughts on “Hey, there’s a shell under those covers in Junos

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s