Created
August 31, 2015 17:06
-
-
Save jeffbrl/1ad542dda06c9efaa9f8 to your computer and use it in GitHub Desktop.
Example of using apply-macro as generic key/value store - SLAX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 / { | |
<op-script-results> { | |
var $key_vals_rtf := { call get_key_value_pairs($macro_name="upgrade"); } | |
for-each($key_vals_rtf/pair) { | |
<output> "key: " _ key; | |
<output> "value: " _ value; | |
} | |
} | |
} | |
/* Returns node set of key value pairs from apply-macros | |
Param: name of apply macro to parse | |
*/ | |
template get_key_value_pairs($macro_name = "") | |
{ | |
var $config-rpc = { | |
<get-configuration database="committed">; | |
} | |
var $routing-instance-configuration = jcs:invoke( $config-rpc ); | |
for-each($routing-instance-configuration/apply-macro[name = $macro_name]/data) { | |
<pair> { | |
<key>name; | |
<value>value; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i suppose once I passed on the JNCIS-Devops I'll understand what this really does.
right now I just understand that it is likely really important and could be very useful.
;-)