当前位置: 首页>>代码示例>>Python>>正文


Python models.Processor类代码示例

本文整理汇总了Python中ralph.discovery.models.Processor的典型用法代码示例。如果您正苦于以下问题:Python Processor类的具体用法?Python Processor怎么用?Python Processor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Processor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_processors

 def test_processors(self):
     model = ComponentModel(type=ComponentType.processor, name="CPU Xeon 2533MHz, 4-core")
     model.save()
     for i in xrange(4):
         p = Processor(label="ziew", model=model, device=self.device, index=i)
         p.save()
     data = get_device_data(Device.objects.get(sn="123456789"))
     processors = data["processors"]
     self.assertEqual(len(processors), 4)
     self.assertEqual(processors[0]["label"], "ziew")
     self.assertEqual(processors[0]["model_name"], "CPU Xeon 2533MHz, 4-core")
     self.assertEqual(processors[0]["cores"], 4)
     self.assertEqual(processors[3]["index"], 3)
开发者ID:pydubreucq,项目名称:ralph,代码行数:13,代码来源:test_data.py

示例2: _add_dev_cpu

def _add_dev_cpu(ip, pairs, parent, raw, counts, dev_id):
    try:
        model = pairs['Mach type/model']
    except KeyError:
        DiscoveryWarning(
            message="Processor model unknown",
            plugin=__name__,
            device=parent,
            ip=ip,
        ).save()
        return
    counts.cpu += 1
    try:
        index = int(model.split()[-1])
    except ValueError:
        index = counts.cpu
    cpu, created = Processor.concurrent_get_or_create(
        device=parent,
        index=index,
    )
    cpu.label = pairs['Mach type/model']
    family = pairs['Processor family']
    if family.startswith('Intel '):
        family = cpu.label[len('Intel '):]
    speed = int(float(pairs['Speed'].replace('GHz', '')) * 1000)
    cores = int(pairs['Processor cores'])
    cpu.model, c = ComponentModel.create(
        ComponentType.processor,
        speed=speed,
        cores=cores,
        name='CPU %s %d MHz, %s-core' % (family, speed, cores),
        family=family,
        priority=SAVE_PRIORITY,
    )
    cpu.save(priority=SAVE_PRIORITY)
开发者ID:andrzej-jankowski,项目名称:ralph,代码行数:35,代码来源:ssh_ibm_bladecenter.py

示例3: handle_lshw_processors

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)
开发者ID:Makdaam,项目名称:ralph,代码行数:34,代码来源:lshw.py

示例4: save_processors

def save_processors(processors, dev):
    indexes = []
    for p in processors:
        cpuname = p.get('label')
        try:
            index = int(p.get('index')[3:]) + 1 #CPU0
            speed = int(p.get('speed'))
            cores = int(p.get('cores'))
        except ValueError:
            continue
        indexes.append(index)
        cpu, created = Processor.concurrent_get_or_create(
            device=dev, index=index)
        cpu.label = cpuname
        cpu.speed = speed
        cpu.cores = cores
        is64bit = p.get('is64bit') == 'true'
        extra = '%s %s %s ' % (p.get('manufacturer'),
            p.get('version'), '64bit' if is64bit else '')
        name = 'CPU %s%s %s %s' % (
            '64bit ' if is64bit else '',
            cpuname, '%dMhz' % speed if speed else '',
            'multicore' if cores else '')
        cpu.model, c = ComponentModel.concurrent_get_or_create(
            speed=speed, type=ComponentType.processor.id,
            family=cpuname,
            cores=cores, extra_hash=hashlib.md5(extra).hexdigest())
        cpu.model.extra = extra
        cpu.model.name = name
        cpu.model.save(priority=SAVE_PRIORITY)
        cpu.save(priority=SAVE_PRIORITY)
    for cpu in dev.processor_set.exclude(index__in=indexes):
        cpu.delete()
开发者ID:Makdaam,项目名称:ralph,代码行数:33,代码来源:api_donpedro.py

示例5: _add_dev_cpu

