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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
trigger_logging.py - Test log levels w/ Twisted logger.
"""
import os
import logging
import sys

Keybase proof

I hereby claim:

  • I am jathanism on github.
  • I am jathanism (https://keybase.io/jathanism) on keybase.
  • I have a public key whose fingerprint is 9B1E C9E6 D0B1 B49F 64C2 F97A A539 DE2F 6716 94A8

To claim this, I am signing this object:

@jathanism
jathanism / scp.py
Created August 21, 2015 00:02
Pure Python SCP library based on Twisted SSH libraries.
#!/usr/bin/env python
"""
scp.py - SCP implementation using Twisted.
This currently only uploads files to the remote host. Receiving files and
uploading directories is NYI.
Credit: http://bit.ly/1EG3eL4
# -*- coding: utf-8 -*-
"""
Loader for Trigger NetDevices using NSoT API.
Right now this loads ALL devices ALL the time, which scales very poorly with
the number of devices and attributes in NSoT.
Note that ``NETDEVICES_SOURCE`` is ignored because the settings from your
``~/.pynsotrc``.
@jathanism
jathanism / pty_logger.py
Last active September 15, 2015 20:34
Illustrates how Trigger can control and capture anything over it's master SSH connection, even connections to other systems.
from trigger.netdevices import NetDevices
import StringIO
nd = NetDevices()
dev = nd.find('ubuntu.local')
logger = StringIO.StringIO()
dev.connect(output_logger=logger)
# Interactive stdio over the pty session.
"""
@jathanism
jathanism / ssh-proxy.py
Last active September 16, 2015 19:15 — forked from hiboma/ssh-proxy.py
twisted - ssh proxy スケッチ
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
import base64, os, fcntl, tty, struct
from twisted.enterprise import adbapi
from trigger.cmds import Commando
devices = ['device1', 'device2']
commands = ['show mac address-table']
c = Commando(devices=devices, commands=commands)
c.run()
# When it's done
print c.results

NSoT Installation Options & Instructions

Network Server of Truth, or NSoT, is designed to run on multiple architectures and environments that support Python. Provided the host is properly configured, NSoT can be installed with a single command line entry.

$ pip install nsot
import copy
from pynsot.client import get_api_client()
api = get_api_client()
site = api.sites(api.default_site)
objects = site.networks.get(network_address='192.168.0.0')['data']['networks']
to_update = copy.deepcopy(objects)
[t['attributes'] = {} for t in to_update] # Strip the attributes
@jathanism
jathanism / reachable.py
Last active November 15, 2019 13:04
Run 4 reachability tests on network devices and return a list of results for each.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
"""
reachable.py - Run reachability tests on Devices.
The following tests are run:
- DNS ok