@@ -2558,40 +2558,58 @@ public void syncVMMetaData(final Map<String, String> vmMetadatum) {
25582558 if (vmMetadatum == null || vmMetadatum .isEmpty ()) {
25592559 return ;
25602560 }
2561+ List <Pair <Pair <String , VirtualMachine .Type >, Pair <Long , String >>> vmDetails = _userVmDao .getVmsDetailByNames (vmMetadatum .keySet (), "platform" );
25612562 for (final Map .Entry <String , String > entry : vmMetadatum .entrySet ()) {
25622563 final String name = entry .getKey ();
25632564 final String platform = entry .getValue ();
25642565 if (platform == null || platform .isEmpty ()) {
25652566 continue ;
25662567 }
2567- final VMInstanceVO vm = _vmDao .findVMByInstanceName (name );
2568- if (vm != null && vm .getType () == VirtualMachine .Type .User ) {
2569- boolean changed = false ;
2570- final UserVmVO userVm = _userVmDao .findById (vm .getId ());
2571- _userVmDao .loadDetails (userVm );
2572- if ( userVm .details .containsKey ("timeoffset" )) {
2573- userVm .details .remove ("timeoffset" );
2574- changed = true ;
2575- }
2576- if (!userVm .details .containsKey ("platform" ) || !userVm .details .get ("platform" ).equals (platform )) {
2577- userVm .setDetail ("platform" , platform );
2578- changed = true ;
2579- }
2580- String pvdriver = "xenserver56" ;
2581- if ( platform .contains ("device_id" )) {
2582- pvdriver = "xenserver61" ;
2583- }
2584- if (!userVm .details .containsKey ("hypervisortoolsversion" ) || !userVm .details .get ("hypervisortoolsversion" ).equals (pvdriver )) {
2585- userVm .setDetail ("hypervisortoolsversion" , pvdriver );
2586- changed = true ;
2568+
2569+ boolean found = false ;
2570+ for (Pair <Pair <String , VirtualMachine .Type >, Pair <Long , String >> vmDetail : vmDetails ) {
2571+ Pair <String , VirtualMachine .Type > vmNameTypePair = vmDetail .first ();
2572+ if (vmNameTypePair .first ().equals (name )) {
2573+ found = true ;
2574+ if (vmNameTypePair .second () == VirtualMachine .Type .User ) {
2575+ Pair <Long , String > detailPair = vmDetail .second ();
2576+ String platformDetail = detailPair .second ();
2577+
2578+ if (platformDetail != null && platformDetail .equals (platform )) {
2579+ break ;
2580+ }
2581+ updateVmMetaData (detailPair .first (), platform );
2582+ }
2583+ break ;
25872584 }
2588- if ( changed ) {
2589- _userVmDao .saveDetails (userVm );
2585+ }
2586+
2587+ if (!found ) {
2588+ VMInstanceVO vm = _vmDao .findVMByInstanceName (name );
2589+ if (vm .getType () == VirtualMachine .Type .User ) {
2590+ updateVmMetaData (vm .getId (), platform );
25902591 }
25912592 }
25922593 }
25932594 }
25942595
2596+ // this is XenServer specific
2597+ private void updateVmMetaData (Long vmId , String platform ) {
2598+ UserVmVO userVm = _userVmDao .findById (vmId );
2599+ _userVmDao .loadDetails (userVm );
2600+ if ( userVm .details .containsKey ("timeoffset" )) {
2601+ userVm .details .remove ("timeoffset" );
2602+ }
2603+ userVm .setDetail ("platform" , platform );
2604+ String pvdriver = "xenserver56" ;
2605+ if ( platform .contains ("device_id" )) {
2606+ pvdriver = "xenserver61" ;
2607+ }
2608+ if (!userVm .details .containsKey ("hypervisortoolsversion" ) || !userVm .details .get ("hypervisortoolsversion" ).equals (pvdriver )) {
2609+ userVm .setDetail ("hypervisortoolsversion" , pvdriver );
2610+ }
2611+ _userVmDao .saveDetails (userVm );
2612+ }
25952613
25962614 private void ensureVmRunningContext (final long hostId , VMInstanceVO vm , final Event cause ) throws OperationTimedoutException , ResourceUnavailableException ,
25972615 NoTransitionException , InsufficientAddressCapacityException {
0 commit comments