Junos Automation (Scripting)
Junos Automation (Scripting)

Script prevents "commit at" from working

‎10-06-2011 06:12 AM

Hi,

 

I use the following script to fill a prefix-list with prefixes from interfaces which have the apply-macro "customer-interface" defined. It works well when doing a "normal" commit, but when I do a "commit at <time>" the commit will not execute and the cscript.log shows that the commit-script is called every minute after the original "commit at" time. I have to manually clear the pending commit. A show | compare shows me that the prefix-list has been deleted but did not get created again.

 

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 {

    var $policy-options = policy-options;
    var $auto-bgp-pfx-list = "AUTO-customer-bgp-routes";

    var $replace-pfxlist = {
        <prefix-list delete="delete"> {
            <name> $auto-bgp-pfx-list;
        }
    }
    call jcs:emit-change($dot = $policy-options, $content = $replace-pfxlist);

    var $change = {
        <junos:comment> "/* This prefix-list is generated automatically! */";
        <prefix-list> {
            <name> $auto-bgp-pfx-list;

            /* Search for customer interfaces */
            for-each( interfaces/interface/unit[apply-macro/name == "customer-interface"]/family/inet/address ) {
                var $xaddr = jcs:parse-ip(name);
                var $pfx = $xaddr[4] _ "/" _ $xaddr[3];
                <prefix-list-item> {
                    <name> $pfx;
                }
            }
        }
    }
    call jcs:emit-change($dot = $policy-options, $content = $change);
}

 Any idea why that happens and how to make it work?

--
Sebastian Wiesinger
JNCIS-SP
2 REPLIES 2
Junos Automation (Scripting)

Re: Script prevents "commit at" from working

‎10-06-2011 07:16 AM

I don't know why there was a delete in there just to add it back later, but changing it to a "replace" fixed the problem. I still don't know where the problem came from so an answer would be nice...

 

 

This is the new (working) script:

 

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 {

    var $policy-options = policy-options;
    var $auto-bgp-pfx-list = "AUTO-customer-bgp-routes";

    var $change = {
        <junos:comment> "/* This prefix list is generated atomatically! */";
        <prefix-list replace="replace"> {
            <name> $auto-bgp-pfx-list;

            /* search for customer interfaces */
            for-each( interfaces/interface/unit[apply-macro/name == "customer-interface"]/family/inet/address ) {
                var $xaddr = jcs:parse-ip(name);
                var $pfx = $xaddr[4] _ "/" _ $xaddr[3];
                <prefix-list-item> {
                    <name> $pfx;
                }
            }
        }
    }
    call jcs:emit-change($dot = $policy-options, $content = $change);
}

 

--
Sebastian Wiesinger
JNCIS-SP
Junos Automation (Scripting)

Re: Script prevents "commit at" from working

‎10-10-2011 11:25 AM

I can't think of a reason why this would be different for "commit" versus "commit at". You might be hitting a PR of some kind.