コード例 #1
0
ファイル: test_api_ralph.py プロジェクト: xliiv/ralph_assets
 def test_get_asset_with_empty_asset_source(self):
     """Getting an asset with empty 'source' field should also succeed."""
     category = AssetCategoryFactory()
     model = AssetModelFactory(category=category)
     asset = DCAssetFactory(model=model, source=None)
     asset_data = get_asset(asset.device_info.ralph_device_id)
     self.assertEqual(asset_data['source'], None)
コード例 #2
0
 def test_get_asset_with_empty_asset_source(self):
     """Getting an asset with empty 'source' field should also succeed."""
     category = AssetCategoryFactory()
     model = AssetModelFactory(category=category)
     asset = DCAssetFactory(model=model, source=None)
     asset_data = get_asset(asset.device_info.ralph_device_id)
     self.assertEqual(asset_data['source'], None)
コード例 #3
0
 def test_get_asset(self):
     """Test get asset information by ralph_device_id."""
     support1 = DCSupportFactory()
     support2 = DCSupportFactory()
     category = AssetCategoryFactory()
     model = AssetModelFactory(category=category)
     asset = DCAssetFactory(
         model=model,
         supports=[support1, support2],
     )
     asset_data = get_asset(asset.device_info.ralph_device_id)
     self.assertEqual(asset_data['sn'], asset.sn)
     self.assertEqual(asset_data['barcode'], asset.barcode)
     self.assertEqual(asset_data['supports'][0]['name'], support1.name)
     self.assertEqual(
         asset_data['supports'][0]['url'],
         support1.get_absolute_url(),
     )
     self.assertEqual(asset_data['supports'][1]['name'], support2.name)
     self.assertEqual(
         asset_data['supports'][1]['url'],
         support2.get_absolute_url(),
     )
     self.assertEqual(
         asset_data['required_support'], asset.required_support,
     )
コード例 #4
0
 def test_get_asset(self):
     """Test get asset information by ralph_device_id."""
     support1 = DCSupportFactory()
     support2 = DCSupportFactory()
     category = AssetCategoryFactory()
     model = AssetModelFactory(category=category)
     asset = DCAssetFactory(
         model=model,
         supports=[support1, support2],
     )
     asset_data = get_asset(asset.device_info.ralph_device_id)
     self.assertEqual(asset_data['sn'], asset.sn)
     self.assertEqual(asset_data['barcode'], asset.barcode)
     self.assertEqual(asset_data['supports'][0]['name'], support1.name)
     self.assertEqual(asset_data['supports'][0]['url'], support1.url)
     self.assertEqual(asset_data['supports'][1]['name'], support2.name)
     self.assertEqual(asset_data['supports'][1]['url'], support2.url)
     self.assertEqual(
         asset_data['required_support'],
         asset.required_support,
     )
コード例 #5
0
 def test_get_asset(self):
     """Test get asset information by ralph_device_id"""
     asset = Asset.objects.get(pk=self.asset_id)
     asset_data = get_asset(asset.device_info.ralph_device_id)
     self.assertEqual(asset_data, self.asset_data_raw)
