Skip to content

Commit e85961a

Browse files
author
ciscodatacenter
committed
TLS NXAPI Script and NDBActivator3.0_I5_Plus
1 parent 0f9b367 commit e85961a

File tree

8 files changed

+2046
-0
lines changed

8 files changed

+2046
-0
lines changed

nexusdatabroker/NDBActivator3.0_I5_Plus.py

+495
Large diffs are not rendered by default.
Binary file not shown.
Binary file not shown.

nexusdatabroker/TLSNXAPITool1.0/OpenSSL.py

+1,078
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import os
2+
import sys
3+
import yaml
4+
import requests
5+
import subprocess
6+
import logging
7+
import paramiko
8+
# pylint: disable-msg=E0611
9+
from requests.packages.urllib3.exceptions import InsecureRequestWarning
10+
from requests.packages.urllib3.exceptions import SNIMissingWarning
11+
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
12+
requests.packages.urllib3.disable_warnings(SNIMissingWarning)
13+
14+
class Server:
15+
def __init__(self):
16+
self.conn_type = "https"
17+
with open(INPUTFILE) as file_ptr:
18+
confi = yaml.safe_load(file_ptr)
19+
self.server_ip = confi['ServerIP']['ServerIP1']['ip']
20+
self.username = confi['ServerIP']['ServerIP1']['user']
21+
self.password = confi['ServerIP']['ServerIP1']['password']
22+
self.port = '8443'
23+
self.web_url = ""
24+
self.login_url = ""
25+
self.add_device_url = ""
26+
self.device_response = 0
27+
self.xnc_pwd = str(confi['xnc_password'])
28+
self.xnc_usr = str(confi['xnc_username'])
29+
def ndb_servrer_login(self, device_info):
30+
try:
31+
self.web_url = self.conn_type+"://"+self.server_ip+":"\
32+
+self.port+"/monitor/"
33+
self.login_url = self.conn_type+"://"+self.server_ip+":"\
34+
+self.port+"/monitor/j_security_check"
35+
login_payload = {"j_username" : self.xnc_usr, "j_password" : self.xnc_pwd}
36+
with open(INPUTFILE) as file_ptr:
37+
dev_info = yaml.safe_load(file_ptr)
38+
add_device_payload = device_info
39+
add_device_payload['connectiontype'] = 'NXAPI'
40+
add_device_payload['auxnode'] = 'false'
41+
for key in add_device_payload:
42+
add_device_payload[key] = str(add_device_payload[key])
43+
self.add_device_url = str(self.conn_type+"://"+\
44+
str(self.server_ip)+":"+str(self.port)+\
45+
"/controller/web/devices/extended//element/add")
46+
#pylint: disable=maybe-no-member
47+
with requests.session() as ses:
48+
ses.get(self.web_url, verify=False)
49+
ses.post(self.login_url, data=login_payload, verify=False)
50+
ses.post(self.add_device_url, data=add_device_payload, verify=False)
51+
LOGGER.info("Device - "+add_device_payload['address']+\
52+
" Device added successfully")
53+
except paramiko.SSHException:
54+
LOGGER.error("Device - "+add_device_payload['address']+\
55+
" Failed to add device in NDB")
56+
if __name__ == "__main__":
57+
FILE1 = '/etc/ssh/ssh_config'
58+
DIR = os.path.dirname(__file__)
59+
#sys.stdout = os.devnull
60+
if not os.path.isdir('./Utilities/Log'):
61+
os.mkdir("./Utilities/Log")
62+
#sys.stdout = open(os.devnull, "w")
63+
if len(sys.argv) == 1:
64+
FILENAME = os.path.join(DIR, './Utilities/Log/Logfile.log')
65+
LOGGER = logging.getLogger(__name__)
66+
LOGGER.setLevel(logging.DEBUG)
67+
CON_LOG_HANDLER = logging.StreamHandler()
68+
FILE_LOG_HANDLER = logging.FileHandler(FILENAME)
69+
FILE_LOG_HANDLER.setLevel(logging.DEBUG)
70+
CON_LOG_HANDLER.setLevel(logging.DEBUG)
71+
FORMATTER = logging.Formatter(
72+
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
73+
FILE_LOG_HANDLER.setFormatter(FORMATTER)
74+
CON_LOG_HANDLER.setFormatter(FORMATTER)
75+
LOGGER.addHandler(FILE_LOG_HANDLER)
76+
LOGGER.addHandler(CON_LOG_HANDLER)
77+
elif len(sys.argv) == 2:
78+
if '--quiet' in sys.argv:
79+
FILENAME = os.path.join(DIR, './Utilities/Log/Logfile.log')
80+
LOGGER = logging.getLogger(__name__)
81+
LOGGER.setLevel(logging.DEBUG)
82+
FILE_LOG_HANDLER = logging.FileHandler(FILENAME)
83+
FILE_LOG_HANDLER.setLevel(logging.DEBUG)
84+
FORMATTER = logging.Formatter(
85+
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
86+
FILE_LOG_HANDLER.setFormatter(FORMATTER)
87+
LOGGER.addHandler(FILE_LOG_HANDLER)
88+
else:
89+
FILENAME = os.path.join(DIR, './Utilities/Log/Logfile.log')
90+
LOGGER = logging.getLogger(__name__)
91+
LOGGER.setLevel(logging.DEBUG)
92+
CON_LOG_HANDLER = logging.StreamHandler()
93+
FILE_LOG_HANDLER = logging.FileHandler(FILENAME)
94+
FILE_LOG_HANDLER.setLevel(logging.DEBUG)
95+
CON_LOG_HANDLER.setLevel(logging.DEBUG)
96+
FORMATTER = logging.Formatter(
97+
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
98+
FILE_LOG_HANDLER.setFormatter(FORMATTER)
99+
CON_LOG_HANDLER.setFormatter(FORMATTER)
100+
LOGGER.addHandler(FILE_LOG_HANDLER)
101+
LOGGER.addHandler(CON_LOG_HANDLER)
102+
LOGGER.error(" Run python script without arguments or along "+\
103+
"with --quiet argument")
104+
sys.exit(0)
105+
else:
106+
LOGGER.error(" Run python script without arguments or along "+\
107+
"with --quiet argument")
108+
sys.exit(0)
109+
if '--quiet' in sys.argv:
110+
subprocess.call(" python TLSScript.py --quiet", shell=True)
111+
subprocess.call(" python OpenSSL.py --quiet", shell=True)
112+
else:
113+
subprocess.call(" python TLSScript.py 1", shell=True)
114+
subprocess.call(" python OpenSSL.py 1", shell=True)
115+
INPUTFILE = os.path.join(DIR, './Utilities/Input/inputfile.yaml')
116+
DEV = Server()
117+
with open(INPUTFILE) as f:
118+
DEVICE_INFO = yaml.safe_load(f)
119+
for dic in sorted(DEVICE_INFO['IP'].keys()):
120+
DEV.ndb_servrer_login(DEVICE_INFO['IP'][dic])
121+
os.system("rm -rf ./Utilities/TlsCerts/temp")
122+
os.system("rm -rf ./Utilities/TlsCerts/xnc.log")

0 commit comments

Comments
 (0)