def usage(): utilities.reporter("\r\nUsage: ", 'red') print("python " + sys.argv[0] + " bfdell01 10.7.15.1") utilities.reporter( "\r\nYou can run few servers in parallel.\r\nThen save the results in file or print the output in your local machine\r\n", 'red') exit(2) #close the app
def save_objects_in_file(setup): try: file_path = "/.autodirect/QA/qa/smart_nic/debug_files_eliad/servers_details_" + str( datetime.date.today()) + ".txt" f = open(file_path, "w+") except: print("Fail to create the file: " + file_path) for host in setup: try: f.write("HostName: %s\r\n" % (str(host.instance.ip))) f.write("Ofed Info: %s\r\n" % (str(host.instance.ofed_info))) f.write("MST Version: %s\r\n" % (str(host.instance.mst_version))) f.write("MST Device: %s\r\n" % (str(host.instance.mst_device))) f.write("FW Version: %s\r\n" % (str(host.instance.fw))) f.write("Rom Info: %s\r\n" % (str(host.instance.exp_rom))) f.write("PCI: %s\r\n" % (str(host.instance.pci))) f.write("Board Id: %s\r\n" % (str(host.instance.board_id))) f.write("Part Number: %s\r\n" % (str(host.instance.part_number))) f.write("------------------------------------------\n") except: #f.write("HostName: %s\r\n" % (str(host.ip))) f.write("Fail to save the content of this host\r\n") f.write("------------------------------------------\n") print("\r\n------------------------------------------\n") utilities.reporter("Check running report in: " + file_path + "\n", 'green') print("------------------------------------------\n") f.close()
def driver_action(host_obj, action): cmd = "etc/init.d/openibd " + action try: return host_obj.run_cmd(cmd, 0, 1, 1) except: utilities.reporter("Driver action failed: " + cmd + "\n", 'red') return None
def install_driver(host_obj, action): try: host_obj.run_cmd(action, 0, 1, 1, INSTALLATION_LOG) action = 'cat ' + INSTALLATION_LOG + " | grep -i '/etc/init.d/openibd restart'" res = host_obj.run_cmd(action, 0, 1, 1) if res: return True else: return False except: utilities.reporter("install failed: " + action + "\n", 'red') return False
def print_content(self): utilities.reporter("Printing the attributes of Host_linux Object:",'bold') try: print ("Host Name: " + self.ip + "\n" + "Ofed Info: " + self.ofed_info + "\n" + "MST Version: " + self.mst_version + "\n" + "MST Device: " + self.mst_device + "\n" + "FW Version: " + self.fw + "\n" + "Rom Info: " + self.exp_rom + "\n" + "PCI: " + self.pci + "\n" + "Board Id: " + self.board_id + "\n" + "Part Number: " + self.part_number + "\n" + "------------------------------------------\n") except: print("Fail to print the object attributes!\n" + "------------------------------------------\n")
def __init__(self,host_ip): err=0 print ("------------------------------------------") utilities.reporter("Start to build host_linux object of host: "+host_ip,'blue') try: client = paramiko.Transport((host_ip, PORT)) client.connect(username=USERNAME, password=PASSWORD) except: utilities.reporter("No connection to host: "+host_ip+" -> Object not created!",'red') print ("------------------------------------------\n") return None try: #session = client.open_channel(kind='session') #output = utilities.run_command_on_session(session,'hostname') self.ip = host_ip time.sleep(0.5) except: utilities.reporter("Cant pull the hostname with command: hostname",'red') self.ip = 'Cant pull the hostname with command: hostname' err=1 try: session = client.open_channel(kind='session') output = utilities.run_command_on_session(session,'mst start') time.sleep(0.5) except: print("Fail to run the command: mst start") return None try: session = client.open_channel(kind='session') output = utilities.run_command_on_session(session,'ofed_info -s') self.ofed_info = re.findall('\w+\-(\d\.\d\-\d\.\d\.\d+\.\d)', output)[0] time.sleep(0.5) except: print("Fail to pull the ofed version") self.ofed_info = "Fail to pull the ofed version" err=1 try: session = client.open_channel(kind='session') output = utilities.run_command_on_session(session,'mst version') self.mst_version = re.findall('mst\W+mft\s(\d\.\d+\.\d\-\d+).*', output)[0] time.sleep(0.5) except: print("Fail to pull the mst version") self.mst_version = "Fail to pull the mst version" err=1 try: session = client.open_channel(kind='session') output = utilities.run_command_on_session(session,'mst status -v') self.mst_device = re.findall('\W+(/dev/mst/mt\d+\_\w+\d).*', output)[0] time.sleep(0.5) except: print("Fail to pull the mst device with command: mst status -v") self.mst_device = "Fail to pull the mst device with command: mst status -v" err=1 try: session = client.open_channel(kind='session') output = utilities.run_command_on_session(session,"flint -d "+self.mst_device+" q | grep -i fw | grep -i version") self.fw = re.findall('FW\sVersion\:\s+(\d{2}\.\d{2}\.\d{4})', output)[0] time.sleep(0.5) except: print("Fail to pull the FW version with flint query") self.fw = "Fail to pull the FW version with flint query" err=1 try: session = client.open_channel(kind='session') output = utilities.run_command_on_session(session,"flint -d "+self.mst_device+" q | grep -i rom") self.exp_rom = re.findall('Rom\sInfo\:\s+(.*)', output)[0] time.sleep(0.5) except: print("Fail to pull the Rom Info with flint query") self.exp_rom = "Fail to pull the Rom Info with flint query" err=1 try: session = client.open_channel(kind='session') output = utilities.run_command_on_session(session,'mst status -v') self.pci = re.findall('(\d{2}\:\d{2}\.0).*', output)[0] time.sleep(0.5) except: print("Fail to pull the PCI with mst status command") self.pci = "Fail to pull the PCI with mst status command" err=1 try: session = client.open_channel(kind='session') output = utilities.run_command_on_session(session,'mlxburn -d '+self.mst_device+' -vpd') self.board_id = re.findall('.*Board\sId\s+(.*)', output)[0] time.sleep(0.5) except: print("Fail to pull the board id with mlxburn -d <device> -vpd") self.board_id = "Fail to pull the board id with mlxburn -d <device> -vpd" err=1 try: session = client.open_channel(kind='session') output = utilities.run_command_on_session(session,'mlxburn -d '+self.mst_device+' -vpd') self.part_number = re.findall('.*Part\sNumber\s+(.*)', output)[0] time.sleep(0.5) except: print("Fail to pull the part number with mlxburn -d <device> -vpd") self.part_number = "Fail to pull the part number with mlxburn -d <device> -vpd" err=1 utilities.reporter("host_linux object created successfully!",'green') if err: utilities.reporter("1 or more fields is missing in this host_linux object!",'red')