Skip to content

Instantly share code, notes, and snippets.

View ktbyers's full-sized avatar

Kirk Byers ktbyers

View GitHub Profile
#!/usr/bin/env python
from getpass import getpass
from pprint import pprint as pp
from napalm import get_network_driver
#from napalm_base import get_network_driver
#import napalm_ios
from netmiko import ConnectHandler
#!/usr/bin/env python
from netmiko import ConnectHandler
from getpass import getpass
ip_addr = raw_input("Enter IP Address: ")
device = {
'device_type': 'cisco_ios',
'ip': ip_addr,
'username': 'admin',
#!/usr/bin/env python
'''
Write a Python program that creates a list. One of the elements of the list
should be a dictionary with at least two keys. Write this list out to a file
using both YAML and JSON formats. The YAML file should be in the expanded form.
'''
import yaml
import json
---
- name: NAPALM vlan configuration
hosts: nxos2
gather_facts: False
tasks:
- napalm_install_config:
hostname: "{{ host }}"
username: "{{ username }}"
password: "{{ password }}"
- name: NAPALM vlan configuration
hosts: pynet-sw1
gather_facts: False
tasks:
- napalm_install_config:
hostname: "{{ eapi_hostname }}"
username: "{{ eapi_username }}"
password: "{{ eapi_password }}"
dev_os: eos
config_file: pynet-sw1-merge.cfg
@ktbyers
ktbyers / threading_csv.py
Created February 24, 2017 20:10
Netmiko Threading from a CSV file
import csv
import threading
from Queue import Queue
from getpass import getpass
from netmiko import ConnectHandler
from datetime import datetime
USER = 'pyclass'
PASSWORD = getpass()
@ktbyers
ktbyers / arista_class.py
Created March 23, 2017 18:14
Arista Class
import socket
import jsonrpclib
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
class AristaSwitch(object):
def __init__(self, switch, username, password):
self.switch = switch
self.username = username
@ktbyers
ktbyers / gist:7372e272000389e38f287482140898d5
Created March 27, 2017 18:08
EOS NAPALM get_optics data
{u'Ethernet3/1/1': {u'physical_channels': {u'channel': [{u'index': 0,
u'state': {u'input_power': {u'avg': 0.0,
u'instant': -1.8025870272698974,
u'max': 0.0,
u'min': 0.0},
u'laser_bias_current': {u'avg': 0.0,
u'instant': 6.306,
u'max': 0.0,
u'min': 0.0},
u'output_power': {u'avg': 0.0,
new_output:
changed: false
msg: "All items completed"
results:
- item: Vlan99
stdout: ["Building configuration...\n\nCurrent configuration : 66 bytes\n!\ninterface Vlan99\n no ip address\n ip helper-address 1.1.1.1\nend\n",]
warnings: []
- item: Vlan1
stdout: ["Building configuration...\n\nCurrent configuration : 66 bytes\n!\ninterface Vlan99\n no ip address\n ip helper-address 1.1.1.1\nend\n",]
warnings: []
tasks:
- ios_facts:
provider: "{{ creds }}"
- ios_config:
provider: "{{ creds }}"
lines:
- ip helper-address 1.1.1.1
parents: interface {{ item }}
with_items: "{{ dhcp_interfaces }}"