def find_orphaned_instances(xenapi):
 ctxt = context.get_admin_context(read_deleted='only')
 orphaned_instances = []
 for (vm_ref, vm_rec) in _get_applicable_vm_recs(xenapi):
  try:
   uuid = vm_rec['other_config']['nova_uuid']
   instance = db.api.instance_get_by_uuid(ctxt, uuid)
  except (KeyError, exception.InstanceNotFound):
   print_xen_object('INFO: Ignoring VM', vm_rec, indent_level=0)
   continue
  is_active_and_deleting = ((instance.vm_state == 'active') and (instance.task_state == 'deleting'))
  is_zombie_vm = ((instance.vm_state != 'active') and timeutils.is_older_than(instance.updated_at, CONF.zombie_instance_updated_at_window))
  if (is_active_and_deleting or is_zombie_vm):
   orphaned_instances.append((vm_ref, vm_rec, instance))
 return orphaned_instances

def find_orphaned_instances ( xenapi ) : ctxt = context . get_admin_context ( read_deleted = 'only' ) orphaned_instances = [ ] for ( vm_ref , vm_rec ) in _get_applicable_vm_recs ( xenapi ) : try : uuid = vm_rec [ 'other_config' ] [ 'nova_uuid' ] instance = db . api . instance_get_by_uuid ( ctxt , uuid ) except ( KeyError , exception . InstanceNotFound ) : print_xen_object ( 'INFO: Ignoring VM' , vm_rec , indent_level = 0 ) continue is_active_and_deleting = ( ( instance . vm_state == 'active' ) and ( instance . task_state == 'deleting' ) ) is_zombie_vm = ( ( instance . vm_state != 'active' ) and timeutils . is_older_than ( instance . updated_at , CONF . zombie_instance_updated_at_window ) ) if ( is_active_and_deleting or is_zombie_vm ) : orphaned_instances . append ( ( vm_ref , vm_rec , instance ) ) return orphaned_instances
find and return a list of orphaned instances .