本文整理汇总了Python中ralph.discovery.models.Processor.concurrent_get_or_create方法的典型用法代码示例。如果您正苦于以下问题:Python Processor.concurrent_get_or_create方法的具体用法?Python Processor.concurrent_get_or_create怎么用?Python Processor.concurrent_get_or_create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ralph.discovery.models.Processor
的用法示例。
在下文中一共展示了Processor.concurrent_get_or_create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _add_dev_cpu
# 需要导入模块: from ralph.discovery.models import Processor [as 别名]
# 或者: from ralph.discovery.models.Processor import concurrent_get_or_create [as 别名]
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)
示例2: handle_lshw_processors
# 需要导入模块: from ralph.discovery.models import Processor [as 别名]
# 或者: from ralph.discovery.models.Processor import concurrent_get_or_create [as 别名]
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)
示例3: save_processors
# 需要导入模块: from ralph.discovery.models import Processor [as 别名]
# 或者: from ralph.discovery.models.Processor import concurrent_get_or_create [as 别名]
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()
示例4: make_components
# 需要导入模块: from ralph.discovery.models import Processor [as 别名]
# 或者: from ralph.discovery.models.Processor import concurrent_get_or_create [as 别名]
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()
示例5: _add_dev_cpu
# 需要导入模块: from ralph.discovery.models import Processor [as 别名]
# 或者: from ralph.discovery.models.Processor import concurrent_get_or_create [as 别名]
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)
示例6: save_processors
# 需要导入模块: from ralph.discovery.models import Processor [as 别名]
# 或者: from ralph.discovery.models.Processor import concurrent_get_or_create [as 别名]
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()
示例7: handle_lshw_processors
# 需要导入模块: from ralph.discovery.models import Processor [as 别名]
# 或者: from ralph.discovery.models.Processor import concurrent_get_or_create [as 别名]
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)
示例8: make_components
# 需要导入模块: from ralph.discovery.models import Processor [as 别名]
# 或者: from ralph.discovery.models.Processor import concurrent_get_or_create [as 别名]
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)
示例9: _save_cpu
# 需要导入模块: from ralph.discovery.models import Processor [as 别名]
# 或者: from ralph.discovery.models.Processor import concurrent_get_or_create [as 别名]
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()
示例10: _add_dev_cpu
# 需要导入模块: from ralph.discovery.models import Processor [as 别名]
# 或者: from ralph.discovery.models.Processor import concurrent_get_or_create [as 别名]
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)
示例11: run_http_ibm_system_x
# 需要导入模块: from ralph.discovery.models import Processor [as 别名]
# 或者: from ralph.discovery.models.Processor import concurrent_get_or_create [as 别名]
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
示例12: _add_ipmi_components
# 需要导入模块: from ralph.discovery.models import Processor [as 别名]
# 或者: from ralph.discovery.models.Processor import concurrent_get_or_create [as 别名]
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
示例13: handle_dmidecode
# 需要导入模块: from ralph.discovery.models import Processor [as 别名]
# 或者: from ralph.discovery.models.Processor import concurrent_get_or_create [as 别名]
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
示例14: handle_dmidecode
# 需要导入模块: from ralph.discovery.models import Processor [as 别名]
# 或者: from ralph.discovery.models.Processor import concurrent_get_or_create [as 别名]
def handle_dmidecode(info, ethernets=(), 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=priority,
)
for i, cpu_info in enumerate(info["cpu"]):
model, created = ComponentModel.create(
ComponentType.processor,
speed=cpu_info["speed"] or 0,
cores=cpu_info["cores"] or 0,
family=cpu_info["family"],
name=cpu_info["model"],
priority=priority,
)
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.create(
ComponentType.memory,
speed=mem_info["speed"] or 0,
size=mem_info["size"] or 0,
family=mem_info["type"],
priority=priority,
)
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
示例15: save_processors
# 需要导入模块: from ralph.discovery.models import Processor [as 别名]
# 或者: from ralph.discovery.models.Processor import concurrent_get_or_create [as 别名]
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()