Пример #1
0
    def _from_db_object(context, compute_node, db_compute_node):
        """Converts a database entity to a formal object."""
        special_cases = set(['pci_device_pools'])
        fields = set(compute_node.fields) - special_cases
        for field in fields:
            if field == 'numa_topology':
                numa_obj = NUMATopology._from_dict(
                    db_compute_node['numa_topology'])
                compute_node.numa_topology = numa_obj
            else:
                setattr(compute_node, field, db_compute_node[field])

        pci_stats = db_compute_node.get('pci_stats')
        if pci_stats is not None:
            pci_stats = pci_device_pool.from_pci_stats(pci_stats)
        compute_node.pci_device_pools = pci_stats
        compute_node.obj_reset_changes(recursive=True)
        return compute_node
Пример #2
0
    def _from_db_object(context, compute_node, db_compute_node):
        """Converts a database entity to a formal object."""
        special_cases = set(['pci_device_pools'])
        fields = set(compute_node.fields) - special_cases
        for field in fields:
            if field == 'numa_topology':
                numa_obj = NUMATopology._from_dict(
                    db_compute_node['numa_topology'])
                compute_node.numa_topology = numa_obj
            else:
                setattr(compute_node, field, db_compute_node[field])

        pci_stats = db_compute_node.get('pci_stats')
        if pci_stats is not None:
            pci_stats = pci_device_pool.from_pci_stats(pci_stats)
        compute_node.pci_device_pools = pci_stats
        compute_node.obj_reset_changes(recursive=True)
        return compute_node
Пример #3
0
 def to_device_pools_obj(self):
     """Return the contents of the pools as a PciDevicePoolList object."""
     stats = [x for x in self]
     return pci_device_pool.from_pci_stats(stats)
Пример #4
0
 def test_from_pci_stats_bad(self):
     prim = "not a valid json string for an object"
     pools = pci_device_pool.from_pci_stats(prim)
     self.assertEqual(len(pools), 0)
Пример #5
0
 def test_from_pci_stats_dict(self):
     prim = fake_pci.fake_pool_dict
     pools = pci_device_pool.from_pci_stats(prim)
     self.assertEqual(len(pools), 1)
Пример #6
0
 def test_from_pci_stats_list_of_dicts(self):
     prim = fake_pci.fake_pool_dict
     pools = pci_device_pool.from_pci_stats([prim, prim])
     self.assertEqual(len(pools), 2)
Пример #7
0
 def test_from_pci_stats_obj(self):
     prim = fake_pci.fake_pool_list_primitive
     pools = pci_device_pool.from_pci_stats(prim)
     self.assertEqual(len(pools), 1)
Пример #8
0
 def test_from_pci_stats_bad(self):
     prim = "not a valid json string for an object"
     pools = pci_device_pool.from_pci_stats(prim)
     self.assertEqual(len(pools), 0)
Пример #9
0
 def test_from_pci_stats_list_of_dicts(self):
     prim = fake_pci.fake_pool_dict
     pools = pci_device_pool.from_pci_stats([prim, prim])
     self.assertEqual(len(pools), 2)
Пример #10
0
 def test_from_pci_stats_dict(self):
     prim = fake_pci.fake_pool_dict
     pools = pci_device_pool.from_pci_stats(prim)
     self.assertEqual(len(pools), 1)
Пример #11
0
 def test_from_pci_stats_obj(self):
     prim = fake_pci.fake_pool_list_primitive
     pools = pci_device_pool.from_pci_stats(prim)
     self.assertEqual(len(pools), 1)