Skip to content

Instantly share code, notes, and snippets.

View jathanism's full-sized avatar
🍕
See below.

Jathan McCollum jathanism

🍕
See below.
View GitHub Profile
@jathanism
jathanism / runner.py
Created October 10, 2013 20:09
Commando subclass to run commands on Cisco and Juniper devices.
from trigger.cmds import Commando
class Runner(Commando):
vendors = ['cisco', 'juniper']
def to_cisco(self, dev, commands=None, extra=None):
commands = ['show clock']
return commands
def to_juniper(self, dev, commands=None, extra=None):
@jathanism
jathanism / juniper.vim
Created November 5, 2013 14:30
Vim syntax file for Juniper stateless firewall filters
syn case ignore
syn match juniperPermit "accept"
syn match juniperDeny "discard"
syn match juniperProto "\(ip\|udp\|tcp\)"
syn match juniperIcmp "icmp"
syn match juniperAclName "filter"
syn match juniperComment "\/\*.*.\*\/"
syn match juniperNo "replace"
syn match juniperIP "\<\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}\>"
from django.core.exceptions import MiddlewareNotUsed
from django.conf import settings
import cProfile
import pstats
import marshal
from cStringIO import StringIO
class ProfileMiddleware(object):
def __init__(self):
if not settings.DEBUG:
from tastypie.validation import FormValidation
class InstanceFormValidation(FormValidation):
def is_valid(self, bundle, request=None):
errors = {}
data = bundle.data
instance = bundle.obj
@jathanism
jathanism / 0_reuse_code.js
Created August 19, 2014 16:33
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
from trigger.netdevices.loaders.filesystem import JSONLoader
import requests
class JSONApiLoader(JSONLoader):
"""
Wrapper for loading metadata via JSON from the filesystem.
Parse 'netdevices.json' and return list of JSON objects.
"""
is_usable = True
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
@jathanism
jathanism / reactorless_example.py
Last active August 29, 2015 14:13
An example of fetching the time on any device where a specific user is found to be logged in. It's not the most useful example, but it's simple and gets the idea across on how to build workflows using ReactorlessCommando. It's also not super efficient, because it requires a new connection to each device for each subsequent step.
"""
user_example.py - Sample flow of using ReactorlessCommando.
This is an example of the following:
1. Run 'show users' on a list of devices.
2. Check if a certain user is found in the output for each device.
3. Execute 'show clock' on each device where user was found.
4. Display the results
"""
@jathanism
jathanism / severed_head.py
Created January 8, 2015 01:29
For when things fail and you want to class it up.
from trigger.utils.cli import print_severed_head
print_severed_head()
"""
_( (~\
_ _ / ( \> > \
-/~/ / ~\ :; \ _ > /(~\/
|| | | /\ ;\ |l _____ |; ( \/ > >
_\\)\)\)/ ;;; `8o __-~ ~\ d| \ //
///(())(__/~;;\ "88p;. -. _\_;.oP (_._/ /
@jathanism
jathanism / 01_require_ping.py
Last active August 29, 2015 14:14
Only connect to devices that are reachable.
"""
require_ping.py - Only connect to devices that are reachable.
"""
from twisted.python import log
# Start the logger here so we get all our debug messages.
log.startLogging(open('/tmp/require_ping.log', 'w'), setStdout=False)
from trigger.cmds import Commando