Skip to content

Instantly share code, notes, and snippets.

@jeffbrl
Created August 31, 2015 17:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffbrl/1ad542dda06c9efaa9f8 to your computer and use it in GitHub Desktop.
Save jeffbrl/1ad542dda06c9efaa9f8 to your computer and use it in GitHub Desktop.
Example of using apply-macro as generic key/value store - SLAX
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;
}
}
}
@FlorianHeigl
Copy link

FlorianHeigl commented Sep 23, 2023

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.

;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment