本文整理汇总了Python中ralph.discovery.models.DeviceModel类的典型用法代码示例。如果您正苦于以下问题:Python DeviceModel类的具体用法?Python DeviceModel怎么用?Python DeviceModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DeviceModel类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
self.device_model = DeviceModel(type=DeviceType.rack_server, name="ziew-X")
self.device_model.save()
self.device = Device(
model=self.device_model,
sn='123456789',
name='ziew',
)
self.device.save()
示例2: _save_device
def _save_device(ip, name, model_name, sn, mac):
model, model_created = DeviceModel.concurrent_get_or_create(
name = 'Onstor %s' % model_name, type=DeviceType.storage.id)
dev, dev_created = Device.concurrent_get_or_create(sn=sn, model=model)
dev.save()
ipaddr, ip_created = IPAddress.concurrent_get_or_create(address=ip)
ipaddr.device = dev
ipaddr.is_management = True
ipaddr.save(update_last_seen=True)
dev.management = ipaddr
dev.save(update_last_seen=True)
return dev
示例3: _save_device
def _save_device(ip, name, model_name, sn):
model, model_created = DeviceModel.concurrent_get_or_create(
name='3PAR %s' % model_name,
defaults={'type': DeviceType.storage.id},
)
dev = Device.create(sn=sn, model=model)
ipaddr, ip_created = IPAddress.concurrent_get_or_create(address=ip)
ipaddr.device = dev
ipaddr.is_management = True
ipaddr.save()
dev.management = ipaddr
dev.save()
return dev
示例4: _make_dc_rack
def _make_dc_rack(dc_no, rack_no):
if dc_no is None:
return None, None
dev_model, created = DeviceModel.concurrent_get_or_create(
name='Data center', type=DeviceType.data_center.id)
dc, created = Device.concurrent_get_or_create(sn=dc_no,
model=dev_model)
if created:
dc.name = dc_no
dc.save(update_last_seen=True)
if rack_no is None:
rack = None
else:
rack_name = 'Rack %s' % rack_no
dev_model, created = DeviceModel.concurrent_get_or_create(
name='Rack', type=DeviceType.rack.id)
rack, created = Device.concurrent_get_or_create(
sn=rack_name, model=dev_model)
if created:
rack.name = rack_name
rack.parent = dc
rack.save(update_last_seen=True)
return dc, rack
示例5: _make_dc
def _make_dc(dc_no):
if dc_no is None:
return
dev_model, created = DeviceModel.concurrent_get_or_create(
name='Data center',
defaults={
'type': DeviceType.data_center.id,
},
)
dc, created = Device.concurrent_get_or_create(
sn=dc_no,
defaults={
'model': dev_model,
},
)
if created:
dc.name = dc_no
dc.save(update_last_seen=True)
return dc
示例6: add_model
def add_model(self, name, device_type):
dm = DeviceModel()
dm.model_type = device_type,
dm.name = name
dm.save()
return dm
示例7: GetDeviceDataTest
class GetDeviceDataTest(TestCase):
def setUp(self):
self.device_model = DeviceModel(type=DeviceType.rack_server, name="ziew-X")
self.device_model.save()
self.device = Device(model=self.device_model, sn="123456789", name="ziew")
self.device.save()
def test_basic_data(self):
data = get_device_data(Device.objects.get(sn="123456789"))
self.assertEqual(data["serial_number"], "123456789")
self.assertEqual(data["hostname"], "ziew")
self.assertEqual(data["type"], "rack server")
self.assertEqual(data["model_name"], "ziew-X")
def test_position(self):
self.device.chassis_position = 3
self.device.dc = "dc3"
self.device.rack = "232"
self.device.save()
data = get_device_data(Device.objects.get(sn="123456789"))
self.assertEqual(data["chassis_position"], 3)
self.assertEqual(data["data_center"], "dc3")
self.assertEqual(data["rack"], "232")
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)
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)
def test_disks(self):
model = ComponentModel(type=ComponentType.disk, name="HP DG0300BALVP SAS 307200MiB, 10000RPM")
model.save()
Storage(sn="abc3", device=self.device, label="ziew", mount_point="/dev/hda", model=model, size=307200).save()
data = get_device_data(Device.objects.get(sn="123456789"))
disks = data["disks"]
self.assertEqual(len(disks), 1)
self.assertEqual(disks[0]["size"], 307200)
self.assertEqual(disks[0]["serial_number"], "abc3")
self.assertEqual(disks[0]["mount_point"], "/dev/hda")
def test_fc(self):
model = ComponentModel(type=ComponentType.fibre, name="FC-336")
model.save()
FibreChannel(physical_id="deadbeefcafe", label="ziew", device=self.device, model=model).save()
data = get_device_data(Device.objects.get(sn="123456789"))
fc = data["fibrechannel_cards"]
self.assertEqual(len(fc), 1)
self.assertEqual(fc[0]["physical_id"], "deadbeefcafe")
self.assertEqual(fc[0]["model_name"], "FC-336")
def test_mac_addresses(self):
for i in xrange(5):
mac = "deadbeefcaf%d" % i
Ethernet(mac=mac, device=self.device).save()
def test_parts(self):
model = ComponentModel(type=ComponentType.management, name="weapons of mass destruction")
model.save()
GenericComponent(label="ziew", device=self.device, model=model).save()
data = get_device_data(Device.objects.get(sn="123456789"))
parts = data["parts"]
self.assertEqual(parts[0]["type"], "management")
self.assertEqual(parts[0]["model_name"], "weapons of mass destruction")
self.assertEqual(len(parts), 1)
def test_software(self):
model = ComponentModel(type=ComponentType.software, name="cobol")
model.save()
Software(
label="cobol", device=self.device, model=model, version="1.0.0", path="/usr/bin/cobol", sn="0000001"
).save()
data = get_device_data(Device.objects.get(sn="123456789"))
soft = data["installed_software"]
self.assertEqual(soft[0]["version"], "1.0.0")
self.assertEqual(soft[0]["model_name"], "cobol")
self.assertEqual(len(soft), 1)
def test_disk_shares_and_exports(self):
model = ComponentModel(type=ComponentType.share, name="3par share")
model.save()
#.........这里部分代码省略.........
示例8: SetDeviceDataTest
class SetDeviceDataTest(TestCase):
def setUp(self):
self.device_model = DeviceModel(type=DeviceType.rack_server, name="ziew-X")
self.device_model.save()
self.device = Device(model=self.device_model, sn="123456789", name="ziew")
self.device.save()
def test_basic_data(self):
data = {
"serial_number": "aaa123456789",
"hostname": "mervin",
"data_center": "chicago",
"barcode": "00000",
"rack": "i31",
"chassis_position": "4",
"management": "10.10.10.2",
}
set_device_data(self.device, data)
self.device.save()
device = Device.objects.get(sn="aaa123456789")
self.assertEqual(device.sn, "aaa123456789")
self.assertEqual(device.name, "mervin")
self.assertEqual(device.dc, "chicago")
self.assertEqual(device.barcode, "00000")
self.assertEqual(device.rack, "i31")
self.assertEqual(device.chassis_position, 4)
self.assertEqual(device.management.address, "10.10.10.2")
def test_basic_data_with_asset(self):
asset = DCAssetFactory()
asset.model.category.is_blade = False
asset.model.category.save()
data = {
"serial_number": "aaa123456789",
"hostname": "mervin",
"data_center": "chicago",
"barcode": "00000",
"rack": "i31",
"chassis_position": "4",
"management": "10.10.10.2",
"asset": asset,
}
warnings = []
set_device_data(self.device, data, warnings=warnings)
self.device.save()
device = Device.objects.get(sn="aaa123456789")
self.assertIsNone(device.dc)
self.assertIsNone(device.rack)
self.assertIsNone(device.chassis_position)
self.assertIsNone(device.management)
self.assertEqual(
warnings,
[
"You can not set data for `chassis_position` here - skipped. " "Use assets module.",
"You can not set data for `data_center` here - skipped. " "Use assets module.",
"You can not set data for `rack` here - skipped. " "Use assets module.",
"Management IP address (10.10.10.2) has been ignored. To " "change them, please use the Assets module.",
],
)
def test_model_name(self):
data = {"type": "blade_server", "model_name": "ziew-Y"}
set_device_data(self.device, data)
self.device.save()
device = Device.objects.get(sn="123456789")
self.assertEqual(device.model.name, "ziew-Y")
self.assertEqual(device.model.type, DeviceType.blade_server)
data = {"type": "rack_server", "model_name": "ziew-X"}
set_device_data(self.device, data)
self.device.save()
device = Device.objects.get(sn="123456789")
self.assertEqual(device.model.name, "ziew-X")
self.assertEqual(device.model.type, DeviceType.rack_server)
def test_disks(self):
data = {
"disks": [
{
"serial_number": "1234",
"size": "128",
"mount_point": "/dev/sda",
"label": "sda",
"family": "Simpsons",
},
{"size": "512", "mount_point": "/dev/sdb", "label": "sdb", "family": "Jetsons"},
]
}
set_device_data(self.device, data)
self.device.save()
device = Device.objects.get(sn="123456789")
disks = list(device.storage_set.order_by("label"))
self.assertEqual(disks[0].mount_point, "/dev/sda")
self.assertEqual(disks[0].sn, "1234")
self.assertEqual(disks[0].model.family, "Simpsons")
self.assertEqual(disks[1].sn, None)
self.assertEqual(disks[1].mount_point, "/dev/sdb")
self.assertEqual(disks[1].model.family, "Jetsons")
self.assertEqual(len(disks), 2)
data = {
"disks": [
#.........这里部分代码省略.........
示例9: GetDeviceDataTest
class GetDeviceDataTest(TestCase):
def setUp(self):
self.device_model = DeviceModel(
type=DeviceType.rack_server, name="ziew-X")
self.device_model.save()
self.device = Device(
model=self.device_model,
sn='123456789',
name='ziew',
)
self.device.save()
def test_basic_data(self):
data = get_device_data(Device.objects.get(sn='123456789'))
self.assertEqual(data['serial_number'], '123456789')
self.assertEqual(data['hostname'], 'ziew')
self.assertEqual(data['type'], 'rack server')
self.assertEqual(data['model_name'], 'ziew-X')
def test_position(self):
self.device.chassis_position = 3
self.device.dc = 'dc3'
self.device.rack = '232'
self.device.save()
data = get_device_data(Device.objects.get(sn='123456789'))
self.assertEqual(data['chassis_position'], 3)
self.assertEqual(data['data_center'], 'dc3')
self.assertEqual(data['rack'], '232')
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)
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)
def test_disks(self):
model = ComponentModel(
type=ComponentType.disk,
name="HP DG0300BALVP SAS 307200MiB, 10000RPM",
)
model.save()
Storage(
sn="abc3",
device=self.device,
label="ziew",
mount_point="/dev/hda",
model=model,
size=307200,
).save()
data = get_device_data(Device.objects.get(sn='123456789'))
disks = data['disks']
self.assertEqual(len(disks), 1)
self.assertEqual(disks[0]['size'], 307200)
self.assertEqual(disks[0]['serial_number'], "abc3")
self.assertEqual(disks[0]['mount_point'], "/dev/hda")
def test_fc(self):
model = ComponentModel(
type=ComponentType.fibre,
name="FC-336",
)
model.save()
FibreChannel(
physical_id='deadbeefcafe',
label='ziew',
device=self.device,
#.........这里部分代码省略.........
示例10: SetDeviceDataTest
class SetDeviceDataTest(TestCase):
def setUp(self):
self.device_model = DeviceModel(
type=DeviceType.rack_server,
name="ziew-X",
)
self.device_model.save()
self.device = Device(
model=self.device_model,
sn='123456789',
name='ziew',
)
self.device.save()
def test_basic_data(self):
data = {
'serial_number': 'aaa123456789',
'hostname': 'mervin',
'data_center': 'chicago',
'barcode': '00000',
'rack': 'i31',
'chassis_position': '4',
}
set_device_data(self.device, data)
self.device.save()
device = Device.objects.get(sn='aaa123456789')
self.assertEqual(device.sn, 'aaa123456789')
self.assertEqual(device.name, 'mervin')
self.assertEqual(device.dc, 'chicago')
self.assertEqual(device.barcode, '00000')
self.assertEqual(device.rack, 'i31')
self.assertEqual(device.chassis_position, 4)
def test_model_name(self):
data = {
'type': 'blade_server',
'model_name': 'ziew-Y',
}
set_device_data(self.device, data)
self.device.save()
device = Device.objects.get(sn='123456789')
self.assertEqual(device.model.name, 'ziew-Y')
self.assertEqual(device.model.type, DeviceType.blade_server)
data = {
'type': 'rack_server',
'model_name': 'ziew-X',
}
set_device_data(self.device, data)
self.device.save()
device = Device.objects.get(sn='123456789')
self.assertEqual(device.model.name, 'ziew-X')
self.assertEqual(device.model.type, DeviceType.rack_server)
def test_disks(self):
data = {
'disks': [
{
'serial_number': '1234',
'size': '128',
'mount_point': '/dev/sda',
'label': 'sda',
'family': 'Simpsons',
},
{
'size': '512',
'mount_point': '/dev/sdb',
'label': 'sdb',
'family': 'Jetsons',
},
],
}
set_device_data(self.device, data)
self.device.save()
device = Device.objects.get(sn='123456789')
disks = list(device.storage_set.order_by('label'))
self.assertEqual(disks[0].mount_point, '/dev/sda')
self.assertEqual(disks[0].sn, '1234')
self.assertEqual(disks[0].model.family, 'Simpsons')
self.assertEqual(disks[1].sn, None)
self.assertEqual(disks[1].mount_point, '/dev/sdb')
self.assertEqual(disks[1].model.family, 'Jetsons')
self.assertEqual(len(disks), 2)
data = {
'disks': [
{
'mount_point': '/dev/sda',
'family': 'Simpsons',
},
{
'serial_number': '12346',
'mount_point': '/dev/sdb',
},
],
}
set_device_data(self.device, data)
self.device.save()
device = Device.objects.get(sn='123456789')
disks = list(device.storage_set.order_by('label'))
self.assertEqual(disks[0].mount_point, '/dev/sda')
#.........这里部分代码省略.........