def handle_lshw_processors(dev, processors, is_virtual=False, priority=0): if isinstance(processors, dict): processors = [processors] detected_cpus = {} for i, processor in enumerate(processors): if processor['disabled'] == 'true' or not processor['size']: continue label = 'CPU {}'.format(i + 1) speed = int(processor['size']['value'] or 0) # 'size', sic! speed /= units.speed_divisor[processor['size']['units']] speed = int(speed) family = processor['version'] or '' caps = processor['capabilities'] extra = "\n".join([": ".join((key, ' '.join(e for e in untangle(caps[key]) if e) or '')) for key in sorted(caps.keys())]) model, c = ComponentModel.concurrent_get_or_create( speed=speed, type=ComponentType.processor.id, extra_hash=hashlib.md5(extra).hexdigest(), family=family, cores=0) model.extra = extra model.name = processor['product'] or 'CPU {} {}MHz'.format(family, speed) model.save(priority=priority) detected_cpus[i+1] = label, model for cpu in dev.processor_set.all(): label, model = detected_cpus.get(cpu.index, (None, None)) if cpu.label != label or cpu.model != model: cpu.delete() for index, (label, model) in detected_cpus.iteritems(): cpu, created = Processor.concurrent_get_or_create( device=dev, index=index) cpu.label = label cpu.model = model cpu.save(priority=priority)
def handle_lshw_mac_addresses(lshw): mac_addresses = set() ethernets = sorted( (e for e in jpath.get_all('..network', lshw) if e), key=_get_logical_name, ) for i, ethernet in enumerate(untangle(ethernets)): try: mac = MACAddressField.normalize(ethernet['serial']) except (ValueError, KeyError): continue if not mac: continue mac_addresses.add(mac) return list(mac_addresses)
def handle_lshw_ethernets(lshw): ethernets = sorted((e for e in jpath.get_all("..network", lshw) if e), key=get_logical_name) for i, ethernet in enumerate(untangle(ethernets)): try: mac = MACAddressField.normalize(ethernet["serial"]) except (ValueError, KeyError): continue if not mac: continue full_name = ethernet["product"] if ethernet["vendor"] not in full_name: full_name = "{} {}".format(ethernet["vendor"], full_name) label = "{}: {}".format(get_logical_name(ethernet), full_name) caps = set(ethernet["capabilities"].keys()) if "1000bt-fd" in caps or "1000bt" in caps: speed = EthernetSpeed.s1gbit.id elif "100bt-fd" in caps or "100bt" in caps: speed = EthernetSpeed.s100mbit.id else: speed = None yield Eth(label, mac, speed)
def handle_lshw_processors(dev, processors, is_virtual=False, priority=0): if isinstance(processors, dict): processors = [processors] detected_cpus = {} for i, processor in enumerate(processors): if processor['disabled'] == 'true' or not processor['size']: continue label = 'CPU {}'.format(i + 1) speed = int(processor['size']['value'] or 0) # 'size', sic! speed /= units.speed_divisor[processor['size']['units']] speed = int(speed) family = processor['version'] or '' caps = processor['capabilities'] extra = "\n".join([ ": ".join((key, ' '.join(e for e in untangle(caps[key]) if e) or '')) for key in sorted(caps.keys()) ]) model, c = ComponentModel.concurrent_get_or_create( speed=speed, type=ComponentType.processor.id, extra_hash=hashlib.md5(extra).hexdigest(), family=family, cores=0) model.extra = extra model.name = processor['product'] or 'CPU {} {}MHz'.format( family, speed) model.save(priority=priority) detected_cpus[i + 1] = label, model for cpu in dev.processor_set.all(): label, model = detected_cpus.get(cpu.index, (None, None)) if cpu.label != label or cpu.model != model: cpu.delete() for index, (label, model) in detected_cpus.iteritems(): cpu, created = Processor.concurrent_get_or_create(device=dev, index=index) cpu.label = label cpu.model = model cpu.save(priority=priority)
def handle_lshw_ethernets(lshw): ethernets = sorted((e for e in jpath.get_all('..network', lshw) if e), key=get_logical_name) for i, ethernet in enumerate(untangle(ethernets)): try: mac = MACAddressField.normalize(ethernet['serial']) except (ValueError, KeyError): continue if not mac: continue full_name = ethernet['product'] if ethernet['vendor'] not in full_name: full_name = "{} {}".format(ethernet['vendor'], full_name) label = "{}: {}".format(get_logical_name(ethernet), full_name) caps = set(ethernet['capabilities'].keys()) if '1000bt-fd' in caps or '1000bt' in caps: speed = EthernetSpeed.s1gbit.id elif '100bt-fd' in caps or '100bt' in caps: speed = EthernetSpeed.s100mbit.id else: speed = None yield Eth(label, mac, speed)