def _update_perf_events_xml(xml_doc, migrate_data):
 supported_perf_events = []
 old_xml_has_perf = True
 if ('supported_perf_events' in migrate_data):
  supported_perf_events = migrate_data.supported_perf_events
 perf_events = xml_doc.findall('./perf')
 if (not perf_events):
  perf_events = etree.Element('perf')
  old_xml_has_perf = False
 else:
  perf_events = perf_events[0]
  for (_, event) in enumerate(perf_events):
   perf_events.remove(event)
 if (not supported_perf_events):
  return xml_doc
 for e in supported_perf_events:
  new_event = etree.Element('event', enabled='yes', name=e)
  perf_events.append(new_event)
 if (not old_xml_has_perf):
  xml_doc.append(perf_events)
 return xml_doc

def _update_perf_events_xml ( xml_doc , migrate_data ) : supported_perf_events = [ ] old_xml_has_perf = True if ( 'supported_perf_events' in migrate_data ) : supported_perf_events = migrate_data . supported_perf_events perf_events = xml_doc . findall ( './perf' ) if ( not perf_events ) : perf_events = etree . Element ( 'perf' ) old_xml_has_perf = False else : perf_events = perf_events [ 0 ] for ( _ , event ) in enumerate ( perf_events ) : perf_events . remove ( event ) if ( not supported_perf_events ) : return xml_doc for e in supported_perf_events : new_event = etree . Element ( 'event' , enabled = 'yes' , name = e ) perf_events . append ( new_event ) if ( not old_xml_has_perf ) : xml_doc . append ( perf_events ) return xml_doc
update xml by the supported events of destination host .