def main(): preserveconfig = True # Ask the user how many nodes that rack has #nodesnum = helper.askNodeQuantity() nodesnum = 10 if preserveconfig is True: while True: # Ask for the username and password of BMC username = input('What is the username of the BMC? ') if username != 'admin': print( "This toolkit only supports \"admin\" account for restoration. If another account is used, please manually create the account. Exiting." ) return False password = input('What is the password of the BMC? ') print('You have entered ' + str(username) + ' and ' + str(password) + ' ') response = input( 'Is this correct? (Enter y for yes or n for no): ') if 'y' in response: print('Perfect! Let\'s move on.') break else: print('Re-asking questions.') # Get the existing nodes #if preserveconfig is True: # # Discover with existing details # nodes = autodiscover.discover(nodesnum, [username], [password]) #else: # # Discover with default details # nodes = autodiscover.discover(nodesnum) nodes = [quantaskylake.DS120('10.76.38.85', 'admin', 'cmb9.admin')] #nodes = [quantaskylake.DS120('fe80::dac4:97ff:fe17:6e7c%ens160', 'admin', 'cmb9.admin')] #nodes = [quantaskylake.DS120('fe80::dac4:97ff:fe17:6e7c', 'admin', 'cmb9.admin')] #nodes = ['fe80::dac4:97ff:fe17:6e7c%ens160'] #r = firmware('fe80::dac4:97ff:fe17:6e7c%ens160', 'admin', 'cmb9.admin') #r.printfirmwareselection("DS120") # Start the firmware object f = firmware() # Ask the user which vSphere version so we can flash the DS120/220 with appropriate firmware. while True: print( '\nWhich appliance are you going to install? (Note: Entering UCP is the default option)\n' ) f.printesxiselection() date = input('Enter the date and/or version (if any): ') if len(f.returnesxiselection(date)) < 1: print('I couldn\'t find this selection. Please try again.') else: print('\nThis selection has the following firmwares:') f.printesxiselection(date) firmwareselection = f.returnesxiselection(date) break
def discoverNodeType(IPv6node, username, password): # Output the address, username and password temp = IPv6node + ' ' + username + ' ' + password print('Start ' + temp) # Set the address # Also %25 has to be used for URLs instead of % due to URL Encoding rules. redfishapi = 'https://[' + IPv6node.replace('%', '%25') + ']/redfish/v1/' # Have to remove the lin-local zone ID for correct curl command redfishheader = { 'Content-Type': 'application/json', 'User-Agent': 'curl/7.54.0', 'Host': '[' + IPv6node.split('%')[0] + ']' } # Attempt to connect try: session = requests.get(redfishapi + 'Systems', auth=(username, password), verify=False, headers=redfishheader, timeout=30) except: print('Finish ' + temp) return None # If Session is not good, return nothing if not session.ok: print('Finish ' + temp) return None try: # Attempt to decode JSON data j = session.json() except: # If return data isn't JSON, return nothing. return None print('Data ' + IPv6node + ' ' + str(j)) ''' Get first member ''' # Attempt to get Members try: members = j['Members'] except: return None # Loop through members and get first member for member in members: try: redfishapi = 'https://[' + IPv6node.replace( '%', '%25') + ']' + member['@odata.id'] break except: # Return nothing if @odata.id key doesn't exist return None ''' Discover which type of node this is ''' # Try to get first member details try: session = requests.get(redfishapi, auth=(username, password), verify=False, headers=redfishheader, timeout=30) except: print('Finish ' + temp) return None # If Session is not good, return nothing if not session.ok: print('Finish ' + temp) return None # Attempt to decode JSON data try: j = session.json() except: # If return data isn't JSON, return nothing. print('Finish ' + temp) return None print('Data ' + IPv6node + ' ' + str(j)) # Attempt to get SKU Data try: SKU = j['SKU'] except: print('Finish ' + temp) return None # Decode which node this is # If its a D52B Series, return Skylake Server if 'DS120' in SKU: print('Finish ' + temp) return quantaskylake.DS120(IPv6node, username, password) elif 'DS220' in SKU: print('Finish ' + temp) return quantaskylake.DS220(IPv6node, username, password) elif 'DS225' in SKU: print('Finish ' + temp) return quantaskylake.DS225(IPv6node, username, password) elif 'DS240' in SKU: print('Finish ' + temp) return quantaskylake.DS240(IPv6node, username, password) elif 'D52BV' in SKU: print('Finish ' + temp) return quantaskylake.D52BV(IPv6node, username, password) elif 'D52B' in SKU: print('Finish ' + temp) return quantaskylake.D52B(IPv6node, username, password) elif 'Q72D' in SKU: print('Finish ' + temp) return quantaskylake.Q72D(IPv6node, username, password) else: # If it doesn't match anything, return nothing print('Finish ' + temp) return None
def main(): preserveconfig = True # Ask the user how many nodes that rack has #nodesnum = helper.askNodeQuantity() nodesnum = 10 if preserveconfig is True: while True: # Ask for the username and password of BMC username = input('What is the username of the BMC? ') if username != 'admin': print( "This toolkit only supports \"admin\" account for restoration. If another account is used, please manually create the account. Exiting." ) return False password = input('What is the password of the BMC? ') print('You have entered ' + str(username) + ' and ' + str(password) + ' ') response = input( 'Is this correct? (Enter y for yes or n for no): ') if 'y' in response: print('Perfect! Let\'s move on.') break else: print('Re-asking questions.') # Get the existing nodes #if preserveconfig is True: # # Discover with existing details # nodes = autodiscover.discover(nodesnum, [username], [password]) #else: # # Discover with default details # nodes = autodiscover.discover(nodesnum) nodes = [quantaskylake.DS120('10.76.38.91', 'admin', 'cmb9.admin')] #nodes = [quantaskylake.DS120('fe80::dac4:97ff:fe17:6e7c%ens160', 'admin', 'cmb9.admin')] #nodes = [quantaskylake.DS120('fe80::dac4:97ff:fe17:6e7c', 'admin', 'cmb9.admin')] #nodes = ['fe80::dac4:97ff:fe17:6e7c%ens160'] #r = firmware('fe80::dac4:97ff:fe17:6e7c%ens160', 'admin', 'cmb9.admin') #r.printfirmwareselection("DS120") # Start the firmware object f = firmware() # Start MiniOS Logic badtime.seperate() print("\nStarting PCI Device Firmware Flashing\n") print('Setting MiniOS BIOS Default') processes = [] for node in nodes: processes.append( multiprocessing.Process(target=node.setMiniOSDefaults2())) # Start threads for process in processes: process.start() time.sleep(1) # Wait for threads for process in processes: process.join() #vmcli_nodes = copy.deepcopy(nodes) #vmcli_nodes = helper.massStartVMCLI(vmcli_nodes, minios.getminiosiso()) print('Powering on the nodes to start MiniOS') processes = [] for node in nodes: processes.append(multiprocessing.Process(target=node.poweron)) # Start threads for process in processes: process.start() # Slowly power-on nodes to not overload circuit time.sleep(2) # Wait for threads for process in processes: process.join() print("\nCreating MiniOS Instances") minioses = [] for node in nodes: minioses.append(minios.minios(node)) print("\nAttempting to login into all MiniOS Instances") for minios_instance in minioses: minios_instance.login() time.sleep(30) print(" Jenny, I am here now") print("\nDiscovering All PCI Devices in all MiniOS Instances") temp_minioses = [] with concurrent.futures.ThreadPoolExecutor(max_workers=32) as executor: futures = [ executor.submit(miniospcidiscoverwrapper, minios_instance) for minios_instance in minioses ] for future in concurrent.futures.as_completed(futures): temp_minioses.append(future.result()) minioses = temp_minioses for minios_instance in minioses: minios_instance.printPCIDevices() # Ask the user which vSphere version so we can flash the DS120/220 with appropriate firmware. while True: print( '\nWhich appliance are you going to install? (Note: Entering UCP is the default option)\n' ) f.printesxiselection() date = input('Enter the date and/or version (if any): ') if len(f.returnesxiselection(date)) < 1: print('I couldn\'t find this selection. Please try again.') else: print('\nThis selection has the following firmwares:') f.printesxiselection(date) firmwareselection = f.returnesxiselection(date) break print("\nFlashing All PCI Devices in all MiniOS Instances") temp_minioses = [] with concurrent.futures.ThreadPoolExecutor(max_workers=32) as executor: futures = [ executor.submit(pciflashing, minios_instance, f, firmwareselection) for minios_instance in minioses ] for future in concurrent.futures.as_completed(futures): try: temp_minioses.append(future.result()) except: continue minioses = temp_minioses input("Hit enter to continue") # Power off the nodes for node in nodes: node.poweroff()
import quantaskylake import minios from prettytable import PrettyTable import os node = quantaskylake.DS120('10.76.38.85', 'admin', 'cmb9.admin') test = minios.minios(node) #tset = minios(node) # if this is used, there is an error that module is not callable #test.login() test.discoverPCIDevices2() founddevices = test.printPCIDevices() ''' #print("=================Starting to Upgrade==========================") #pcitest = minios.intelNIC(test, '3d:00') #pcitest.flash("/cdrom/firmware/Intel(R)_Ethrnet_Connection_X722_for_10GbE_SFP+/ON 10GbE X722-X527-DA4 SFP plus_FW-Online-Auto_Linux_0004.zip") #pcitest.flash("/cdrom/firmware/Intel(R)_Ethernet_Connection_X722_for_10GbE_SFP+/2018_WW46_LBG_X722_NUP_UEFI_v0006.zip") #melltext = minios.mellanoxNIC(test, '3d:00') # melltext.flash('/cdrom/firmware/Quanta_S5B_CX4Lx_25G_2P/3GS5BMA0000_MLX_25G_dual_port_14_20_1010_Online.zip') #melltext.flash('/cdrom/firmware/Intel(R)_Ethernet_Connection_X722_for_10GbE_SFP+/2018_WW46_LBG_X722_NUP_UEFI_v0006.zip') founddevices = test.printPCIDevices2() print(node.host + " Discovered the following PCI Devices:") t = PrettyTable(["PCI_Address", "Name", "Firmware", "Serial", "VID", "DVID", "SVID", "SSID"]) t.sortby = "PCI_Address" for device2, pciclass2 in founddevices.items(): print(node.host + ' In Loop --- Discovered PCI Device: ' + device2 + ' ' + pciclass2.name + ' v.' + pciclass2.firmware) # This path is relative to the MiniOS for ch in ['(', ')']:
def discoverNodeType(IPv6node, username, password): # Output the address, username and password temp = IPv6node + ' ' + username + ' ' + password print('Start ' + temp) # Check if IPMI Port is Open # https://stackoverflow.com/questions/4030269/why-doesnt-a-en0-suffix-work-to-connect-a-link-local-ipv6-tcp-socket-in-python addrinfo = socket.getaddrinfo(IPv6node, 623, socket.AF_INET6, socket.SOCK_STREAM) (family, socktype, proto, canonname, sockaddr) = addrinfo[0] sock = socket.socket(family, socktype, proto) sock.settimeout(0.1) result = sock.connect_ex(sockaddr) sock.close() if result == 0: print('IPMI ' + IPv6node) else: print('NoIPMI ' + IPv6node) return None # Set the address # Also %25 has to be used for URLs instead of % due to URL Encoding rules. redfishapi = 'https://[' + IPv6node.replace('%', '%25') + ']/redfish/v1/' # Have to remove the lin-local zone ID for correct curl command redfishheader = { 'Content-Type': 'application/json', 'User-Agent': 'curl/7.54.0', 'Host': '[' + IPv6node.split('%')[0] + ']' } # Attempt to login with two passwords passwords = [ password, lawcompliance.passwordencode(IPv6node, getPassword()) ] session = None members = None for password in passwords: # Let user know we are checking this username and password temp = IPv6node + ' ' + username + ' ' + password print("Check " + temp) # Attempt to connect. If specific force password change is required, change password. try: session = requests.get(redfishapi + 'Systems', auth=(username, password), verify=False, headers=redfishheader, timeout=30) try: j = session.json() if j['error']['code'] == "Base.1.0.PasswordChangeFromIPMI": # Create a temp node and update the password. Destroy Node tempNode = quantaskylake.QuantaSkylake( IPv6node, 'admin', 'cmb9.admin') password = lawcompliance.passwordencode( IPv6node, getPassword()) # tempNode.forcePasswordChange(password) print("CPASS " + IPv6node + " Changing Password to " + password) tempNode.forcePasswordChange(password) del tempNode except: pass try: members = j['Members'] break except: pass except: print('NoRF ' + temp) continue ''' # If Session is not good, return nothing if not session.ok: print('NoRF ' + temp) session = None continue else: break ''' # Return nothing if nothing is found if session is None or members is None: return None print('RFDATA ' + IPv6node + ' ' + str(j)) # Loop through members and get first member for member in members: try: redfishapi = 'https://[' + IPv6node.replace( '%', '%25') + ']' + member['@odata.id'] break except: # Return nothing if @odata.id key doesn't exist return None ''' Discover which type of node this is ''' # Try to get first member details try: session = requests.get(redfishapi, auth=(username, password), verify=False, headers=redfishheader, timeout=30) except: print('Error ' + temp) return None # If Session is not good, return nothing if not session.ok: print('Error ' + temp) return None # Attempt to decode JSON data try: j = session.json() except: # If return data isn't JSON, return nothing. print('Error ' + temp) return None print('RFDATA ' + IPv6node + ' ' + str(j)) # Attempt to get SKU Data try: SKU = j['SKU'] except: print('NOSKU ' + temp) return None if ' ' is SKU: cmd = 'ipmitool -I lanplus -H ' + IPv6node + ' -U ' + username + ' -P ' + password + ' fru print' session = PopenSpawn(cmd) output = session.read(2000) output = output.decode('utf-8') if 'Error' in output: print('ErrIPMI ' + temp) return None lines = output.splitlines() for line in lines: if 'Product Name' in line: try: SKU = line.split(':', 1)[1].strip() break except: continue # Decode which node this is # If its a D52B Series, return Skylake Server if 'DS120' in SKU: print('Found ' + temp) return quantaskylake.DS120(IPv6node, username, password) elif 'DS220' in SKU: print('Found ' + temp) return quantaskylake.DS220(IPv6node, username, password) elif 'DS225' in SKU: print('Found ' + temp) return quantaskylake.DS225(IPv6node, username, password) elif 'DS240' in SKU: print('Found ' + temp) return quantaskylake.DS240(IPv6node, username, password) elif 'D52BV' in SKU: print('Found ' + temp) return quantaskylake.D52BV(IPv6node, username, password) elif 'D52B' in SKU: print('Found ' + temp) return quantaskylake.D52B(IPv6node, username, password) elif 'Q72D' in SKU: print('Found ' + temp) return quantaskylake.Q72D(IPv6node, username, password) else: # If it doesn't match anything, return nothing print('QError ' + temp + ' SKU=\'' + SKU + '\'') return None