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 / 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
"""
@blueyed
blueyed / test_django_data_migration.py
Last active December 9, 2020 16:20
Test Django data migrations
"""
Test (data) migrations in Django.
This uses py.test/pytest-django (the `transactional_db` fixture comes from there),
but could be easily adopted for Django's testrunner:
from django.test.testcases import TransactionTestCase
class FooTestcase(TransactionTestCase):
def test_with_django(self):
# -*- 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 / 01_napalm_compat.py
Last active January 31, 2017 15:39
A very basic test of integration of Trigger's NetDevices/Tacacsrc w/ Napalm. There are two prototypes: 03_troll_test.py is testing using asyncio/trollius or async I/O. 04_twist_test.py is using Twisted.
"""
Integration of Trigger + NAPALM drivers
"""
from napalm import get_network_driver
def get_driver_for_netdevice(device):
vendor_name = device.vendor.name
if vendor_name == 'cisco':
# -*- coding: utf-8 -*-
"""
config_device2.py
Duplicate of `~trigger.contrib.commando.plugins.config_device` using
``Commando`` as a base vs. ``CommandoApplication``.
Bug fixes:
@coxley
coxley / asn_convert.py
Last active February 24, 2016 20:19
ASPLAIN to ASDOT (AS-PLAIN AS-DOT) and reverse
def plain_to_dot(asn): # -> str
'''Take ASPLAIN and return ASDOT notation
asn: int
'''
barray = struct.pack('>I', asn)
return '%d.%d' % struct.unpack('>HH', barray)
def dot_to_plain(asn): # -> int
import sys
from datetime import datetime
import time
from pprint import pprint
from trigger.cmds import Commando
from twisted.python import log
from twisted.internet import reactor
from trigger.netdevices import NetDevices, NetDevice
@djego
djego / rsa.py
Created September 30, 2017 23:20
A simple RSA implementation in Python
'''
620031587
Net-Centric Computing Assignment
Part A - RSA Encryption
'''
import random
'''
@douglasmiranda
douglasmiranda / instructions.md
Created July 19, 2018 05:51
Add email to Keybase.io PGP Key (Public Key)

Export your public key:

keybase pgp export > keybase-public.key

Export your private key:

keybase pgp export --secret > keybase-private.key
@dustindorroh
dustindorroh / python_rsa_example.py
Last active December 12, 2023 02:21
RSA Encryption/Decryption with python
# Inspired from https://medium.com/@ismailakkila/black-hat-python-encrypt-and-decrypt-with-rsa-cryptography-bd6df84d65bc
# Updated to use python3 bytes and pathlib
import zlib
import base64
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP
from pathlib import Path