def _add_dev_cpu(pairs, parent, raw, counts, dev_id):
    try:
        model = pairs['Mach type/model']
    except KeyError:
        return
    counts.cpu += 1
    try:
        index = int(model.split()[-1])
    except ValueError:
        index = counts.cpu
    cpu, created = Processor.concurrent_get_or_create(device=parent,
            index=index)
    cpu.label = pairs['Mach type/model']
    family = pairs['Processor family']
    if family.startswith('Intel '):
        family = cpu.label[len('Intel '):]
    speed = int(float(pairs['Speed'].replace('GHz', '')) * 1000)
    cores = int(pairs['Processor cores'])
    extra = '\n'.join('%s: %s' % (k, v) for (k, v) in sorted(pairs.iteritems()) if
        v not in ('Not Available', '', None, 'Not Available (Not Available)') and
        k not in ('Processor cores', 'Processor family',
                  'Speed', 'system>', 'Mach type/model'))
    cpu.model, c = ComponentModel.concurrent_get_or_create(
        cores=cores, speed=speed, type=ComponentType.processor.id,
        extra_hash=hashlib.md5(extra).hexdigest(), extra=extra,
        family=family)
    cpu.model.name = 'CPU %s %d MHz, %s-core' % (family, speed, cores)
    cpu.model.save(priority=SAVE_PRIORITY)
    cpu.save(priority=SAVE_PRIORITY)
开发者ID:Makdaam,项目名称:ralph,代码行数:29,代码来源:ssh_ibm_bladecenter.py

示例6: save_processors

def save_processors(processors, dev, is_virtual=False):
    indexes = []
    for p in processors:
        cpuname = p.get("label")
        if is_virtual and not cpuname.lower().startswith("virtual"):
            cpuname = "Virtual %s" % cpuname
        try:
            index = int(p.get("index")[3:]) + 1  # CPU0
            speed = int(p.get("speed"))
            cores = int(p.get("cores"))
        except ValueError:
            continue
        indexes.append(index)
        cpu, created = Processor.concurrent_get_or_create(
            device=dev, index=index, defaults={"label": cpuname, "speed": speed, "cores": cores}
        )
        if not created:
            cpu.label = cpuname
            cpu.speed = speed
            cpu.cores = cores
        is64bit = p.get("is64bit") == "true"
        name = "CPU %s%s %s%s" % (
            "64bit " if is64bit else "",
            cpuname,
            "%dMhz" % speed if speed else "",
            " multicore" if cores > 1 else "",
        )
        cpu.model, c = ComponentModel.create(
            ComponentType.processor, cores=cores, family=cpuname, speed=speed, name=name, priority=SAVE_PRIORITY
        )
        cpu.save(priority=SAVE_PRIORITY)
    for cpu in dev.processor_set.exclude(index__in=indexes):
        cpu.delete()
开发者ID:quamilek,项目名称:ralph,代码行数:33,代码来源:api_donpedro.py

示例7: make_components

def make_components(ilo, dev):
    for i, (label, size, speed) in enumerate(ilo.memories):
        mem, created = Memory.concurrent_get_or_create(device=dev, index=i + 1)
        mem.size = size
        mem.speed = speed
        mem.label = label
        mem.model, c = ComponentModel.concurrent_get_or_create(
            size=mem.size, speed=mem.speed, type=ComponentType.memory.id,
            family='', extra_hash='')
        if c:
            mem.model.name = 'RAM %dMiB, %dMHz' % (mem.size, mem.speed)
            mem.model.save()
        mem.save()

    for i, (label, speed, cores, extra, family) in enumerate(ilo.cpus):
        cpu, created = Processor.concurrent_get_or_create(device=dev,
                                                          index=i + 1)
        family = family or ''
        cpu.label = label
        cpu.model, c = ComponentModel.concurrent_get_or_create(
            speed=speed, type=ComponentType.processor.id, extra=extra,
            extra_hash=hashlib.md5(extra).hexdigest(), cores=cores,
            family=family)
        if c:
            cpu.model.name = 'CPU %s %dMHz, %s-core' % (family, speed, cores)
            cpu.model.save()
        cpu.save()
