-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
61 lines (41 loc) · 2 KB
/
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
56
57
58
59
60
61
import queue
import os
from sys import argv
from threading import Thread
from deffile import *
from datetime import datetime
starttime = datetime.now()
current_date = starttime.strftime("%Y.%m.%d")
current_time = starttime.strftime("%H.%M.%S")
current_dir = os.getcwd()
folder = "{}\\logs\\{}\\".format(current_dir, current_date) # current dir / logs / date /
if not os.path.exists(folder):
os.mkdir(folder)
q = queue.Queue()
#######################################################################################
# ------------------------------ main part -------------------------------------------#
#######################################################################################
argv_dict = get_argv(argv)
username, password = get_user_pw()
devices = get_devinfo("devices.yaml")
total_devices = len(devices)
print("-------------------------------------------------------------------------------------------------------")
print("hostname ip address comment")
print("-------------------------------------------------------------------------------------------------------")
for i in range(argv_dict["maxth"]):
th = Thread(target=mconnect, args=(username, password, q))
th.setDaemon(True)
th.start()
for device in devices:
q.put(device)
q.join()
print("")
failed_connection_count = write_logs(devices, current_date, current_time, folder, export_device_info, export_excel)
duration = datetime.now() - starttime
#######################################################################################
# ------------------------------ last part -------------------------------------------#
#######################################################################################
print("--------------------------------------------------------------")
print("failed connection: {0} total device number: {1}".format(failed_connection_count, total_devices))
print("elapsed time: {}".format(duration))
print("--------------------------------------------------------------\n")