-
Notifications
You must be signed in to change notification settings - Fork 0
/
ap-reset-multi.py
executable file
·80 lines (53 loc) · 1.98 KB
/
ap-reset-multi.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python2
import pexpect
import sys
import argparse
import logging
import multiprocessing
import time
def parseArguments():
parser = argparse.ArgumentParser(description='Ruckus AP Reset')
parser.add_argument('filepath', help='filepath')
parser.add_argument('username',help='admin username on AP')
parser.add_argument('password',help='admin password on AP')
return parser.parse_args()
def spanwProcess(ruckus):
logging.info("Process %s: starting", ruckus.ip)
try:
ruckus.child = pexpect.spawn('ssh -o StrictHostKeyChecking=no ' + ruckus.ip)
ruckus.child.logfile = sys.stdout
ruckus.child.timeout = 45
ruckus.child.expect ('Please login:')
ruckus.child.sendline (ruckus.username)
ruckus.child.expect ('password : ')
ruckus.child.sendline (rukus.password + "\r")
ruckus.child.expect ('rkscli: ')
ruckus.child.sendline('set factory\r')
ruckus.child.expect ('OK')
ruckus.child.sendline('reboot\r')
ruckus.child.expect ('OK')
except:
logging.error("Process %s: an error occurred", ruckus.ip)
logging.info("Process %s: finishing", ruckus.ip)
class Ruckus:
def __init__(self, ip, username, password):
self.ip = ip
self.username = username
self.password = password
if __name__ == '__main__':
format = "%(asctime)s: %(message)s"
logging.basicConfig(format=format, level=logging.INFO, datefmt="%H:%M:%S")
args = parseArguments()
logging.info("Main: parsing jobs")
jobs = []
with open(args.filepath) as file:
for ip in file:
rukus = Ruckus(ip, args.username, args.password)
process = multiprocessing.Process(target=spanwProcess, args=(rukus,))
jobs.append(process)
logging.info("Main: starting %d jobs", len(jobs))
for j in jobs:
j.start()
for j in jobs:
j.join()
logging.info("Main: finishing %d jobs", len(jobs))