开发者ID:iwwwwwwi,项目名称:ralph,代码行数:27,代码来源:ilo_hp.py

示例8: handle_lshw_processors

def handle_lshw_processors(dev, processors, is_virtual=False, priority=0):
    if isinstance(processors, dict):
        processors = [processors]
    detected_cpus = {}
    family = None
    for processor in processors:
        family = processor["version"] or ("Virtual CPU" if is_virtual else processor["product"])
        if family:
            break
    if not family:
        return  # skip CPU changes if we cannot determine family
    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)
        model, c = ComponentModel.create(
            ComponentType.processor,
            speed=speed,
            family=family,
            name=processor["product"] or "CPU {} {}MHz".format(family, speed),
            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)
开发者ID:damjanek,项目名称:ralph,代码行数:35,代码来源:lshw.py

示例9: make_components

def make_components(ilo, dev):
    for i, (label, size, speed) in enumerate(ilo.memories):
        mem, created = Memory.concurrent_get_or_create(device=dev, index=i + 1)
        mem.size = size
        mem.speed = speed
        mem.label = label
        mem.model, c = ComponentModel.create(
            ComponentType.memory,
            size=mem.size,
            speed=mem.speed,
            priority=SAVE_PRIORITY,
        )
        mem.save(priority=SAVE_PRIORITY)

    for i, (label, speed, cores, extra, family) in enumerate(ilo.cpus):
        cpu, created = Processor.concurrent_get_or_create(device=dev,
                                                          index=i + 1)
        cpu.label = label
        cpu.model, c = ComponentModel.create(
            ComponentType.processor,
            speed=speed,
            cores=cores,
            family=family,
            name='CPU %s %dMHz, %s-core' % (family, speed, cores),
            priority=SAVE_PRIORITY,
        )
        cpu.save(priority=SAVE_PRIORITY)
开发者ID:ReJeCtAll,项目名称:ralph,代码行数:27,代码来源:ilo_hp.py

示例10: _save_cpu

def _save_cpu(dev, data):
    detected_cpus = []
    for cpu in data:
        try:
            index = int(cpu['socket'].split('.')[-1])
        except (ValueError, IndexError):
            continue
        model, _ = ComponentModel.create(
            ComponentType.processor,
            speed=cpu['speed'],
            family=cpu['family'],
            cores=cpu['cores_count'],
            name = cpu['model'],
            priority=SAVE_PRIORITY,
        )
        processor, _ = Processor.concurrent_get_or_create(
            device=dev,
            index=index
        )
        processor.label = cpu['model']
        processor.model = model
        processor.speed = cpu['speed']
        processor.cores = cpu['cores_count']
        processor.save(priority=SAVE_PRIORITY)
        detected_cpus.append(processor.pk)
    dev.processor_set.exclude(pk__in=detected_cpus).delete()
开发者ID:andrzej-jankowski,项目名称:ralph,代码行数:26,代码来源:idrac.py

示例11: _add_dev_cpu

def _add_dev_cpu(pairs, parent, raw, counts, dev_id):
    try:
        model = pairs["Mach type/model"]
    except KeyError:
        return
    counts.cpu += 1
    try:
        index = int(model.split()[-1])
    except ValueError:
        index = counts.cpu
    cpu, created = Processor.concurrent_get_or_create(device=parent, index=index)
    cpu.label = pairs["Mach type/model"]
    family = pairs["Processor family"]
    if family.startswith("Intel "):
        family = cpu.label[len("Intel ") :]
    speed = int(float(pairs["Speed"].replace("GHz", "")) * 1000)
    cores = int(pairs["Processor cores"])
    extra = "\n".join(
        "%s: %s" % (k, v)
        for (k, v) in sorted(pairs.iteritems())
        if v not in ("Not Available", "", None, "Not Available (Not Available)")
        and k not in ("Processor cores", "Processor family", "Speed", "system>", "Mach type/model")
    )
    cpu.model, c = ComponentModel.concurrent_get_or_create(
        cores=cores,
        speed=speed,
        type=ComponentType.processor.id,
        extra_hash=hashlib.md5(extra).hexdigest(),
        extra=extra,
        family=family,
    )
    cpu.model.name = "CPU %s %d MHz, %s-core" % (family, speed, cores)
    cpu.model.save(priority=SAVE_PRIORITY)
    cpu.save(priority=SAVE_PRIORITY)
