-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TLS NXAPI Script and NDBActivator3.0_I5_Plus
- Loading branch information
ciscodatacenter
committed
Oct 17, 2017
1 parent
0f9b367
commit e85961a
Showing
8 changed files
with
2,046 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import os | ||
import sys | ||
import yaml | ||
import requests | ||
import subprocess | ||
import logging | ||
import paramiko | ||
# pylint: disable-msg=E0611 | ||
from requests.packages.urllib3.exceptions import InsecureRequestWarning | ||
from requests.packages.urllib3.exceptions import SNIMissingWarning | ||
requests.packages.urllib3.disable_warnings(InsecureRequestWarning) | ||
requests.packages.urllib3.disable_warnings(SNIMissingWarning) | ||
|
||
class Server: | ||
def __init__(self): | ||
self.conn_type = "https" | ||
with open(INPUTFILE) as file_ptr: | ||
confi = yaml.safe_load(file_ptr) | ||
self.server_ip = confi['ServerIP']['ServerIP1']['ip'] | ||
self.username = confi['ServerIP']['ServerIP1']['user'] | ||
self.password = confi['ServerIP']['ServerIP1']['password'] | ||
self.port = '8443' | ||
self.web_url = "" | ||
self.login_url = "" | ||
self.add_device_url = "" | ||
self.device_response = 0 | ||
self.xnc_pwd = str(confi['xnc_password']) | ||
self.xnc_usr = str(confi['xnc_username']) | ||
def ndb_servrer_login(self, device_info): | ||
try: | ||
self.web_url = self.conn_type+"://"+self.server_ip+":"\ | ||
+self.port+"/monitor/" | ||
self.login_url = self.conn_type+"://"+self.server_ip+":"\ | ||
+self.port+"/monitor/j_security_check" | ||
login_payload = {"j_username" : self.xnc_usr, "j_password" : self.xnc_pwd} | ||
with open(INPUTFILE) as file_ptr: | ||
dev_info = yaml.safe_load(file_ptr) | ||
add_device_payload = device_info | ||
add_device_payload['connectiontype'] = 'NXAPI' | ||
add_device_payload['auxnode'] = 'false' | ||
for key in add_device_payload: | ||
add_device_payload[key] = str(add_device_payload[key]) | ||
self.add_device_url = str(self.conn_type+"://"+\ | ||
str(self.server_ip)+":"+str(self.port)+\ | ||
"/controller/web/devices/extended//element/add") | ||
#pylint: disable=maybe-no-member | ||
with requests.session() as ses: | ||
ses.get(self.web_url, verify=False) | ||
ses.post(self.login_url, data=login_payload, verify=False) | ||
ses.post(self.add_device_url, data=add_device_payload, verify=False) | ||
LOGGER.info("Device - "+add_device_payload['address']+\ | ||
" Device added successfully") | ||
except paramiko.SSHException: | ||
LOGGER.error("Device - "+add_device_payload['address']+\ | ||
" Failed to add device in NDB") | ||
if __name__ == "__main__": | ||
FILE1 = '/etc/ssh/ssh_config' | ||
DIR = os.path.dirname(__file__) | ||
#sys.stdout = os.devnull | ||
if not os.path.isdir('./Utilities/Log'): | ||
os.mkdir("./Utilities/Log") | ||
#sys.stdout = open(os.devnull, "w") | ||
if len(sys.argv) == 1: | ||
FILENAME = os.path.join(DIR, './Utilities/Log/Logfile.log') | ||
LOGGER = logging.getLogger(__name__) | ||
LOGGER.setLevel(logging.DEBUG) | ||
CON_LOG_HANDLER = logging.StreamHandler() | ||
FILE_LOG_HANDLER = logging.FileHandler(FILENAME) | ||
FILE_LOG_HANDLER.setLevel(logging.DEBUG) | ||
CON_LOG_HANDLER.setLevel(logging.DEBUG) | ||
FORMATTER = logging.Formatter( | ||
'%(asctime)s - %(name)s - %(levelname)s - %(message)s') | ||
FILE_LOG_HANDLER.setFormatter(FORMATTER) | ||
CON_LOG_HANDLER.setFormatter(FORMATTER) | ||
LOGGER.addHandler(FILE_LOG_HANDLER) | ||
LOGGER.addHandler(CON_LOG_HANDLER) | ||
elif len(sys.argv) == 2: | ||
if '--quiet' in sys.argv: | ||
FILENAME = os.path.join(DIR, './Utilities/Log/Logfile.log') | ||
LOGGER = logging.getLogger(__name__) | ||
LOGGER.setLevel(logging.DEBUG) | ||
FILE_LOG_HANDLER = logging.FileHandler(FILENAME) | ||
FILE_LOG_HANDLER.setLevel(logging.DEBUG) | ||
FORMATTER = logging.Formatter( | ||
'%(asctime)s - %(name)s - %(levelname)s - %(message)s') | ||
FILE_LOG_HANDLER.setFormatter(FORMATTER) | ||
LOGGER.addHandler(FILE_LOG_HANDLER) | ||
else: | ||
FILENAME = os.path.join(DIR, './Utilities/Log/Logfile.log') | ||
LOGGER = logging.getLogger(__name__) | ||
LOGGER.setLevel(logging.DEBUG) | ||
CON_LOG_HANDLER = logging.StreamHandler() | ||
FILE_LOG_HANDLER = logging.FileHandler(FILENAME) | ||
FILE_LOG_HANDLER.setLevel(logging.DEBUG) | ||
CON_LOG_HANDLER.setLevel(logging.DEBUG) | ||
FORMATTER = logging.Formatter( | ||
'%(asctime)s - %(name)s - %(levelname)s - %(message)s') | ||
FILE_LOG_HANDLER.setFormatter(FORMATTER) | ||
CON_LOG_HANDLER.setFormatter(FORMATTER) | ||
LOGGER.addHandler(FILE_LOG_HANDLER) | ||
LOGGER.addHandler(CON_LOG_HANDLER) | ||
LOGGER.error(" Run python script without arguments or along "+\ | ||
"with --quiet argument") | ||
sys.exit(0) | ||
else: | ||
LOGGER.error(" Run python script without arguments or along "+\ | ||
"with --quiet argument") | ||
sys.exit(0) | ||
if '--quiet' in sys.argv: | ||
subprocess.call(" python TLSScript.py --quiet", shell=True) | ||
subprocess.call(" python OpenSSL.py --quiet", shell=True) | ||
else: | ||
subprocess.call(" python TLSScript.py 1", shell=True) | ||
subprocess.call(" python OpenSSL.py 1", shell=True) | ||
INPUTFILE = os.path.join(DIR, './Utilities/Input/inputfile.yaml') | ||
DEV = Server() | ||
with open(INPUTFILE) as f: | ||
DEVICE_INFO = yaml.safe_load(f) | ||
for dic in sorted(DEVICE_INFO['IP'].keys()): | ||
DEV.ndb_servrer_login(DEVICE_INFO['IP'][dic]) | ||
os.system("rm -rf ./Utilities/TlsCerts/temp") | ||
os.system("rm -rf ./Utilities/TlsCerts/xnc.log") |
Oops, something went wrong.