Skip to content

Instantly share code, notes, and snippets.

View jeffbrl's full-sized avatar

Jeff Loughridge jeffbrl

View GitHub Profile
@jeffbrl
jeffbrl / test.slax
Created October 23, 2015 18:48
slaxproc example
version 1.1;
/* usage: slaxproc -r test.slax input.xml */
match / {
for-each(//isis-interface) {
<interface-name>interface-name;
}
}
@jeffbrl
jeffbrl / load-config.slax
Last active March 27, 2018 22:34
jcs:load-configuration with template and document()
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";
ns func extension = "http://exslt.org/functions";
ns automation = "http://xml.juniper.net/automation";
import "../import/junos.xsl";
@jeffbrl
jeffbrl / load-config2.slax
Created December 9, 2015 17:35
An example in slax of merging set-style configuration
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";
ns exsl extension = "http://exslt.org/common";
ns func extension = "http://exslt.org/functions";
ns automation = "http://xml.juniper.net/automation";
import "../import/junos.xsl";
@jeffbrl
jeffbrl / get-junos-configs.yml
Last active March 13, 2017 13:37
Ansible - Using Juniper.junos junos_get_config module
# This task gets all Junos configuration from all devices
- name: Get configuration
hosts: all
connection: local
gather_facts: no
roles:
- Juniper.junos
vars_prompt:
- name: USER
prompt: Device user
@jeffbrl
jeffbrl / put-junos-configs.yml
Last active June 2, 2017 13:23
Ansible - Using Juniper.junos junos_install_config module
# This task pushes Junos config files to devices
- name: Get configuration
hosts: all
connection: local
gather_facts: no
roles:
- Juniper.junos
vars_prompt:
- name: USER
prompt: Device user
@jeffbrl
jeffbrl / ham.py
Created January 13, 2016 20:08
Simple decorator example with functools.wraps
#!/usr/bin/env python3
from functools import wraps
def add_sandwich(wrapped):
''' add_sandwich doc_string '''
# try commenting out the next line to see what happens
@wraps(wrapped)
def wrapper(*args, **kwargs):
@jeffbrl
jeffbrl / run-junos-cmds.yml
Last active March 17, 2016 18:51
Ansible - Using Juniper junos_cli module to execute CLI commands
# Playbook for executing CLI commands with output to text files
#
# Single host:
# ansible-playbook -i "router_name_here," -e '{ "CMD": "your_command_here" }' run-junos-cmds.yml
# Multiple hosts:
# ansible-playbook -i inventory_file -e '{ "CMD": "your_command_here" }' run-junos-cmds.yml
- name: Run CLI commands
hosts: all
connection: local
@jeffbrl
jeffbrl / jxmlease_examples.py
Last active July 12, 2016 14:01
Parsing Junos XML output using jxmlease examples
from __future__ import print_function
import jxmlease
# Accessing current time from get-system-uptime
with open('get-system-uptime.xml') as xml:
root = jxmlease.parse(xml)
uptime = root['rpc-reply']['system-uptime-information']['current-time']['date-time'].get_cdata()
print("uptime: {}".format(uptime))
print('\n===============\n')
@jeffbrl
jeffbrl / bgp_check.py
Last active December 18, 2016 16:30
jsnapy as a module for BGP peer state check
#!/usr/bin/env python
# portions of this code derived from samples directory of the jsnapy project
from __future__ import print_function
import sys
import time
from jnpr.jsnapy import SnapAdmin
from pprint import pprint
@jeffbrl
jeffbrl / 0_reuse_code.js
Created July 25, 2016 12:02
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console