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
############# | |
# Dependencies | |
# This base stage just installs the dependencies required for production | |
# without any development deps. | |
ARG PYTHON_VER=3.8 | |
FROM python:${PYTHON_VER} AS base | |
WORKDIR /usr/src/app |
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 simple_excel(workbook, sheetname, keep_vba=False, data_only=True): | |
wb_obj = load_workbook( | |
filename=workbook, keep_vba=keep_vba, data_only=data_only, read_only=True | |
) | |
wsheet = wb_obj[sheetname] | |
data_key = [] | |
for value in wsheet.iter_rows(values_only=True): |
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 get_vrfcli(task, servicename): | |
''' Retrieve VRF from IOSXR | |
''' | |
vrf = task.run(netmiko_send_command, command_string=f"sh vrf {servicename} detail") | |
print_result(vrf) | |
def get_vprncli(task, servicename): | |
''' Retrieve VPRN from Nokia | |
''' | |
vprn = task.run(netmiko_send_command, command_string=f"show service id {servicename} base") |
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 csvbackup(REGEX, FOLDER): | |
""" Find any file with the REGEX pattern in the PWD | |
and send it to assigned FOLDER. | |
""" | |
try: | |
current = os.getcwd() | |
files = glob.iglob(os.path.join(current, REGEX)) | |
DST_FLD = current + '/' + FOLDER | |
for bkup in files: | |
if os.path.isfile(bkup): |
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 get_credentials(): | |
'''prompts user for password and verifies.''' | |
username = input('Enter Username: ') | |
password = None | |
while not password: | |
password = get_pass() | |
password_verify - get_pass('Re-enter Password') | |
if passowrd != password_verify: | |
print('Passwords do not match. Try again') | |
password = None |
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 netmiko_logging(): | |
''' Netmiko Logging - This creates a Log file (NetmikoLog.txt) under a new 'Logging' folder.. Does not overwrite (a+). | |
Log must end in .txt file as the program won't allow two .log files in the CWD. | |
''' | |
create_folder('Logging') | |
open('Logging/NetmikoLog.txt', 'a+') | |
logging.basicConfig(filename='Logging/NetmikoLog.txt', level=logging.DEBUG) | |
logger = logging.getLogger("netmiko") |
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 dictconvert(lst): | |
res_dct = {lst[i]: lst[i + 1] for i in range(0, len(lst), 2)} | |
return res_dct |
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 get_arguments(): | |
parser = argparse.ArgumentParser(description='Command Line Driven Utility To Enable NETCONF\ | |
And MD-CLI on SROS Devices.') | |
parser.add_argument("-n", "--node", help="Target NODE IP", required=True) | |
parser.add_argument("-u", "--user", help="SSH Username", required=False, default='admin') | |
parser.add_argument("-p", "--port", help="NETCONF TCP Port", required=False, default='830') | |
args = parser.parse_args() | |
return args |
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 netcbackup(ip, NETCONF_USER, NETCONF_PASS): | |
''' This function will establish a netconf connection and pull the running config. It will write a temp file, | |
read it and convert the XML to a python dictionary. Once parsed, we'll pull the system name of the device | |
and create a folder structure by hostname and backup the running config. | |
''' | |
try: | |
# Now let's connect to the device via NETCONF and pull the config to validate | |
nc = netconfconn(ip, NETCONF_USER, NETCONF_PASS) | |
# Grab the running configuration on our device, as an NCElement. |
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 get_ip_only(ipadd): | |
''' This function will use REGEX to strip the subnet mask from an IP/MASK addy. | |
''' | |
try: | |
ip = re.sub(r'/.+', '', str(ipadd)) | |
return ip | |
except Exception as e: | |
print(f"Issue striping subnetmask from {ipadd}, {e}") |
NewerOlder