forked from monavy/cisco-ise-api-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_endpoint.py
executable file
·79 lines (63 loc) · 2.26 KB
/
delete_endpoint.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
#!/usr/bin/env python
import re
import os
import sys
import threading
import random
from local_helpers import accounts_db, utils_endpoint
if __name__ == "__main__":
if (len(sys.argv) != 2):
sys.exit('\nusage: ./script.py <source-list-file>\n')
src_file_path = sys.argv[1]
if os.path.exists(src_file_path):
switch_list = src_file_path
else:
sys.exit('\nfile: ' + src_file_path + ' could not be found\n')
'''get credentials from accounts_db'''
creds_edit = None
creds_read = None
try:
for creds in accounts_db.accounts_pan:
if creds.get('ise_role') == str('primary'):
creds_edit = creds
if creds.get('ise_role') == str('secondary'):
creds_read = creds
except Exception, e:
print e
sys.exit()
f = open(switch_list, "r")
entry_list = []
multi_thread = []
for line_entry in iter(f):
'''skip lines with comments'''
if '#' in line_entry:
next
else:
my_line = re.split('[,]+', re.sub('\n|\r','',line_entry))
mac_add = my_line[0]
role = my_line[1]
desc = my_line[2]
mac_address = str.strip(re.sub(':|\.', '', mac_add))
mac_address = mac_address.lower()
'''ISE does not take spaces. Replace space with a dash'''
role = str.strip(re.sub(' ', '-', role))
if (len(mac_address) != 12):
print 'Invalid MAC Address: ' + str(mac_address)
else:
'''correct mac address format'''
mac_address = ':'.join(mac_address[i:i+2] for i in range(0, len(mac_address), 2))
results = None
try:
utils_endpoint.delete_endpoint_by_mac(creds_edit,creds_read,mac_address)
# thread_call = threading.Thread(
# target=utils_endpoint.delete_endpoint_by_mac,
# args=(creds_edit,creds_read,mac_address))
# multi_thread.append(thread_call)
# thread_call.start()
except Exception, e:
#print e
pass
#sys.exit()
#"""wait for all threads to finish"""
#for t in multi_thread:
# t.join()