Automation
Automation

JUNOS Hashtags

by Juniper Employee on ‎04-02-2018 09:16 AM

Imagine that you can tag configuration elements in JUNOS with arbitrary strings and selectively display parts of the configuration based on a tag value. Much like you use hashtags in social media networks.

 

The hashtag can represent a customer, a service, a temporary feature, or just about anything meanigful to you.

 

Well, this is possible today, below is a sample output of running a display command that shows all configurations tagged with 'customer-a'.

 

user@router> op hashtag.py hashtag customer-a 
## Last commit: 2018-04-01 17:29:41 PDT by user
interfaces {
    xe-1/2/0 {
        unit 0 {
            apply-macro ht {
                customer-a;
            }
            family inet {
                filter {
                    input f-input-shared;                    
                }
                address 192.168.1.1/24;
            }
        }
    }
}
## Last commit: 2018-04-01 17:29:41 PDT by user
protocols {
    bgp {
        group ebgp {
            neighbor 192.168.1.2 {
                apply-macro ht {
                    customer-a;
                }
                peer-as 65520;
            }
        }
    }
}
## Last commit: 2018-04-01 17:29:41 PDT by user
firewall {
    family inet {
        filter f-input-shared {
            apply-macro ht {
                customer-a;
                customer-b;
                customer-c;
            }
            term accept-all {
                then accept;
            }
        }
    }
}

Note apply-macro keyword, this is a standard JUNOS feature available from JUNOS 7.4. It allows to add any paramter to any level of JUNOS configuration hierarchy.

 

Just list your arbitrary hashtags under 'apply-macro ht'.

 

Now, to display configuration elements by hashtag, use this Python op script from Junoscriptorium repository.

The script relies on python script support, available in JUNOS 16.1R1.

 

Happy hashtagging!