def instance_topology_from_instance(instance):
 if isinstance(instance, obj_instance.Instance):
  instance_numa_topology = instance.numa_topology
 elif ('numa_topology' in instance):
  instance_numa_topology = instance['numa_topology']
 elif ('uuid' in instance):
  try:
   instance_numa_topology = objects.InstanceNUMATopology.get_by_instance_uuid(context.get_admin_context(), instance['uuid'])
  except exception.NumaTopologyNotFound:
   instance_numa_topology = None
 else:
  instance_numa_topology = None
 if instance_numa_topology:
  if isinstance(instance_numa_topology, six.string_types):
   instance_numa_topology = objects.InstanceNUMATopology.obj_from_primitive(jsonutils.loads(instance_numa_topology))
  elif isinstance(instance_numa_topology, dict):
   dict_cells = instance_numa_topology.get('cells')
   if dict_cells:
    cells = [objects.InstanceNUMACell(id=cell['id'], cpuset=set(cell['cpuset']), memory=cell['memory'], pagesize=cell.get('pagesize'), cpu_pinning=cell.get('cpu_pinning_raw'), cpu_policy=cell.get('cpu_policy'), cpu_thread_policy=cell.get('cpu_thread_policy')) for cell in dict_cells]
    instance_numa_topology = objects.InstanceNUMATopology(cells=cells)
 return instance_numa_topology

def instance_topology_from_instance ( instance ) : if isinstance ( instance , obj_instance . Instance ) : instance_numa_topology = instance . numa_topology elif ( 'numa_topology' in instance ) : instance_numa_topology = instance [ 'numa_topology' ] elif ( 'uuid' in instance ) : try : instance_numa_topology = objects . InstanceNUMATopology . get_by_instance_uuid ( context . get_admin_context ( ) , instance [ 'uuid' ] ) except exception . NumaTopologyNotFound : instance_numa_topology = None else : instance_numa_topology = None if instance_numa_topology : if isinstance ( instance_numa_topology , six . string_types ) : instance_numa_topology = objects . InstanceNUMATopology . obj_from_primitive ( jsonutils . loads ( instance_numa_topology ) ) elif isinstance ( instance_numa_topology , dict ) : dict_cells = instance_numa_topology . get ( 'cells' ) if dict_cells : cells = [ objects . InstanceNUMACell ( id = cell [ 'id' ] , cpuset = set ( cell [ 'cpuset' ] ) , memory = cell [ 'memory' ] , pagesize = cell . get ( 'pagesize' ) , cpu_pinning = cell . get ( 'cpu_pinning_raw' ) , cpu_policy = cell . get ( 'cpu_policy' ) , cpu_thread_policy = cell . get ( 'cpu_thread_policy' ) ) for cell in dict_cells ] instance_numa_topology = objects . InstanceNUMATopology ( cells = cells ) return instance_numa_topology
extract numa topology from myriad instance representations .