コード例 #6
0
def get_device_data(device):
    """
    Generate a dict with all information that is stored in the database
    about this device, in a format compatible with that returned by the
    discovery plugins.
    """

    data = {
        'id': device.id,
        'system_ip_addresses': [
            ip.address for ip in
            device.ipaddress_set.filter(is_management=False)
        ],
        'management_ip_addresses': [
            ip.address for ip in
            device.ipaddress_set.filter(is_management=True)
        ],
        'mac_addresses': [
            eth.mac for eth in device.ethernet_set.all()
        ],
    }
    if device.name != 'unknown':
        data['hostname'] = device.name
    if device.model is not None:
        data['model_name'] = device.model.name
        data['type'] = DeviceType.from_id(device.model.type).raw
    if device.sn is not None:
        data['serial_number'] = device.sn
    if device.chassis_position:
        data['chassis_position'] = device.chassis_position
    if device.dc:
        data['data_center'] = device.dc
    if device.rack:
        data['rack'] = device.rack
    if device.management:
        data['management'] = device.management.address
    data['memory'] = [
        {
            'label': m.label,
            'size': m.size,
            'speed': m.speed,
            'index': m.index,
        } for m in device.memory_set.order_by('index')
    ]
    data['processors'] = [
        {
            'model_name': p.model.name if p.model else '',
            'speed': p.speed,
            'cores': p.get_cores(),
            'family': p.model.family if p.model else '',
            'label': p.label,
            'index': p.index,
        } for p in device.processor_set.order_by('index')
    ]
    disks = []
    for disk in device.storage_set.order_by('sn', 'mount_point'):
        disk_data = {
            'label': disk.label,
            'size': disk.size,
        }
        if disk.sn:
            disk_data['serial_number'] = disk.sn
        if disk.mount_point:
            disk_data['mount_point'] = disk.mount_point
        if disk.model:
            disk_data.update({
                'model_name': disk.model.name,
                'family': disk.model.family,
            })
        disks.append(disk_data)
    data['disks'] = disks
    data['disk_exports'] = [
        {
            'serial_number': share.wwn,
            'full': share.full,
            'size': share.size,
            'snapshot_size': share.snapshot_size,
            'label': share.label,
            'share_id': share.share_id,
            'model_name': share.model.name if share.model else '',
        } for share in device.diskshare_set.order_by('wwn')
    ]
    disk_shares = []
    for mount in device.disksharemount_set.order_by('volume', 'address'):
        mount_data = {
            'serial_number': mount.share.wwn if mount.share else '',
            'size': mount.size,
            'address': mount.address.address if mount.address else '',
            'is_virtual': mount.is_virtual,
            'volume': mount.volume,
        }
        if mount.server:
            mount_data['server'] = {
                'serial_number': mount.server.sn,
            }
        else:
            mount_data['server'] = None
        disk_shares.append(mount_data)
    data['disk_shares'] = disk_shares
    data['installed_software'] = [
        {
            'label': soft.label,
            'version': soft.version,
            'path': soft.path,
            'serial_number': soft.sn,
            'model_name': soft.model.name if soft.model else '',
        } for soft in device.software_set.order_by('label', 'version')
    ]
    data['fibrechannel_cards'] = [
        {
            'physical_id': fc.physical_id,
            'label': fc.label,
            'model_name': fc.model.name if fc.model else '',
        } for fc in device.fibrechannel_set.order_by('label')
    ]
    data['parts'] = [
        {
            'serial_number': part.sn,
            'label': part.label,
            'boot_firmware': part.boot_firmware,
            'hard_firmware': part.hard_firmware,
            'diag_firmware': part.diag_firmware,
            'mgmt_firmware': part.mgmt_firmware,
            'model_name': part.model.name if part.model else '',
            'type': ComponentType.from_id(
                part.model.type,
            ).raw if part.model else '',
        } for part in device.genericcomponent_set.order_by('sn')
    ]
    if device.model and device.model.type in (DeviceType.switch_stack,):
        data['subdevices'] = [
            get_device_data(dev)
            for dev in device.logicalchild_set.order_by('id')
        ]
    else:
        data['subdevices'] = [
            get_device_data(dev)
            for dev in device.child_set.order_by('id')
        ]
    if device.operatingsystem_set.exists():
        system = device.operatingsystem_set.all()[0]
        data['system_label'] = system.label
        data['system_memory'] = system.memory
        data['system_storage'] = system.storage
        data['system_cores_count'] = system.cores_count
        if system.model:
            data['system_family'] = system.model.family
    if 'ralph_assets' in settings.INSTALLED_APPS:
        from ralph_assets.api_ralph import get_asset
        asset = get_asset(device.id)
        if asset:
            data['asset'] = '{}, sn: {}'.format(asset['model'], asset['sn'])
        else:
            data['asset'] = None
    return data
コード例 #7
0
ファイル: test_api_ralph.py プロジェクト: xliiv/ralph_assets
 def test_none_existisng_asset(self):
     """Getting an assets when assest does not exist"""
     self.assertEqual(get_asset(666), None)
コード例 #8
0
 def test_none_existisng_asset(self):
     """Getting an assets when assest does not exist"""
     self.assertEqual(get_asset(666), None)