def get_power_consumption(self): ''' Parse omreport output like this Amperage PS1 Current 1 : 1.8 A PS2 Current 2 : 1.4 A ''' value = [] if not is_tool('omreport'): logging.error('omreport does not seem to be installed, please debug') return value data = subprocess.getoutput('omreport chassis pwrmonitoring') amperage = False for line in data.splitlines(): if line.startswith('Amperage'): amperage = True continue if amperage: if line.startswith('PS'): amp_value = line.split(':')[1].split()[0] value.append(amp_value) else: break return value
def find_storage(self, obj): if "children" in obj: for device in obj["children"]: d = {} d["logicalname"] = device.get("logicalname") d["product"] = device.get("product") d["serial"] = device.get("serial") d["version"] = device.get("version") d["size"] = device.get("size") d["description"] = device.get("description") self.disks.append(d) elif "nvme" in obj["configuration"]["driver"]: if not is_tool('nvme'): logging.error('nvme-cli >= 1.0 does not seem to be installed') else: try: nvme = json.loads( subprocess.check_output( ["nvme", '-list', '-o', 'json'], encoding='utf8')) for device in nvme["Devices"]: d = {} d['logicalname'] = device["DevicePath"] d['product'] = device["ModelNumber"] d['serial'] = device["SerialNumber"] d["version"] = device["Firmware"] d['size'] = device["UsedSize"] d['description'] = "NVME Disk" self.disks.append(d) except Exception: pass
def __init__(self, output=None): if not is_tool('lldpctl'): logging.debug('lldpd package seems to be missing or daemon not running.') if output: self.output = output else: self.output = subprocess.getoutput('lldpctl -f keyvalue') self.data = self.parse()
def get_raid_cards(self): raid_class = None if self.server.manufacturer == 'Dell': if is_tool('omreport'): raid_class = OmreportRaid if is_tool('storcli'): raid_class = StorcliRaid elif self.server.manufacturer == 'HP': if is_tool('ssacli'): raid_class = HPRaid if not raid_class: return [] self.raid = raid_class() controllers = self.raid.get_controllers() if len(self.raid.get_controllers()): return controllers
def _execute_cmd(): if not is_tool('dmidecode'): logging.error( 'Dmidecode does not seem to be present on your system. Add it your path or ' 'check the compatibility of this project with your distro.') sys.exit(1) return _subprocess.check_output([ 'dmidecode', ], stderr=_subprocess.PIPE)
def __init__(self): if not is_tool('lshw'): logging.error('lshw does not seem to be installed') sys.exit(1) data = subprocess.getoutput( 'lshw -quiet -json' ) self.hw_info = json.loads(data) self.info = {} self.memories = [] self.interfaces = [] self.cpus = [] self.power = [] self.disks = [] self.gpus = [] self.vendor = self.hw_info["vendor"] self.product = self.hw_info["product"] self.chassis_serial = self.hw_info["serial"] self.motherboard_serial = self.hw_info["children"][0].get("serial", "No S/N") self.motherboard = self.hw_info["children"][0].get("product", "Motherboard") for k in self.hw_info["children"]: if k["class"] == "power": # self.power[k["id"]] = k self.power.append(k) if "children" in k: for j in k["children"]: if j["class"] == "generic": continue if j["class"] == "storage": self.find_storage(j) if j["class"] == "memory": self.find_memories(j) if j["class"] == "processor": self.find_cpus(j) if j["class"] == "bridge": self.walk_bridge(j)