-
Notifications
You must be signed in to change notification settings - Fork 7
/
multithread.py
59 lines (52 loc) · 1.5 KB
/
multithread.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
"""
This module controls the multithreaded calls to Class BaseNode
"""
import datetime
import initialize
import os
import threading
import time
from getpass import getpass
def multithread_engine(ntw_object,redirect,commands,authentication):
start_time = datetime.datetime.now()
index = 0
zero = 0
element = 0
if authentication:
initialize.password = authenticate()
for node in ntw_object:
if(redirect[zero] == 'exec_cmd' or redirect[zero] == 'pull_cfgs' ):
"""
argument(s)/command(s) are being blackholed
"""
arguments = commands
element = 0
elif(redirect[index] == 'push_cfgs' or redirect[index] == 'get_config' or redirect[index] == 'get_diff'):
arguments = commands[index]
element = index
my_thread = threading.Thread(delayed_detection(),target=getattr(ntw_object[index],redirect[element]) , args=(initialize.password,arguments,))
my_thread.start()
index = index + 1
main_thread = threading.currentThread()
for some_thread in threading.enumerate():
if some_thread != main_thread:
some_thread.join()
print('[>] Complete [{}]\n'.format(datetime.datetime.now() - start_time))
return None
def authenticate():
"""
Check to see if environment variable exist.
"""
if 'NETWORK_PASSWORD' in os.environ:
initialize.password = os.environ.get('NETWORK_PASSWORD')
else:
try:
initialize.password = getpass()
except KeyboardInterrupt as error:
print('')
print('Terminating...')
exit()
return initialize.password
def delayed_detection():
time.sleep(0)
return None