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
def saveFile(filename, contents): | |
''' Save the contents to a file in the PWD. | |
''' | |
try: | |
f = open(filename, 'w+') | |
f.write(contents) | |
f.close() | |
except Exception as e: | |
print(e) |
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
def netconfconn(nodeip,ncusername,ncpassword): | |
conn = manager.connect(host=nodeip, | |
port=830, | |
username=ncusername, | |
password=ncpassword, | |
hostkey_verify=False, | |
device_params={'name':'alu'}) | |
return conn |
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
def createFolder(directory): | |
try: | |
if not os.path.exists(directory): | |
os.makedirs(directory) | |
except OSError: | |
print('Error: Creating directory. ' + directory) |
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
def globfindfile(regex): | |
''' This function will simply locate a file in the DIR by passing the directory/regex value (ie:(*.log)) | |
The returned value by calling the function is the file. | |
''' | |
try: | |
if len(glob.glob(regex)) == 0: | |
sys.exit(f"No {regex} file found.") | |
else: | |
for file in glob.glob(regex): | |
if len(glob.glob(regex)) > 1: |
NewerOlder