def storage_info(sys, _chass): components = extract_by_path(sys, HARDWARE_COMPONENTS_PATH) storages = extract_components(components, is_memory, parse_memory) return [{ 'name': k, **v } for k, v in storages.items()] # Fix for schema
def power_state(_sys, chass): pwr_state = None try: validate_paths(chass, PWR_STATE_PATH) pwr_state = extract_by_path(chass, PWR_STATE_PATH) return { True: PowerState.ON, False: PowerState.OFF }[pwr_state].value except KeyError: raise CorruptedBufferError( f'Buffer specified unsupported pwr_state: {pwr_state}')
def parse_memsize(dictionary): "Gets memory size from an assumed memory component" unparsed = extract_by_path(dictionary, ['properties', 'Memory size']) number, unit = re.match(r'^(\d+)\s*(\w*)$', unparsed).groups() try: number = int(number) unit = unit.lower() if unit != 'mb': log.error( 'Unsupported memory type found, memory will not count in') return int(number / 1024) except ValueError: return 0
def extract_flat_props(dictionary, path, props): "Extracts the props in the list from the dictionary, which are at given path" info = {} for prop in props: try: working_path = path.copy() working_path.append(prop) bare_validate_paths(dictionary, working_path) info[prop] = extract_by_path( dictionary, working_path).strip() # Noticed some unstripped values in JSON except InvalidPathError: # Going to be a none-value pass return info
def cpus_temperatures(sys, _chass): cpu_temps = {} for cpu_nr in range(constants.MAX_PROCESSORS): cpu_temp_path = [ 'sensors', f'cpu{cpu_nr}_temp', 'reading', 'value' ] try: bare_validate_paths(sys, cpu_temp_path) cpu_temps[f'cpu_{cpu_nr}'] = {} cpu_temps[f'cpu_{cpu_nr}']['temp'] = extract_by_path( sys, cpu_temp_path) except InvalidPathError: # Going to mean just lack of value pass return cpu_temps
def pwr_supplies(sys, _chass): components = extract_by_path(sys, COMPONENTS_PATH) return extract_components(components, is_pwr, parse_pwr)
def pwr_consumed(sys, _chass): validate_paths(sys, SYSTEM_POWER_PATH) return extract_by_path(sys, SYSTEM_POWER_PATH)
def ambient_temp(sys, _chass): validate_paths(sys, AMBIENT_TEMP_PATH) return extract_by_path(sys, AMBIENT_TEMP_PATH)
def exhaust_temp(sys, _chass): validate_paths(sys, EXHAUST_TEMP_PATH) return extract_by_path(sys, EXHAUST_TEMP_PATH)
def pci_info(sys, _chass): components = extract_by_path(sys, HARDWARE_COMPONENTS_PATH) return extract_components(components, is_pci, parse_pci)
def mem_size_gb(sys, _chass): components = extract_by_path(sys, HARDWARE_COMPONENTS_PATH) rollup = reduce(lambda a, b: a + b, map(parse_memsize, filter(is_memory, components))) return rollup
def cpu_summary_power(sys, _chass): validate_paths(sys, CPU_PWR_PATH) return extract_by_path(sys, CPU_PWR_PATH)
def cpu_summary_usage(sys, _chass): validate_paths(sys, CPU_UTILIZATION_PATH) return extract_by_path(sys, CPU_UTILIZATION_PATH)