Description

During provisioning on MX Series routers, users may accidentally delete a router's interface hierarchy by using delete interfaces , causing the entire router to be impacted. To prevent this accidental deletion of interfaces via misconfiguration, a commit script can be used.

This article gives the script that can be used to prevent such accidental deletion.

 

Symptoms

Deletion of all interfaces and potential loss of router

 

Solution

Accidental deletion due to misconfiguration

 

  1. Create a new file under /var/db/scripts/commit . Root access would be required.

cd /var/db/scripts/commit
vi interface.slax 

Paste and save the below lines:
version 1.0;
 
ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
 
import "../import/junos.xsl";
 
match configuration {
 
call error-if-missing($must =
                        interfaces/interface[name='lo0']/unit[name='0']/family/inet/address,
                        $statement = 'interfaces lo0 unit 0 family inet address');
                }
 
error-if-missing ($must, $statement = "unknown", $message = "You deleted the interfaces, not allowed, go sit in your corner. Aborting! Missing mandatory configuration statement") {
   
    if (not($must)) {
        <xnm:error> {
            <edit-path> {
                copy-of $statement;
            }
            <message> {
                copy-of $message;
            }
        }
    }
}
  1. Apply the commit script to the configuration under system scripts:

system {
scripts {
    commit {
        file interface.slax;
    }
}
 

Example

{MASTER}[edit]
lab@router-01# delete interfaces
 
{MASTER}[edit]
lab@router-01# commit
interfaces lo0 unit 0 family inet address
  You deleted the interfaces, not allowed, go sit in your corner. Aborting! Missing mandatory configuration statement
error: 1 error reported by commit scripts
error: commit script failure
 
{MASTER}[edit]
lab@router-01#

 

Modification History

2020-01-09: Modified solution and added some changes to script