开发者ID:relusek,项目名称:ralph,代码行数:34,代码来源:ssh_ibm_bladecenter.py

示例12: run_http_ibm_system_x

def run_http_ibm_system_x(ip):
    session_id = get_session_id(ip)
    management_url = "http://%s/wsman" % ip
    model_name = get_model_name(management_url, session_id)
    sn = get_sn(management_url, session_id)
    macs = get_mac_addresses(management_url, session_id)
    ethernets = [Eth(label=label, mac=mac, speed=0)
                 for (label, mac) in macs]
    ipaddr, ip_created = IPAddress.concurrent_get_or_create(address=ip)
    ipaddr.is_management = True
    ipaddr.save()
    dev = Device.create(
        ethernets=ethernets,
        model_name=model_name,
        sn=sn,
        model_type=DeviceType.rack_server,
    )
    dev.management = ipaddr
    dev.save(priority=SAVE_PRIORITY)
    ipaddr.device = dev
    ipaddr.save()
    detected_memory = get_memory(management_url, session_id)
    detected_memory_indexes = [x.get('index') for x in detected_memory]
    for m in dev.memory_set.exclude(index__in=detected_memory_indexes):
        m.delete()
    for m in detected_memory:
        index = m['index']
        mem, _ = Memory.concurrent_get_or_create(index=index, device=dev)
        mem.label = m['label']
        mem.size = m['size']
        mem.model, c = ComponentModel.create(
            ComponentType.memory,
            size=mem.size,
            priority=SAVE_PRIORITY,
        )
        mem.save(priority=SAVE_PRIORITY)
    detected_processors = get_processors(management_url, session_id)
    detected_processors_keys = [x.get('index') for x in detected_processors]
    for cpu in dev.processor_set.exclude(index__in=detected_processors_keys):
        cpu.delete()
    # add new
    for p in detected_processors:
        processor_model, _ = ComponentModel.create(
            ComponentType.processor,
            speed=p.get('speed'),
            family=p.get('family'),
            cores=p.get('cores'),
            name=p.get('label'),
            priority=SAVE_PRIORITY,
        )
        processor, _ = Processor.concurrent_get_or_create(
            device=dev,
            index=p.get('index'),
        )
        processor.label = p.get('label')
        processor.model = processor_model
        processor.speed = p.get('speed')
        processor.save(priority=SAVE_PRIORITY)
    return model_name
开发者ID:damjanek,项目名称:ralph,代码行数:59,代码来源:http_ibm_system_x.py

示例13: _add_ipmi_components

def _add_ipmi_components(device, data):
    # CPUs
    cpu_index = 0
    total_mem_index = 0
    while True:
        cpu = data['MB/P{}'.format(cpu_index)]
        if not cpu:
            break
        if not cpu['Product Name']:
            cpu_index += 1
            continue
        proc, _ = Processor.concurrent_get_or_create(index=cpu_index+1,
            device=device)
        proc.label = re.sub(' +', ' ', cpu['Product Name']).title()
        speed_match = re.search(r'(\d+\.\d+)GHZ', cpu['Product Name'])
        if speed_match:
            speed = int(float(speed_match.group(1)) * 1000)
        else:
            speed = 0
        cores = 0
        proc.model, c = ComponentModel.concurrent_get_or_create(
            family=proc.label, speed=speed, type=ComponentType.processor.id,
            cores=cores, extra_hash='', size=0)
        if c:
            proc.model.name = ('CPU %s %dMHz %d-core' %
                                (proc.label, speed, cores))[:50]
            proc.model.save()
        proc.save()
        # Memory
        mem_index = 0
        while True:
            memory = data['MB/P{}/D{}'.format(cpu_index, mem_index)]
            if not memory:
                break
            if not memory['Product Name']:
                mem_index += 1
                total_mem_index += 1
                continue
            size_match = re.search(r'(\d+)GB', memory['Product Name'])
            if not size_match:
                mem_index += 1
                total_mem_index += 1
                continue
            mem, _ = Memory.concurrent_get_or_create(index=total_mem_index+1,
                device=device)
            mem.label = memory['Product Name']
            size = int(size_match.group(1)) * 1024
            speed = 0
            mem.model, c = ComponentModel.concurrent_get_or_create(
                name='RAM %s %dMiB' % (mem.label, size), size=size, speed=speed,
                type=ComponentType.memory.id, extra='', extra_hash='',
                family=mem.label, cores=0)
            mem.save()
            mem_index += 1
            total_mem_index += 1
        cpu_index += 1
