def _instances_fill_metadata(context, instances, manual_joins=None):
 uuids = [inst['uuid'] for inst in instances]
 if (manual_joins is None):
  manual_joins = ['metadata', 'system_metadata']
 meta = collections.defaultdict(list)
 if ('metadata' in manual_joins):
  for row in _instance_metadata_get_multi(context, uuids):
   meta[row['instance_uuid']].append(row)
 sys_meta = collections.defaultdict(list)
 if ('system_metadata' in manual_joins):
  for row in _instance_system_metadata_get_multi(context, uuids):
   sys_meta[row['instance_uuid']].append(row)
 pcidevs = collections.defaultdict(list)
 if ('pci_devices' in manual_joins):
  for row in _instance_pcidevs_get_multi(context, uuids):
   pcidevs[row['instance_uuid']].append(row)
 filled_instances = []
 for inst in instances:
  inst = dict(inst)
  inst['system_metadata'] = sys_meta[inst['uuid']]
  inst['metadata'] = meta[inst['uuid']]
  if ('pci_devices' in manual_joins):
   inst['pci_devices'] = pcidevs[inst['uuid']]
  filled_instances.append(inst)
 return filled_instances

def _instances_fill_metadata ( context , instances , manual_joins = None ) : uuids = [ inst [ 'uuid' ] for inst in instances ] if ( manual_joins is None ) : manual_joins = [ 'metadata' , 'system_metadata' ] meta = collections . defaultdict ( list ) if ( 'metadata' in manual_joins ) : for row in _instance_metadata_get_multi ( context , uuids ) : meta [ row [ 'instance_uuid' ] ] . append ( row ) sys_meta = collections . defaultdict ( list ) if ( 'system_metadata' in manual_joins ) : for row in _instance_system_metadata_get_multi ( context , uuids ) : sys_meta [ row [ 'instance_uuid' ] ] . append ( row ) pcidevs = collections . defaultdict ( list ) if ( 'pci_devices' in manual_joins ) : for row in _instance_pcidevs_get_multi ( context , uuids ) : pcidevs [ row [ 'instance_uuid' ] ] . append ( row ) filled_instances = [ ] for inst in instances : inst = dict ( inst ) inst [ 'system_metadata' ] = sys_meta [ inst [ 'uuid' ] ] inst [ 'metadata' ] = meta [ inst [ 'uuid' ] ] if ( 'pci_devices' in manual_joins ) : inst [ 'pci_devices' ] = pcidevs [ inst [ 'uuid' ] ] filled_instances . append ( inst ) return filled_instances
selectively fill instances with manually-joined metadata .