-
Notifications
You must be signed in to change notification settings - Fork 0
/
net_main.py
55 lines (38 loc) · 1.63 KB
/
net_main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#! /usr/bin/env python
# net_main.py example program for inventory gathering
# Class 8 in Byers' Applied Python series
from net_system.models import NetworkDevice, Credentials #removed SnmpCredentials
from remote_connection.ssh_connection import SSHConnection
import django
import time
def gather_inventory():
# Main program dispatch for working each device,
# connecting appropriately based on class and
# looking through config
DEBUG = False
net_devices = NetworkDevice.objects.all()
for a_device in net_devices:
if 'ssh' in a_device.device_class:
if DEBUG: print "SSH inventory call: {} {}".format(a_device.device_name, a_device.device_class)
ssh_connect = SSHConnection(a_device)
ssh_connect.establish_connection()
elif 'onepk' in a_device.device_class:
if DEBUG: print "onePK inventory call: {} {}".format(a_device.device_name, a_device.device_class)
pass
elif 'eapi' in a_device.device_class:
if DEBUG: print "eAPI inventory call: {} {}".format(a_device.device_name, a_device.device_class)
pass
else: #invalid conditions handler
pass
# START MAIN LOOP
if __name__ == "__main__":
django.setup()
LOOP_DELAY = 300 # 5-minute pause between loops
VERBOSE = True
time.sleep(5)
print
while True:
if VERBOSE: print "Gather inventory from devices"
gather_inventory()
if VERBOSE: print "Sleeping for {} seconds".format(LOOP_DELAY)
time.sleep(LOOP_DELAY)