开发者ID:pb-it,项目名称:ralph,代码行数:56,代码来源:ipmi.py

示例14: test_processors

 def test_processors(self):
     model = ComponentModel(
         type=ComponentType.processor,
         name="CPU Xeon 2533MHz, 4-core",
     )
     model.save()
     for i in xrange(4):
         p = Processor(
             label="ziew",
             model=model,
             device=self.device,
             index=i,
         )
         p.save()
     data = get_device_data(Device.objects.get(sn='123456789'))
     processors = data['processors']
     self.assertEqual(len(processors), 4)
     self.assertEqual(processors[0]['label'], "ziew")
     self.assertEqual(processors[0]['model_name'], "CPU Xeon 2533MHz, 4-core")
     self.assertEqual(processors[0]['cores'], 4)
     self.assertEqual(processors[3]['index'], 3)
开发者ID:andrzej-jankowski,项目名称:ralph,代码行数:21,代码来源:test_data.py

示例15: handle_dmidecode

def handle_dmidecode(info, ethernets=(), save_priority=0):
    """Take the data collected by parse_dmidecode and apply it to a device."""

    # It's either a rack or a blade server, who knows?
    # We will let other plugins determine that.
    dev = Device.create(
        ethernets=ethernets, sn=info['sn'], uuid=info['uuid'],
        model_name='DMI '+info['model'], model_type=DeviceType.unknown,
        priority=save_priority
    )
    for i, cpu_info in enumerate(info['cpu']):
        extra = ',\n'.join(cpu_info['flags'])
        extra = ('threads: %d\n' % cpu_info['threads']
                 if cpu_info['threads'] else '') + extra
        if cpu_info['64bit']:
            extra = '64bit\n' + extra
        model, created = ComponentModel.concurrent_get_or_create(
            speed=cpu_info['speed'] or 0,
            cores=cpu_info['cores'] or 0,
            family=cpu_info['family'],
            extra_hash=hashlib.md5(extra).hexdigest(),
            type=ComponentType.processor.id,
        )
        if created:
            model.name = cpu_info['model']
            model.extra = extra
            model.save()
        cpu, created = Processor.concurrent_get_or_create(device=dev,
                                                          index=i + 1)
        if created:
            cpu.label = cpu_info['label']
            cpu.model = model
            cpu.save()
    for cpu in dev.processor_set.filter(index__gt=i + 1):
        cpu.delete()
    for i, mem_info in enumerate(info['mem']):
        model, created = ComponentModel.concurrent_get_or_create(
            speed=mem_info['speed'] or 0,
            size=mem_info['size'] or 0,
            type=ComponentType.memory.id,
        )
        if created:
            model.name = 'RAM %s %dMiB' % (mem_info['type'], mem_info['size'])
            model.save()
        mem, created = Memory.concurrent_get_or_create(device=dev, index=i + 1)
        if created:
            mem.label = mem_info['label']
            mem.model = model
            mem.save()
    for mem in dev.memory_set.filter(index__gt=i + 1):
        mem.delete()
    return dev
开发者ID:szaydel,项目名称:ralph,代码行数:52,代码来源:hardware.py


注:本文中的ralph.discovery.models.Processor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。