def do_reset(): """ Reset and wait. Returns True on failure. """ if not args.quiet: print "Checking ECME versions..." results, errors = run_command(args, nodes, "get_versions") if errors: print "ERROR: MC reset aborted. Backup partitions not updated." return True for result in results.values(): version = result.ecme_version.lstrip("v") if parse_version(version) < parse_version("1.2.0"): print "ERROR: MC reset is unsafe on ECME version v%s" % version print "Please power cycle the system and start a new fwupdate." return True if not args.quiet: print "Resetting nodes..." results, errors = run_command(args, nodes, "mc_reset", True) if errors: print "ERROR: MC reset failed. Backup partitions not updated." return True return False
def macaddrs_command(args): """get mac addresses from a cluster or host""" args.all_nodes = False tftp = get_tftp(args) nodes = get_nodes(args, tftp) if not args.quiet: print "Getting MAC addresses..." results, errors = run_command(args, nodes, "get_fabric_macaddrs") for node in nodes: if node in results: print "MAC addresses from %s" % node.ip_address for node_id in sorted(results[node]): for port in results[node][node_id]: for mac_address in results[node][node_id][port]: print "Node %s, Port %i: %s" % (node_id, port, mac_address) print if not args.quiet and errors: print "Some errors occured during the command.\n" return len(errors) == 0
def info_basic_command(args): """Print basic info""" tftp = get_tftp(args) nodes = get_nodes(args, tftp) if not args.quiet: print "Getting info..." results, errors = run_command(args, nodes, "get_versions") # Print results node_strings = get_node_strings(args, results, justify=False) for node in nodes: if node in results: result = results[node] # Get mappings between attributes and formatted strings components = COMPONENTS print "[ Info from %s ]" % node_strings[node] print "Hardware version : %s" % result.hardware_version print "Firmware version : %s" % result.firmware_version # var is the variable, string is the printable string of var for var, string in components: if hasattr(result, var): version = getattr(result, var) print "%s: %s" % (string.ljust(20), version) print if not args.quiet and errors: print "Some errors occured during the command.\n" return len(errors) > 0
def write_version_info(args, nodes): """Write the version info (like cxmanage info) for each node to their respective files. """ info_results, _ = run_command(args, nodes, "get_versions") for node in nodes: lines = [ "[ Version Info for Node %s ]" % node.node_id, "ECME IP Address : %s" % node.ip_address ] if node in info_results: info_result = info_results[node] lines.append("Hardware version : %s" % info_result.hardware_version) lines.append("Firmware version : %s" % info_result.firmware_version) # Get mappings between attributes and formatted strings components = COMPONENTS for var, description in components: if hasattr(info_result, var): version = getattr(info_result, var) lines.append("%s: %s" % (description.ljust(20), version)) else: lines.append("No version information could be found.") write_to_file(node, lines)
def fwinfo_command(args): """print firmware info""" tftp = get_tftp(args) nodes = get_nodes(args, tftp) if not args.quiet: print "Getting firmware info..." results, errors = run_command(args, nodes, "get_firmware_info") node_strings = get_node_strings(args, results, justify=False) for node in nodes: if node in results: print "[ Firmware info for %s ]" % node_strings[node] for partition in results[node]: print "Partition : %s" % partition.partition print "Type : %s" % partition.type print "Offset : %s" % partition.offset print "Size : %s" % partition.size print "Priority : %s" % partition.priority print "Daddr : %s" % partition.daddr print "Flags : %s" % partition.flags print "Version : %s" % partition.version print "In Use : %s" % partition.in_use print if not args.quiet and errors: print "Some errors occured during the command.\n" return len(errors) > 0
def write_depth_chart(args, nodes): """Write the depth chart for each node to their respective files.""" depth_results, _ = run_command(args, nodes, "get_depth_chart") for node in nodes: lines = [] # Lines of text to write to file # \n is used here to give a blank line before this section lines.append("\n[ Depth Chart for Node %s ]" % node.node_id) if node in depth_results: depth_chart = depth_results[node] for key in depth_chart: subchart = depth_chart[key] lines.append("To node " + str(key)) # The 'shortest' entry is one tuple, but # the 'others' are a list. for subkey in subchart: if str(subkey) == "shortest": lines.append(" " + str(subkey) + " : " + str(subchart[subkey])) else: for entry in subchart[subkey]: lines.append(" " + str(subkey) + " : " + str(entry)) else: lines.append("Could not get depth chart!") write_to_file(node, lines)
def do_update(): """Updates the EEPROM images""" if(args.eeprom_location == 'node'): for node in nodes: node_hw_ver = node.get_versions().hardware_version if('Uplink' in node_hw_ver): needed_image = 'dual_uplink_node_%s' % (node.node_id % 4) else: needed_image = 'dual_node_%s' % (node.node_id % 4) image = [img for img in args.images if needed_image in img][0] print 'Updating node EEPROM on node %s' % node.node_id if(args.verbose): print ' %s' % image try: node.update_node_eeprom(image) except Exception as err: print 'ERROR: %s' % str(err) return True print '' # for readability else: image = args.images[0] # First node in every slot gets the slot image slot_nodes = [node for node in nodes if node.node_id % 4 == 0] _, errors = run_command( args, slot_nodes, "update_slot_eeprom", image ) if(errors): print 'ERROR: EEPROM update failed' return True return False
def write_fwinfo(args, nodes): """Write information about each node's firware partitions to its respective file. """ results, _ = run_command(args, nodes, "get_firmware_info") for node in nodes: lines = [] # Lines of text to write to file # \n is used here to give a blank line before this section lines.append("\n[ Firmware Info for Node %s ]" % node.node_id) if node in results: first_partition = True # The first partiton doesn't need \n for partition in results[node]: if first_partition: lines.append("Partition : %s" % partition.partition) first_partition = False else: lines.append("\nPartition : %s" % partition.partition) lines.append("Type : %s" % partition.type) lines.append("Offset : %s" % partition.offset) lines.append("Size : %s" % partition.size) lines.append("Priority : %s" % partition.priority) lines.append("Daddr : %s" % partition.daddr) lines.append("Flags : %s" % partition.flags) lines.append("Version : %s" % partition.version) lines.append("In Use : %s" % partition.in_use) else: lines.append("Could not get firmware info!") write_to_file(node, lines)
def write_depth_chart(args, nodes): """Write the depth chart for each node to their respective files.""" depth_results, _ = run_command(args, nodes, "get_depth_chart") for node in nodes: lines = [] # Lines of text to write to file # \n is used here to give a blank line before this section lines.append("\n[ Depth Chart for Node %s ]" % node.node_id) if node in depth_results: depth_chart = depth_results[node] for key in depth_chart: subchart = depth_chart[key] lines.append("To node " + str(key)) # The 'shortest' entry is one tuple, but # the 'others' are a list. for subkey in subchart: if str(subkey) == "shortest": lines.append( " " + str(subkey) + " : " + str(subchart[subkey]) ) else: for entry in subchart[subkey]: lines.append( " " + str(subkey) + " : " + str(entry) ) else: lines.append("Could not get depth chart!") write_to_file(node, lines)
def ipmitool_command(args): """run arbitrary ipmitool command""" if args.lanplus: ipmitool_args = ['-I', 'lanplus'] + args.ipmitool_args else: ipmitool_args = args.ipmitool_args tftp = get_tftp(args) nodes = get_nodes(args, tftp) if not args.quiet: print "Running IPMItool command..." results, errors = run_command(args, nodes, "ipmitool_command", ipmitool_args) # Print results node_strings = get_node_strings(args, results, justify=False) for node in nodes: if node in results and results[node] != "": print "[ IPMItool output from %s ]" % node_strings[node] print results[node] print if not args.quiet and errors: print "Some errors occured during the command.\n" return len(errors) > 0
def write_mac_addrs(args, nodes): """Write the MAC addresses for each node to their respective files.""" mac_addr_results, _ = run_command( args, nodes, "get_fabric_macaddrs" ) for node in nodes: lines = [] # Lines of text to write to file # \n is used here to give a blank line before this section lines.append("\n[ MAC Addresses for Node %s ]" % node.node_id) if node in mac_addr_results: for node_id in mac_addr_results[node]: for port in mac_addr_results[node][node_id]: for mac_address in mac_addr_results[node][node_id][port]: lines.append( "Node %s, Port %i: %s" % (node.node_id, port, mac_address) ) else: lines.append("\nWARNING: No MAC addresses found!") write_to_file(node, lines)
def write_version_info(args, nodes): """Write the version info (like cxmanage info) for each node to their respective files. """ info_results, _ = run_command(args, nodes, "get_versions") for node in nodes: lines = [ "[ Version Info for Node %s ]" % node.node_id, "ECME IP Address : %s" % node.ip_address ] if node in info_results: info_result = info_results[node] lines.append( "Hardware version : %s" % info_result.hardware_version ) lines.append( "Firmware version : %s" % info_result.firmware_version ) # Get mappings between attributes and formatted strings components = COMPONENTS for var, description in components: if hasattr(info_result, var): version = getattr(info_result, var) lines.append("%s: %s" % (description.ljust(20), version)) else: lines.append("No version information could be found.") write_to_file(node, lines)
def write_crash_log(args, nodes): """Write the crash log for each node""" results, errors = run_command(args, nodes, "read_fru", 99) for node in nodes: lines = ["\n[ Crash log for Node %s ]" % node.node_id] if node in results: lines.append(results[node].strip()) else: lines.append(str(errors[node])) write_to_file(node, lines)
def write_lan_info(args, nodes): """Write LAN info for each node""" results, _ = run_command(args, nodes, "bmc.lan_print") for node in nodes: lines = ["\n[ LAN info for Node %s ]" % node.node_id] for (key, value) in sorted(vars(results[node]).items()): lines.append("%s: %s" % (key, value)) write_to_file(node, lines)
def sensor_command(args): """read sensor values from a cluster or host""" tftp = get_tftp(args) nodes = get_nodes(args, tftp) if not args.quiet: print "Getting sensor readings..." results, errors = run_command(args, nodes, "get_sensors", args.sensor_name) sensors = {} for node in nodes: if node in results: for sensor_name, sensor in results[node].iteritems(): if not sensor_name in sensors: sensors[sensor_name] = [] reading = sensor.sensor_reading.replace("(+/- 0) ", "") try: value = float(reading.split()[0]) suffix = reading.lstrip("%f " % value) sensors[sensor_name].append((node, value, suffix)) except ValueError: sensors[sensor_name].append((node, reading, "")) node_strings = get_node_strings(args, results, justify=True) if node_strings: jsize = len(node_strings.itervalues().next()) for sensor_name, readings in sensors.iteritems(): print sensor_name for node, reading, suffix in readings: try: print "%s: %.2f %s" % (node_strings[node], reading, suffix) except TypeError: print "%s: %s" % (node_strings[node], reading) try: if all(suffix == x[2] for x in readings): minimum = min(x[1] for x in readings) maximum = max(x[1] for x in readings) average = sum(x[1] for x in readings) / len(readings) print "%s: %.2f %s" % ("Minimum".ljust(jsize), minimum, suffix) print "%s: %.2f %s" % ("Maximum".ljust(jsize), maximum, suffix) print "%s: %.2f %s" % ("Average".ljust(jsize), average, suffix) except TypeError: pass print if not args.quiet and errors: print "Some errors occured during the command.\n" return len(errors) > 0
def do_update(): """ Do a single firmware check+update. Returns True on failure. """ if not args.force: if not args.quiet: print "Checking hosts..." _, errors = run_command(args, nodes, "_check_firmware", package, args.partition, args.priority) if errors: print "ERROR: Firmware update aborted." return True if not args.quiet: print "Updating firmware..." _, errors = run_command(args, nodes, "update_firmware", package, args.partition, args.priority) if errors: print "ERROR: Firmware update failed." return True return False
def mcreset_command(args): """reset the management controllers of a cluster or host""" tftp = get_tftp(args) nodes = get_nodes(args, tftp) if not args.quiet: print 'Sending MC reset command...' _, errors = run_command(args, nodes, 'mc_reset') if not args.quiet and not errors: print 'Command completed successfully.\n' return len(errors) > 0
def config_reset_command(args): """reset to factory default settings""" tftp = get_tftp(args) nodes = get_nodes(args, tftp, verify_prompt=True) if not args.quiet: print "Sending config reset command..." _, errors = run_command(args, nodes, "config_reset") if not args.quiet and not errors: print "Command completed successfully.\n" return len(errors) > 0
def power_policy_command(args): """Executes power policy command with args.""" tftp = get_tftp(args) nodes = get_nodes(args, tftp) if not args.quiet: print 'Setting power policy to %s...' % args.policy _, errors = run_command(args, nodes, 'set_power_policy', args.policy) if not args.quiet and not errors: print 'Command completed successfully.\n' return len(errors) > 0
def power_command(args): """change the power state of a cluster or host""" tftp = get_tftp(args) nodes = get_nodes(args, tftp) if not args.quiet: print 'Sending power %s command...' % args.power_mode _, errors = run_command(args, nodes, 'set_power', args.power_mode) if not args.quiet and not errors: print 'Command completed successfully.\n' return len(errors) > 0
def write_boot_order(args, nodes): """Write the boot order of each node to their respective files.""" results, _ = run_command(args, nodes, "get_boot_order") for node in nodes: lines = [] # Lines of text to write to file # \n is used here to give a blank line before this section lines.append("\n[ Boot Order for Node %s ]" % node.node_id) if node in results: lines.append(", ".join(results[node])) else: lines.append("Could not get boot order!") write_to_file(node, lines)
def write_routing_table(args, nodes): """Write the routing table for each node to their respective files.""" routing_results, _ = run_command(args, nodes, "get_routing_table") for node in nodes: lines = [] # Lines of text to write to file # \n is used here to give a blank line before this section lines.append("\n[ Routing Table for Node %s ]" % node.node_id) if node in routing_results: table = routing_results[node] for node_to in table: lines.append(str(node_to) + " : " + str(table[node_to])) else: lines.append("Could not get routing table!") write_to_file(node, lines)
def write_sensor_info(args, nodes): """Write sensor information for each node to their respective files.""" args.sensor_name = "" results, _ = run_command(args, nodes, "get_sensors", args.sensor_name) for node in nodes: lines = ["\n[ Sensors for Node %s ]" % node.node_id] justify_length = max(len(x) for x in results[node]) + 1 for sensor_name, sensor in results[node].items(): lines.append( "%s: %s" % (sensor_name.ljust(justify_length), sensor.sensor_reading)) write_to_file(node, lines)
def write_sensor_info(args, nodes): """Write sensor information for each node to their respective files.""" args.sensor_name = "" results, _ = run_command(args, nodes, "get_sensors", args.sensor_name) for node in nodes: lines = ["\n[ Sensors for Node %s ]" % node.node_id] justify_length = max(len(x) for x in results[node]) + 1 for sensor_name, sensor in results[node].items(): lines.append("%s: %s" % ( sensor_name.ljust(justify_length), sensor.sensor_reading )) write_to_file(node, lines)
def write_mac_addrs(args, nodes): """Write the MAC addresses for each node to their respective files.""" mac_addr_results, _ = run_command(args, nodes, "get_fabric_macaddrs") for node in nodes: lines = [] # Lines of text to write to file # \n is used here to give a blank line before this section lines.append("\n[ MAC Addresses for Node %s ]" % node.node_id) if node in mac_addr_results: for node_id in mac_addr_results[node]: for port in mac_addr_results[node][node_id]: for mac_address in mac_addr_results[node][node_id][port]: lines.append("Node %s, Port %i: %s" % (node.node_id, port, mac_address)) else: lines.append("\nWARNING: No MAC addresses found!") write_to_file(node, lines)
def ipinfo_command(args): """get ip info from a cluster or host""" args.all_nodes = False tftp = get_tftp(args) nodes = get_nodes(args, tftp) if not args.quiet: print "Getting IP addresses..." results, _ = run_command(args, nodes, "get_fabric_ipinfo") for node in nodes: if node in results: print 'IP info from %s' % node.ip_address for node_id, node_address in sorted(results[node].items()): print 'Node %s: %s' % (node_id, node_address) print return 0
def config_boot_command(args): """set A9 boot order""" if args.boot_order == ['status']: return config_boot_status_command(args) validate_boot_args(args.boot_order) tftp = get_tftp(args) nodes = get_nodes(args, tftp) if not args.quiet: print "Setting boot order..." _, errors = run_command(args, nodes, "set_boot_order", args.boot_order) if not args.quiet and not errors: print "Command completed successfully.\n" return len(errors) > 0
def config_pxe_command(args): """set the PXE boot interface""" if args.interface == "status": return config_pxe_status_command(args) validate_pxe_interface(args.interface) tftp = get_tftp(args) nodes = get_nodes(args, tftp) if not args.quiet: print "Setting pxe interface..." _, errors = run_command(args, nodes, "set_pxe_interface", args.interface) if not args.quiet and not errors: print "Command completed successfully.\n" return len(errors) > 0
def write_sel(args, nodes): """Write the SEL for each node to their respective files.""" results, _ = run_command(args, nodes, "get_sel") for node in nodes: lines = [] # Lines of text to write to file # \n is used here to give a blank line before this section lines.append("\n[ System Event Log for Node %s ]" % node.node_id) try: if node in results: for event in results[node]: lines.append(event) # pylint: disable=W0703 except Exception as error: lines.append("Could not get SEL! " + str(error)) if not args.quiet: print("Failed to get system event log for " + node.ip_address) write_to_file(node, lines)
def ipdiscover_command(args): """discover server IP addresses""" tftp = get_tftp(args) nodes = get_nodes(args, tftp) if not args.quiet: print "Getting server-side IP addresses..." results, errors = run_command(args, nodes, "get_server_ip", args.interface, args.ipv6, args.aggressive) if results: node_strings = get_node_strings(args, results, justify=True) print "IP addresses (ECME, Server)" for node in nodes: if node in results: print "%s: %s" % (node_strings[node], results[node]) print if not args.quiet and errors: print "Some errors occurred during the command." return len(errors) > 0
def power_policy_status_command(args): """Executes the power policy status command with args.""" tftp = get_tftp(args) nodes = get_nodes(args, tftp) if not args.quiet: print 'Getting power policy status...' results, errors = run_command(args, nodes, 'get_power_policy') # Print results if results: node_strings = get_node_strings(args, results, justify=True) print 'Power policy status' for node in nodes: if node in results: print '%s: %s' % (node_strings[node], results[node]) print if not args.quiet and errors: print 'Some errors occured during the command.\n' return len(errors) > 0
def config_pxe_status_command(args): """Gets pxe status.""" tftp = get_tftp(args) nodes = get_nodes(args, tftp) if not args.quiet: print "Getting pxe interface..." results, errors = run_command(args, nodes, "get_pxe_interface") # Print results if results: node_strings = get_node_strings(args, results, justify=True) print "PXE interface" for node in nodes: if node in results: print "%s: %s" % (node_strings[node], results[node]) print if not args.quiet and errors: print "Some errors occured during the command.\n" return len(errors) > 0
def config_boot_status_command(args): """Get boot status command.""" tftp = get_tftp(args) nodes = get_nodes(args, tftp) if not args.quiet: print "Getting boot order..." results, errors = run_command(args, nodes, "get_boot_order") # Print results if results: node_strings = get_node_strings(args, results, justify=True) print "Boot order" for node in nodes: if node in results: print "%s: %s" % (node_strings[node], ",".join(results[node])) print if not args.quiet and errors: print "Some errors occured during the command.\n" return len(errors) > 0
def partition_config_command(args): """get partition config from nodes""" args.all_nodes = False tftp = get_tftp(args) nodes = get_nodes(args, tftp) if not args.quiet: print "Getting partition config..." results, errors = run_command(args, nodes, "run_fabric_tftp_command", "fabric_info_partition_config") for node in nodes: if node in results: print "[ Partition config from %s ]" % node.ip_address print results[node].strip() print if not args.quiet and errors: print "Some errors occured during the command.\n" return len(errors) == 0
def ipdiscover_command(args): """discover server IP addresses""" tftp = get_tftp(args) nodes = get_nodes(args, tftp) if not args.quiet: print 'Getting server-side IP addresses...' results, errors = run_command(args, nodes, 'get_server_ip', args.interface, args.ipv6, args.aggressive) if results: node_strings = get_node_strings(args, results, justify=True) print 'IP addresses (ECME, Server)' for node in nodes: if node in results: print '%s: %s' % (node_strings[node], results[node]) print if not args.quiet and errors: print 'Some errors occurred during the command.' return len(errors) > 0
def info_ubootenv_command(args): """Print uboot info""" tftp = get_tftp(args) nodes = get_nodes(args, tftp) if not args.quiet: print "Getting u-boot environment..." results, errors = run_command(args, nodes, "get_ubootenv") # Print results node_strings = get_node_strings(args, results, justify=False) for node in nodes: if node in results: ubootenv = results[node] print "[ U-Boot Environment from %s ]" % node_strings[node] for variable in ubootenv.variables: print "%s=%s" % (variable, ubootenv.variables[variable]) print if not args.quiet and errors: print "Some errors occured during the command.\n" return len(errors) > 0