本文整理匯總了Python中ralph.discovery.models.Storage類的典型用法代碼示例。如果您正苦於以下問題:Python Storage類的具體用法?Python Storage怎麽用?Python Storage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Storage類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: handle_facts_disks
def handle_facts_disks(dev, facts, is_virtual=False):
disks = {}
_cur_key = None
for k, v in facts.iteritems():
if not k.startswith('disk_'):
continue
k = k[5:]
if k.endswith('_product'):
_cur_key = 'product'
k = k[:-8]
elif k.endswith('_revision'):
_cur_key = 'revision'
k = k[:-9]
elif k.endswith('_size'):
_cur_key = 'size'
k = k[:-5]
elif k.endswith('_vendor'):
_cur_key = 'vendor'
k = k[:-7]
elif k.endswith('_serial'):
_cur_key = 'serial'
k = k[:-7]
else:
continue
disks.setdefault(k, {})[_cur_key] = v.strip()
for label, disk in disks.iteritems():
try:
if 'size' not in disk or not int(disk['size']):
continue
except ValueError:
continue
if disk['vendor'].lower() in DISK_VENDOR_BLACKLIST:
continue
if disk['product'].lower() in DISK_PRODUCT_BLACKLIST:
continue
sn = disk.get('serial', '').strip()
if sn:
stor, created = Storage.concurrent_get_or_create(
device=dev, sn=sn)
else:
stor, created = Storage.concurrent_get_or_create(
device=dev, mount_point=label, sn=None)
stor.size = disk['size'] = int(int(disk['size']) / 1024 / 1024)
stor.label = '{} {} {}'.format(
disk['vendor'].strip(), disk['product'].strip(),
disk['revision'].strip())
extra = """Vendor: {vendor}
Product: {product}
Firmware Revision: {revision}
Size: {size}""".format(**disk)
stor.model, c = ComponentModel.concurrent_get_or_create(
size=stor.size, speed=0, type=ComponentType.disk.id,
family=disk['vendor'].strip(),
extra_hash=hashlib.md5(extra).hexdigest(), extra=extra)
stor.model.name = '{} {}MiB'.format(stor.label, stor.size)
stor.model.save(priority=SAVE_PRIORITY)
stor.save(priority=SAVE_PRIORITY)
示例2: handle_hpacu
def handle_hpacu(dev, disks, priority=0):
for disk_handle, disk in disks.iteritems():
if not disk.get('serial_number'):
continue
stor, created = Storage.concurrent_get_or_create(device=dev,
sn=disk['serial_number'])
stor.device = dev
size_value, size_unit = disk['size'].split()
stor.size = int(float(size_value) / units.size_divisor[size_unit])
stor.speed = int(disk.get('rotational_speed', 0))
stor.label = '{} {}'.format(' '.join(disk['model'].split()),
disk['interface_type'])
disk_default = dict(
model = 'unknown',
firmware_revision = 'unknown',
interface_type = 'unknown',
size = 'unknown',
rotational_speed = 'unknown',
status = 'unknown',
)
disk_default.update(disk)
extra = """Model: {model}
Firmware Revision: {firmware_revision}
Interface: {interface_type}
Size: {size}
Rotational Speed: {rotational_speed}
Status: {status}""".format(**disk_default)
stor.model, c = ComponentModel.concurrent_get_or_create(
size=stor.size, speed=stor.speed, type=ComponentType.disk.id,
family='', extra_hash=hashlib.md5(extra).hexdigest(), extra=extra)
stor.model.name = '{} {}MiB'.format(stor.label, stor.size)
stor.model.save(priority=priority)
stor.save(priority=priority)
示例3: handle_smartctl
def handle_smartctl(dev, disks, priority=0):
for disk_handle, disk in disks.iteritems():
if not disk.get("serial_number") or disk.get("device_type") != "disk":
continue
if {"user_capacity", "vendor", "product", "transport_protocol"} - set(disk.keys()):
# not all required keys present
continue
if disk["vendor"].lower() in DISK_VENDOR_BLACKLIST:
continue
if disk["product"].lower() in DISK_PRODUCT_BLACKLIST:
continue
stor, created = Storage.concurrent_get_or_create(device=dev, sn=disk["serial_number"], mount_point=None)
stor.device = dev
size_value, size_unit, rest = disk["user_capacity"].split(" ", 2)
size_value = size_value.replace(",", "")
stor.size = int(int(size_value) / units.size_divisor[size_unit])
stor.speed = int(disk.get("rotational_speed", 0))
label_meta = [" ".join(disk["vendor"].split()), disk["product"]]
if "transport_protocol" in disk:
label_meta.append(disk["transport_protocol"])
stor.label = " ".join(label_meta)
disk_default = dict(
vendor="unknown",
product="unknown",
revision="unknown",
transport_protocol="unknown",
user_capacity="unknown",
)
disk_default.update(disk)
stor.model, c = ComponentModel.create(
ComponentType.disk, size=stor.size, speed=stor.speed, family=stor.label, priority=priority
)
stor.save(priority=priority)
示例4: _save_storage
def _save_storage(dev, data):
detected_storage = []
for disk in data:
model_name = "{} {}".format(
disk['manufacturer'],
disk['model']
)
size = int(int(disk['size']) / 1024 / 1024 / 1024)
model, _ = ComponentModel.create(
ComponentType.disk,
size=size,
family=model_name,
priority=SAVE_PRIORITY,
)
storage, _ = Storage.concurrent_get_or_create(
device=dev,
sn=disk['sn'],
mount_point=None,
)
storage.model = model
storage.label = model.name
storage.size = size
storage.save(priority=SAVE_PRIORITY)
detected_storage.append(storage.pk)
dev.storage_set.exclude(pk__in=detected_storage).delete()
示例5: handle_hpacu
def handle_hpacu(dev, disks, priority=0):
for disk_handle, disk in disks.iteritems():
if not disk.get('serial_number'):
continue
stor, created = Storage.concurrent_get_or_create(
device=dev, sn=disk['serial_number'], mount_point=None,
)
stor.device = dev
size_value, size_unit = disk['size'].split()
stor.size = int(float(size_value) / units.size_divisor[size_unit])
stor.speed = int(disk.get('rotational_speed', 0))
stor.label = '{} {}'.format(' '.join(disk['model'].split()),
disk['interface_type'])
disk_default = dict(
model='unknown',
firmware_revision='unknown',
interface_type='unknown',
size='unknown',
rotational_speed='unknown',
status='unknown',
)
disk_default.update(disk)
stor.model, c = ComponentModel.create(
ComponentType.disk,
size=stor.size,
speed=stor.speed,
family=stor.label,
priority=priority,
)
stor.save(priority=priority)
示例6: parse_megaraid
def parse_megaraid(facts, dev):
disks = {}
for k, value in facts.iteritems():
m = MEGARAID_REGEX.match(k)
if not m:
continue
controller = m.group(1)
disk = m.group(2)
property = m.group(3)
disks.setdefault((controller, disk), {})[property] = value.strip()
for (controller_handle, disk_handle), disk in disks.iteritems():
disk['vendor'], disk['product'], disk['serial_number'] = \
_handle_inquiry_data(disk.get('inquiry_data', ''),
controller_handle, disk_handle)
if not disk.get('serial_number') or disk.get('media_type') not in ('Hard Disk Device',
'Solid State Device'):
continue
if {'coerced_size', 'vendor', 'product', 'pd_type'} - \
set(disk.keys()):
# not all required keys present
continue
if disk['vendor'].lower() in DISK_VENDOR_BLACKLIST:
continue
if disk['product'].lower() in DISK_PRODUCT_BLACKLIST:
continue
stor, created = Storage.concurrent_get_or_create(device=dev,
sn=disk['serial_number'])
stor.device = dev
size_value, size_unit, rest = disk['coerced_size'].split(' ', 2)
size_value = size_value.replace(',', '')
stor.size = int(float(size_value) / units.size_divisor[size_unit])
stor.speed = int(disk.get('rotational_speed', 0))
label_meta = [' '.join(disk['vendor'].split()), disk['product']]
if 'pd_type' in disk:
label_meta.append(disk['pd_type'])
stor.label = ' '.join(label_meta)
disk_default = dict(
vendor = 'unknown',
product = 'unknown',
device_firmware_level = 'unknown',
pd_type = 'unknown',
coerced_size = 'unknown',
)
disk_default.update(disk)
extra = """Model: {vendor} {product}
Firmware Revision: {device_firmware_level}
Interface: {pd_type}
Size: {coerced_size}
""".format(**disk_default)
stor.model, c = ComponentModel.concurrent_get_or_create(
size=stor.size, speed=stor.speed, type=ComponentType.disk.id,
family='', extra_hash=hashlib.md5(extra).hexdigest(), extra=extra)
stor.model.name = '{} {}MiB'.format(stor.label, stor.size)
stor.model.save(priority=SAVE_PRIORITY)
stor.save(priority=SAVE_PRIORITY)
示例7: handle_lshw_storage
def handle_lshw_storage(dev, lshw, is_virtual=False, priority=0):
mount_points, storages = get_storage_from_lshw(lshw)
dev.storage_set.filter(mount_point__in=mount_points).delete()
for storage in storages:
if storage['sn']:
stor, created = Storage.concurrent_get_or_create(sn=storage['sn'],
device=dev)
stor.mount_point = storage['mount_point']
else:
stor, created = Storage.concurrent_get_or_create(
sn=None, device=dev, mount_point=storage['mount_point'])
stor.size = storage['size']
stor.speed = storage['speed']
stor.label = storage['label']
stor.model, c = ComponentModel.concurrent_get_or_create(
size=stor.size, speed=stor.speed, type=ComponentType.disk.id,
family='', extra_hash=hashlib.md5(storage['extra']).hexdigest())
stor.model.extra = storage['extra']
stor.model.name = '{} {}MiB'.format(stor.label, stor.size)
stor.model.save(priority=priority)
stor.save(priority=priority)
示例8: handle_facts_disks
def handle_facts_disks(dev, facts, is_virtual=False):
disks = {}
_cur_key = None
for k, v in facts.iteritems():
if not k.startswith('disk_'):
continue
k = k[5:]
if k.endswith('_product'):
_cur_key = 'product'
k = k[:-8]
elif k.endswith('_revision'):
_cur_key = 'revision'
k = k[:-9]
elif k.endswith('_size'):
_cur_key = 'size'
k = k[:-5]
elif k.endswith('_vendor'):
_cur_key = 'vendor'
k = k[:-7]
elif k.endswith('_serial'):
_cur_key = 'serial'
k = k[:-7]
else:
continue
disks.setdefault(k, {})[_cur_key] = v.strip()
for label, disk in disks.iteritems():
try:
if 'size' not in disk or not int(disk['size']):
continue
except ValueError:
continue
if disk['vendor'].lower() in DISK_VENDOR_BLACKLIST:
continue
if disk['product'].lower() in DISK_PRODUCT_BLACKLIST:
continue
sn = disk.get('serial', '').strip()
stor, created = Storage.concurrent_get_or_create(
device=dev,
mount_point=label,
sn=sn if sn else None,
)
stor.size = disk['size'] = int(int(disk['size']) / 1024 / 1024)
stor.label = '{} {} {}'.format(
disk['vendor'].strip(), disk['product'].strip(),
disk['revision'].strip())
stor.model, c = ComponentModel.create(
ComponentType.disk,
size=stor.size,
family=disk['vendor'].strip(),
priority=SAVE_PRIORITY,
)
stor.save(priority=SAVE_PRIORITY)
示例9: handle_lshw_storage
def handle_lshw_storage(dev, lshw, is_virtual=False, priority=0):
mount_points, storages = get_storage_from_lshw(lshw)
dev.storage_set.filter(mount_point__in=mount_points).delete()
for storage in storages:
sn = storage["sn"] if storage["sn"] else None
stor, created = Storage.concurrent_get_or_create(sn=sn, mount_point=storage["mount_point"], device=dev)
stor.size = storage["size"]
stor.speed = storage["speed"]
stor.label = storage["label"]
stor.model, c = ComponentModel.create(
ComponentType.disk, size=stor.size, speed=stor.speed, family=stor.label, priority=priority
)
stor.save(priority=priority)
示例10: parse_smartctl
def parse_smartctl(facts, dev):
disks = {}
for k, value in facts.iteritems():
m = SMARTCTL_REGEX.match(k)
if not m:
continue
disk = m.group(1)
property = m.group(2)
disks.setdefault(disk, {})[property] = value.strip()
for disk_handle, disk in disks.iteritems():
if not disk.get('serial_number') or disk.get('device_type') != 'disk':
continue
if {'user_capacity', 'vendor', 'product', 'transport_protocol'} - \
set(disk.keys()):
# not all required keys present
continue
if disk['vendor'].lower() in DISK_VENDOR_BLACKLIST:
continue
if disk['product'].lower() in DISK_PRODUCT_BLACKLIST:
continue
stor, created = Storage.concurrent_get_or_create(device=dev,
sn=disk['serial_number'])
stor.device = dev
size_value, size_unit, rest = disk['user_capacity'].split(' ', 2)
size_value = size_value.replace(',', '')
stor.size = int(int(size_value) / units.size_divisor[size_unit])
stor.speed = int(disk.get('rotational_speed', 0))
label_meta = [' '.join(disk['vendor'].split()), disk['product']]
if 'transport_protocol' in disk:
label_meta.append(disk['transport_protocol'])
stor.label = ' '.join(label_meta)
disk_default = dict(
vendor = 'unknown',
product = 'unknown',
revision = 'unknown',
transport_protocol = 'unknown',
user_capacity = 'unknown',
)
disk_default.update(disk)
extra = """Model: {vendor} {product}
Firmware Revision: {revision}
Interface: {transport_protocol}
Size: {user_capacity}
""".format(**disk_default)
stor.model, c = ComponentModel.concurrent_get_or_create(
size=stor.size, speed=stor.speed, type=ComponentType.disk.id,
family='', extra_hash=hashlib.md5(extra).hexdigest(), extra=extra)
stor.model.name = '{} {}MiB'.format(stor.label, stor.size)
stor.model.save(priority=SAVE_PRIORITY)
stor.save(priority=SAVE_PRIORITY)
示例11: handle_megaraid
def handle_megaraid(dev, disks, priority=0):
for (controller_handle, disk_handle), disk in disks.iteritems():
disk['vendor'], disk['product'], disk['serial_number'] = \
_handle_inquiry_data(
disk.get('inquiry_data', ''),
controller_handle, disk_handle
)
if not disk.get('serial_number') or disk.get('media_type') not in (
'Hard Disk Device', 'Solid State Device'):
continue
if {'coerced_size', 'vendor', 'product', 'pd_type'} - \
set(disk.keys()):
# not all required keys present
continue
if disk['vendor'].lower() in DISK_VENDOR_BLACKLIST:
continue
if disk['product'].lower() in DISK_PRODUCT_BLACKLIST:
continue
stor, created = Storage.concurrent_get_or_create(
device=dev, sn=disk['serial_number'], mount_point=None,
)
stor.device = dev
size_value, size_unit, rest = disk['coerced_size'].split(' ', 2)
size_value = size_value.replace(',', '')
stor.size = int(float(size_value) / units.size_divisor[size_unit])
stor.speed = int(disk.get('rotational_speed', 0))
label_meta = [' '.join(disk['vendor'].split()), disk['product']]
if 'pd_type' in disk:
label_meta.append(disk['pd_type'])
stor.label = ' '.join(label_meta)
disk_default = dict(
vendor='unknown',
product='unknown',
device_firmware_level='unknown',
pd_type='unknown',
coerced_size='unknown',
)
disk_default.update(disk)
stor.model, c = ComponentModel.create(
ComponentType.disk,
size=stor.size,
speed=stor.speed,
family=stor.label,
priority=priority,
)
stor.save(priority=priority)
示例12: save_storage
def save_storage(storage, dev):
mount_points = []
for item in storage:
sn = item.get("sn")
mount_point = item.get("mountpoint")
if not sn or not mount_point:
continue
label = item.get("label")
try:
size = int(item.get("size"))
except ValueError:
continue
model_name = "{} {}MiB".format(label, size)
model, c = ComponentModel.create(ComponentType.disk, size=size, family=model_name, priority=SAVE_PRIORITY)
stor = None
try:
stor = Storage.objects.get(device=dev, mount_point=mount_point)
if stor.sn != sn:
try:
stor_found_by_sn = Storage.objects.get(sn=sn)
if all(
(
stor_found_by_sn.model == model,
stor_found_by_sn.size == size,
stor_found_by_sn.label == label,
)
):
stor.mount_point = None
stor.save(priotity=SAVE_PRIORITY)
stor = stor_found_by_sn
stor.device = dev
stor.mount_point = mount_point
else:
stor = None
except Storage.DoesNotExist:
stor.sn = sn
except Storage.DoesNotExist:
try:
stor = Storage.objects.get(sn=sn)
if all((stor.model == model, stor.size == size, stor.label == label)):
stor.device = dev
stor.mount_point = mount_point
else:
stor = None
except Storage.DoesNotExist:
stor = Storage(device=dev, mount_point=mount_point, sn=sn)
if stor:
stor.model = model
stor.label = label
stor.size = size
stor.save(priority=SAVE_PRIORITY)
mount_points.append(mount_point)
dev.storage_set.exclude(mount_point__in=mount_points).update(mount_point=None)
示例13: parse_hpacu
def parse_hpacu(facts, dev):
disks = {}
for k, value in facts.iteritems():
m = HPACU_GENERAL_REGEX.match(k)
if not m:
continue
n = HPACU_LOGICAL_PHYSICAL_REGEX.match(m.group(2))
physical_disk = n.group(1) if n else None
property = n.group(2) if n else m.group(2)
if not physical_disk:
continue
disks.setdefault(physical_disk, {})[property] = value.strip()
for disk_handle, disk in disks.iteritems():
if not disk.get('serial_number'):
continue
stor, created = Storage.concurrent_get_or_create(device=dev,
sn=disk['serial_number'])
stor.device = dev
size_value, size_unit = disk['size'].split()
stor.size = int(float(size_value) / units.size_divisor[size_unit])
stor.speed = int(disk.get('rotational_speed', 0))
stor.label = '{} {}'.format(' '.join(disk['model'].split()),
disk['interface_type'])
disk_default = dict(
model = 'unknown',
firmware_revision = 'unknown',
interface_type = 'unknown',
size = 'unknown',
rotational_speed = 'unknown',
status = 'unknown',
)
disk_default.update(disk)
extra = """Model: {model}
Firmware Revision: {firmware_revision}
Interface: {interface_type}
Size: {size}
Rotational Speed: {rotational_speed}
Status: {status}""".format(**disk_default)
stor.model, c = ComponentModel.concurrent_get_or_create(
size=stor.size, speed=stor.speed, type=ComponentType.disk.id,
family='', extra_hash=hashlib.md5(extra).hexdigest(), extra=extra)
stor.model.name = '{} {}MiB'.format(stor.label, stor.size)
stor.model.save(priority=SAVE_PRIORITY)
stor.save(priority=SAVE_PRIORITY)
示例14: handle_3ware
def handle_3ware(dev, disks, priority=0):
for disk_handle, disk in disks.iteritems():
if not disk.get("serial"):
continue
stor, created = Storage.concurrent_get_or_create(device=dev, sn=disk["serial"], mount_point=None)
stor.device = dev
size_value, size_unit, trash = disk["capacity"].split(None, 2)
stor.size = int(float(size_value) / units.size_divisor[size_unit])
stor.label = disk["model"]
disk_default = dict(
model="unknown",
firmware_revision="unknown",
interface_type="unknown",
size="unknown",
rotational_speed="unknown",
status="unknown",
)
disk_default.update(disk)
stor.model, c = ComponentModel.create(ComponentType.disk, size=stor.size, family=stor.label, priority=priority)
stor.save(priority=priority)
示例15: handle_smartctl
def handle_smartctl(dev, disks, priority=0):
for disk_handle, disk in disks.iteritems():
if not disk.get('serial_number') or disk.get('device_type') != 'disk':
continue
if {'user_capacity', 'vendor', 'product', 'transport_protocol'} - \
set(disk.keys()):
# not all required keys present
continue
if disk['vendor'].lower() in DISK_VENDOR_BLACKLIST:
continue
if disk['product'].lower() in DISK_PRODUCT_BLACKLIST:
continue
stor, created = Storage.concurrent_get_or_create(
device=dev, sn=disk['serial_number'], mount_point=None,
)
stor.device = dev
size_value, size_unit, rest = disk['user_capacity'].split(' ', 2)
size_value = size_value.replace(',', '')
stor.size = int(int(size_value) / units.size_divisor[size_unit])
stor.speed = int(disk.get('rotational_speed', 0))
label_meta = [' '.join(disk['vendor'].split()), disk['product']]
if 'transport_protocol' in disk:
label_meta.append(disk['transport_protocol'])
stor.label = ' '.join(label_meta)
disk_default = dict(
vendor='unknown',
product='unknown',
revision='unknown',
transport_protocol='unknown',
user_capacity='unknown',
)
disk_default.update(disk)
stor.model, c = ComponentModel.create(
ComponentType.disk,
size=stor.size,
speed=stor.speed,
family=stor.label,
priority=priority,
)
stor.save(priority=priority)