本文整理匯總了Python中ralph.discovery.models.Memory類的典型用法代碼示例。如果您正苦於以下問題:Python Memory類的具體用法?Python Memory怎麽用?Python Memory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Memory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_memory
def test_memory(self):
for i in xrange(8):
m = Memory(label="ziew", size=128, device=self.device, index=i)
m.save()
data = get_device_data(Device.objects.get(sn="123456789"))
memory = data["memory"]
self.assertEqual(len(memory), 8)
self.assertEqual(memory[0]["label"], "ziew")
self.assertEqual(memory[0]["size"], 128)
self.assertEqual(memory[3]["index"], 3)
示例2: test_memory
def test_memory(self):
for i in xrange(8):
m = Memory(
label="ziew",
size=128,
device=self.device,
index=i,
)
m.save()
data = get_device_data(Device.objects.get(sn='123456789'))
memory = data['memory']
self.assertEqual(len(memory), 8)
self.assertEqual(memory[0]['label'], "ziew")
self.assertEqual(memory[0]['size'], 128)
self.assertEqual(memory[3]['index'], 3)
示例3: 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()
示例4: 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)
示例5: save_memory
def save_memory(memory, dev):
indexes = []
index = 0
for row in memory:
index += 1
indexes.append(index)
try:
size = int(row.get('size'))
speed = int(row.get('speed')) if row.get('speed') else 0
except ValueError:
pass
label = row.get('label')
mem, created = Memory.concurrent_get_or_create(device=dev, index=index)
mem.size = size
mem.label = 'RAM %dMiB' % size
mem.speed = speed
family = 'Virtual' if 'Virtual' in label else ''
extra = '%s %dMiB %s %s' % (label, size, speed, row.get('caption'))
mem.model, c = ComponentModel.concurrent_get_or_create(
family=family, size=size, speed=speed,
type=ComponentType.memory.id,
extra_hash=hashlib.md5(extra.encode('utf-8')).hexdigest())
mem.model.extra = extra
mem.model.name = 'RAM Windows %dMiB' % size
mem.model.save()
mem.save(priority=SAVE_PRIORITY)
dev.memory_set.exclude(index__in=indexes).delete()
示例6: _add_dev_memory
def _add_dev_memory(ip, pairs, parent, raw, counts, dev_id):
try:
model = pairs['Mach type/model']
except KeyError:
DiscoveryWarning(
message="Memory model unknown",
plugin=__name__,
device=parent,
ip=ip,
).save()
return
counts.mem += 1
try:
index = int(model.split()[-1])
except ValueError:
index = counts.mem
mem, created = Memory.concurrent_get_or_create(device=parent, index=index)
size = int(pairs['Size'].replace('GB', '')) * 1024
speed = int(pairs.get('Speed', '0').replace('MHz', ''))
mem.label = pairs.get('Mach type/model', '')
mem.model, c = ComponentModel.create(
ComponentType.memory,
size=size,
speed=speed,
priority=SAVE_PRIORITY,
)
mem.save(priority=SAVE_PRIORITY)
示例7: save_memory
def save_memory(memory, dev):
indexes = []
index = 0
for row in memory:
index += 1
indexes.append(index)
try:
size = int(row.get('size'))
speed = int(row.get('speed')) if row.get('speed') else 0
except ValueError:
pass
label = row.get('label')
mem, created = Memory.concurrent_get_or_create(device=dev, index=index)
mem.size = size
mem.label = 'RAM %dMiB' % size
mem.speed = speed
family = 'Virtual Windows' if 'Virtual' in label else 'Windows'
mem.model, c = ComponentModel.create(
ComponentType.memory,
family=family,
size=size,
speed=speed,
priority=SAVE_PRIORITY,
)
mem.save(priority=SAVE_PRIORITY)
dev.memory_set.exclude(index__in=indexes).delete()
示例8: 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
示例9: _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
示例10: 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
示例11: _save_memory
def _save_memory(dev, data):
detected_memory = []
for mem, index in zip(data, range(1, len(data) + 1)):
model, _ = ComponentModel.create(
ComponentType.memory,
size=int(mem['size']),
speed=int(mem['speed']),
priority=SAVE_PRIORITY,
)
memory, _ = Memory.concurrent_get_or_create(index=index, device=dev)
memory.label = "{} {}".format(mem['manufacturer'], mem['model'])
memory.size = mem['size']
memory.speed = mem['speed']
memory.model = model
memory.save(priority=SAVE_PRIORITY)
detected_memory.append(memory.pk)
dev.memory_set.exclude(pk__in=detected_memory).delete()
示例12: handle_lshw_memory
def handle_lshw_memory(dev, bus_memory, is_virtual=False, priority=0):
memory_banks = []
for _mem in bus_memory:
# we're interested only in the system memory, not in caches etc.
if _mem['id'] == 'memory':
memory_banks = _mem['memory']
break
elif _mem['id'].startswith('memory:'):
memory_banks.extend(_mem['memory'])
index = 0
if isinstance(memory_banks, dict):
memory_banks = [memory_banks]
detected_memory = {}
for memory in memory_banks:
if 'size' not in memory:
# empty slot
continue
index += 1
size = int(memory['size']['value'] or 0)
size /= units.size_divisor[memory['size']['units']]
size = int(size)
label = memory['slot']
family = 'Virtual' if is_virtual else ''
model, created = ComponentModel.concurrent_get_or_create(
size=size, speed=0, type=ComponentType.memory.id,
family=family, extra_hash='')
if created:
name = 'RAM %dMiB' % size
if family:
name = '%s %s' % (family, name)
model.name = name
model.save(priority=priority)
detected_memory[index] = label, model
for mem in dev.memory_set.all():
label, model = detected_memory.get(mem.index, (None, None))
if mem.label != label or mem.model != model:
mem.delete()
for index, (label, model) in detected_memory.iteritems():
mem, created = Memory.concurrent_get_or_create(device=dev, index=index)
if created:
mem.model = model
mem.size = model.size
mem.speed = model.speed
mem.label = label
mem.save(priority=priority)
示例13: handle_dmidecode
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
示例14: handle_lshw_memory
def handle_lshw_memory(dev, bus_memory, is_virtual=False, priority=0):
memory_banks = []
for _mem in bus_memory:
# we're interested only in the system memory, not in caches etc.
if _mem["id"] == "memory":
memory_banks = _mem["memory"]
break
elif _mem["id"].startswith("memory:"):
memory_banks.extend(_mem["memory"])
index = 0
if isinstance(memory_banks, dict):
memory_banks = [memory_banks]
detected_memory = {}
for memory in memory_banks:
if "size" not in memory:
# empty slot
continue
index += 1
size = int(memory["size"]["value"] or 0)
size /= units.size_divisor[memory["size"]["units"]]
size = int(size)
label = memory["slot"]
family = "Virtual" if is_virtual else ""
model, created = ComponentModel.concurrent_get_or_create(
size=size, speed=0, type=ComponentType.memory.id, family=family, extra_hash=""
)
if created:
name = "RAM %dMiB" % size
if family:
name = "%s %s" % (family, name)
model.name = name
model.save(priority=priority)
detected_memory[index] = label, model
for mem in dev.memory_set.all():
label, model = detected_memory.get(mem.index, (None, None))
if mem.label != label or mem.model != model:
mem.delete()
for index, (label, model) in detected_memory.iteritems():
mem, created = Memory.concurrent_get_or_create(device=dev, index=index)
if created:
mem.model = model
mem.size = model.size
mem.speed = model.speed
mem.label = label
mem.save(priority=priority)
示例15: _add_dev_memory
def _add_dev_memory(pairs, parent, raw, counts, dev_id):
try:
model = pairs["Mach type/model"]
except KeyError:
return
counts.mem += 1
try:
index = int(model.split()[-1])
except ValueError:
index = counts.mem
mem, created = Memory.concurrent_get_or_create(device=parent, index=index)
family = pairs.get("Memory type", "")
size = int(pairs["Size"].replace("GB", "")) * 1024
speed = int(pairs.get("Speed", "0").replace("MHz", ""))
mem.label = pairs.get("Mach type/model", "")
mem.model, c = ComponentModel.concurrent_get_or_create(
family=family, size=size, speed=speed, type=ComponentType.memory.id, extra_hash=""
)
mem.model.name = "RAM %s %dMiB %dMHz" % (family, size, speed)
mem.model.save(priority=SAVE_PRIORITY)
mem.save(priority=SAVE_PRIORITY)