Skip to content

Instantly share code, notes, and snippets.

View jeffbrl's full-sized avatar

Jeff Loughridge jeffbrl

View GitHub Profile
@jeffbrl
jeffbrl / NameCheck.robot
Created September 16, 2015 15:46
Robot file for NameCheck testing (robot framework example)
*** Settings ***
Documentation Example test cases using the keyword-driven testing approach.
Library NameCheckLibrary.py
*** Test Cases ***
Test for validity
Set name Bruce
Result should be ${true}
Test for invalidity
@jeffbrl
jeffbrl / get_config.py
Created October 14, 2015 18:39
Pyez - Get router configuration and save to file
# code courtesy of shermdog on pyez google group
from jnpr.junos import Device
dev = Device(host='IP', user='user', passwd='password')
dev.open()
config = dev.rpc.get_config()
from lxml import etree
@jeffbrl
jeffbrl / TestApiConsumer.py
Created October 17, 2015 21:38
Faking an API call using mock object
from api_consumer.api_consumer import ApiConsumer
import unittest
import unittest.mock
import json
class TestApiConsumer(unittest.TestCase):
def setUp(self):
self.ac = ApiConsumer()
@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-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 / 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 / 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
@jeffbrl
jeffbrl / api.py
Created October 3, 2015 22:42
Simple JSON API example in Python
# test with
# curl -X POST -H "Content-Type: application/json" -d '{ "action" : "RUN"}'
# http://127.0.0.1:5000/example/
import json
from flask import request, url_for
from flask.ext.api import FlaskAPI, status, exceptions
app = FlaskAPI(__name__)