def from_pci_stats(pci_stats):
"""Create and return a PciDevicePoolList from the data stored in the db,
which can be either the serialized object, or, prior to the creation of the
device pool objects, a simple dict or a list of such dicts.
"""
pools = []
if isinstance(pci_stats, six.string_types):
try:
pci_stats = jsonutils.loads(pci_stats)
except (ValueError, TypeError):
pci_stats = None
if pci_stats:
# Check for object-ness, or old-style storage format.
if 'zun_object.namespace' in pci_stats:
return PciDevicePoolList.obj_from_primitive(pci_stats)
else:
# This can be either a dict or a list of dicts
if isinstance(pci_stats, list):
pools = [PciDevicePool.from_dict(stat)
for stat in pci_stats]
else:
pools = [PciDevicePool.from_dict(pci_stats)]
return PciDevicePoolList(objects=pools)
评论列表
文章目录