python
2 days, 12 hours ago
import re
import subprocess
import sys
import shutil
import time
if len(sys.argv) != 2:
print('Please pass the servername\nEx: python compare_connections.py <SITE>')
exit(1)
width = shutil.get_terminal_size((70, 30)).columns
if width < 120:
input("Please maximize the terminal window for better display and Enter:")
dest = sys.argv[1]
def get_console_out(command, shell=False):
result = subprocess.run(command, shell=shell, stdout=subprocess.PIPE)
lines = result.stdout.decode('utf-8').split("\n")
return lines
hostname = get_console_out("hostname", shell=True)[0]
server_no = (int(hostname[-3:])-1)*2
sources = {
'idrac': {'dest': f'{dest}401to1', 'dest_itf': 'GigabitEthernet0/0/0/0'},
'eno3': {'dest': f'{dest}401to1', 'dest_itf': f'GigabitEthernet0/0/0/{int(hostname[-3:])+5}'},
'enp94s0f0': {'dest': f'{dest}401to1', 'dest_itf': f'TenGigE0/0/0/{server_no+12}'},
'enp216s0f0': {'dest': f'{dest}402to1', 'dest_itf': f'TenGigE0/0/0/{server_no+12}'},
'enp94s0f1': {'dest': f'{dest}401to1', 'dest_itf': f'TenGigE0/0/0/{server_no+13}'},
'enp216s0f1': {'dest': f'{dest}402to1', 'dest_itf': f'TenGigE0/0/0/{server_no+13}'},
}
RED = "\033[31m"
GREEN = "\033[32m"
YELLOW = "\033[33m"
RESET = "\033[0m"
def print_headers():
print(f"{'#':<5} {'Check':<25} {'Expected':<40} {'Installed':<40} {'Result':<10}")
print("-" * 120)
counter = 0
def print_row(ch, ex, ins, res):
global counter
counter += 1
print(f"{counter:<5} {ch:<25} {ex:<40} {ins:<40} {res:<10}")
print('\n')
print('-'*120)
print("Hardware Validations")
print_headers()
cpu_lines = get_console_out(["racadm", "get", "BIOS.ProcSettings"])
for line in cpu_lines:
if "NumCores" in line:
cpu_cores = int(line.split('=')[1])
if cpu_cores > 22:
print_row("CPU Cores", "Min 22", cpu_cores, YELLOW + "WARNING" + RESET)
elif cpu_cores == 22:
print_row("CPU Cores", "Min 22", cpu_cores, GREEN + "PASSED" + RESET)
else:
print_row("CPU Cores", "Min 22", cpu_cores, RED + "FAILED" + RESET)
# if re.findall('Proc[0-9]+Brand', line):
# print(line)
memory_lines = get_console_out(["racadm", "get", "BIOS.MemSettings"])
for line in memory_lines:
if "SysMemSize" in line:
if "384 GB" not in line:
print_row("Memory", "384GB", line, RED + "FAILED" + RESET)
else:
print_row("Memory", "384GB", "384 GB", GREEN + "PASSED" + RESET)
slots = get_console_out(["racadm", "get", "NIC.NICConfig"])
valid_slots = ["NIC.Slot.3-1-1", "NIC.Slot.3-2-1", "NIC.Slot.8-1-1", "NIC.Slot.8-2-1"]
slots_present = []
for line in slots:
if "Slot" in line:
slots_present.append(re.findall("NIC\.Slot\.[0-9]+-[0-9]+-[0-9]+", line)[0])
nn = 1
for slot in valid_slots:
if slot not in slots_present:
print_row("NIC Slot", slot, "Not Present", RED + "FAILED" + RESET)
else:
print_row("NIC Slot", slot, slot, GREEN + "PASSED" + RESET)
nn += 1
'''
card_out = get_console_out("/usr/bin/lshw -businfo | /bin/grep 5e:00.0 |/usr/bin/awk '{print $4}'|/bin/sed 's/^ *//g'", shell=True)
if card_out and card_out[0].strip() in ["MT28800", "MT28841"]:
print_row("Correct Card", "MT28800 / MT28841", card_out[0].strip(), GREEN + "PASSED" + RESET)
else:
print_row("Correct Card", "MT28800 / MT28841", card_out[0].strip(), RED + "FAILED" + RESET)
'''
dim_lines = get_console_out("dmidecode -t 17", shell=True)
dims = []
cur_dim = None
for dim_line in dim_lines:
cur_line = dim_line.strip()
if "Handle" in cur_line and "DMI type" in cur_line:
cur_dim = [cur_line]
if "Size" in cur_line and "No Module Installed" not in cur_line:
cur_dim.append(cur_line)
elif "Size" in cur_line and "No Module Installed" in cur_line:
cur_dim = None
if cur_dim and "Locator" in cur_line:
cur_dim.append(cur_line)
dims.append(cur_dim)
cur_dim = None
if len(dims) == 12:
print_row("DIM Slots Count", 12, 12, GREEN + "PASSED" + RESET)
else:
print_row("DIM Slots Count", 12, len(dims), RED + "FAILED" + RESET)
for dim in dims:
if "32 GB" not in dim[1]:
print_row("DIM Memory", "32 GB", dim[1].replace("Size:", "").strip(), RED + 'FAILED' + RESET)
# print_row("DIM Memory", "32 GB", dim[0].split(",")[0]+" "+dim[1], RED + 'FAILED' + RESET)
else:
print_row("DIM Memory", "32 GB", dim[1].replace("Size:", "").strip(), GREEN + 'PASSED' + RESET)
raid_slot = get_console_out(["racadm", "storage", "get", "controllers"], shell=False)
if "RAID.Slot.6-1" in raid_slot[0]:
print_row("RAID Slot", "RAID.Slot.6-1", "RAID.Slot.6-1", GREEN + "PASSED" + RESET)
else:
print_row("RAID Slot", "RAID.Slot.6-1", re.findall("RAID\.Slot\.[0-9]+\-[0-9]+", raid_slot[0])[0], RED + "FAILED" + RESET)
hw_disks = get_console_out("/bin/racadm storage get pdisks|grep Disk|wc -l", shell=True)
if hw_disks[0].strip() in ["4", "16"]:
print_row("HW Disk Count", "4 or 16", hw_disks[0].strip(), GREEN + "PASSED" + RESET)
else:
print_row("HW Disk Count", "4 or 16", hw_disks[0].strip(), RED + "FAILED" + RESET)
counter = 0
print('\n')
print('-'*120)
print("Software Validations")
print_headers()
BIOS_firmware = get_console_out("/bin/racadm getversion -f bios|sed -n 1p|awk -F= '{print $2}'|/bin/sed 's/^ *//g'", shell=True)
BIOS_firmware = [i for i in BIOS_firmware if i and i.strip()!=""]
if BIOS_firmware and BIOS_firmware[0].strip() == "2.21.2":
print_row("BIOS firmware", "2.21.2", "2.21.2", GREEN + "PASSED" + RESET)
else:
print_row("BIOS firmware", "2.21.2", BIOS_firmware[0], RED + "FAILED" + RESET)
iDRAC_firmware = get_console_out(["/bin/racadm getversion -f lc |sed -n 1p|awk -F= '{print $2}'|/bin/sed 's/^ *//g'"], shell=True)
if iDRAC_firmware and iDRAC_firmware[0].strip() == "7.00.00.172":
print_row("iDRAC firmware", "7.00.00.172", "7.00.00.172", GREEN + "PASSED" + RESET)
else:
print_row("iDRAC firmware", "7.00.00.172", iDRAC_firmware[0], RED + "FAILED" + RESET)
RAID_controller_firmware = get_console_out(["/bin/racadm storage get controllers:RAID.Slot.6-1|/bin/grep -i Firmware|/usr/bin/awk -F= '{print $2}'|/bin/sed 's/^[ \t]*//;s/[ \t]*$//'"], shell=True)
if RAID_controller_firmware and RAID_controller_firmware[0].strip() == "25.5.9.0001":
print_row("RAID controller firmware", "25.5.9.0001", "25.5.9.0001", GREEN + "PASSED" + RESET)
else:
print_row("RAID controller firmware", "25.5.9.0001", RAID_controller_firmware[0], RED + "FAILED" + RESET)
CPLD_firmware = get_console_out(["/bin/racadm getversion -c|sed -n 1p|awk -F= '{print $2}'|/bin/sed 's/^ *//g'"], shell=True)
if CPLD_firmware and CPLD_firmware[0].strip() == "1.1.4":
print_row("CPLD firmware", "1.1.4", "1.1.4", GREEN + "PASSED" + RESET)
else:
print_row("CPLD firmware", "1.1.4", CPLD_firmware[0], RED + "FAILED" + RESET)
nics_order = ['eno1', 'eno2', 'eno3', 'eno4', 'enp94s0f0', 'enp94s0f1', 'enp216s0f0', 'enp216s0f1']
for i in range(1,9):
cmd_out = get_console_out("/bin/racadm get NIC.FrmwImgMenu."+str(i)+"|sed -n 3p|awk -F= '{print $2}'", shell=True)
if cmd_out and i<9:
if cmd_out[0].strip() == "22.5.7":
print_row(nics_order[i-1], "22.5.7", "22.5.7", GREEN + "PASSED" + RESET)
else:
print_row(nics_order[i-1], "22.5.7", cmd_out[0], RED + "FAILED" + RESET)
counter = 0
print('\n')
print('-'*120)
print('Connectivity Validations')
print_headers()
def compare_server(sources):
interfaces = sources
compared = {}
lines = get_console_out(['lldpcli', 'show', 'neighbors'])
for line in lines:
line1 = line.strip()
if "Interface" in line1:
cur_if = line1.replace("Interface:", "").split(",")[0].strip()
compared[cur_if] = []
if "SysName:" in line1:
cur_dest = re.findall(".*40[1-2]+to1", line1.replace("SysName:", "").strip().lower())
if cur_dest:
interfaces[cur_if]['cur_dest'] = cur_dest[0]
if "PortID" in line1:
cur_itf_lst = re.findall(f'{interfaces[cur_if]["dest_itf"][0:-2]}[0-9]+', line1)
cur_itf = cur_itf_lst[0] if cur_itf_lst else '-'
interfaces[cur_if]['cur_itf'] = cur_itf
if interfaces[cur_if]["dest_itf"] in cur_itf and interfaces[cur_if]['cur_dest'] == interfaces[cur_if]['dest'].lower():
interfaces[cur_if]['result'] = GREEN + "PASSED" + RESET
else:
interfaces[cur_if]['result'] = RED + "FAILED" + RESET
return compared
compare_server(sources)
for intf, rec in sources.items():
cur_val = f"{rec.get('cur_dest', '')}:{rec.get('cur_itf', '')}"
if cur_val.strip() == ":":
cur_val = ""
print_row(f"Conn: {intf}", f"{rec['dest']}:{rec['dest_itf']}", cur_val, rec.get('result', RED +'FAILED'+ RESET))
print('\n')
0 Comments
Please Login to Comment Here