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.
delete interfaces
This article gives the script that can be used to prevent such accidental deletion.
Deletion of all interfaces and potential loss of router
Accidental deletion due to misconfiguration
Create a new file under /var/db/scripts/commit . Root access would be required.
/var/db/scripts/commit
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; } } } }
Apply the commit script to the configuration under system scripts:
commit
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#
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#
2020-01-09: Modified solution and added some changes to script