178178import com .cloud .configuration .ConfigurationManager ;
179179import com .cloud .configuration .ConfigurationManagerImpl ;
180180import com .cloud .configuration .Resource .ResourceType ;
181+ import com .cloud .cpu .CPU ;
181182import com .cloud .dc .ClusterVO ;
182183import com .cloud .dc .DataCenterVO ;
183184import com .cloud .dc .VsphereStoragePolicyVO ;
@@ -3585,6 +3586,40 @@ public ImageStore discoverImageStore(String name, String url, String providerNam
35853586 return (ImageStore )_dataStoreMgr .getDataStore (store .getId (), DataStoreRole .Image );
35863587 }
35873588
3589+ protected void registerSystemVmTemplateForHypervisorArch (final HypervisorType hypervisorType ,
3590+ final CPU .CPUArch arch , final Long zoneId , final String url , final DataStore store ,
3591+ final SystemVmTemplateRegistration systemVmTemplateRegistration , final String filePath ,
3592+ final Pair <String , Long > storeUrlAndId , final String nfsVersion ) {
3593+ if (HypervisorType .Simulator .equals (hypervisorType )) {
3594+ return ;
3595+ }
3596+ String templateName = getValidTemplateName (zoneId , hypervisorType );
3597+ Long templateId = systemVmTemplateRegistration .getRegisteredTemplateId (templateName , arch );
3598+ VMTemplateVO vmTemplateVO = null ;
3599+ TemplateDataStoreVO templateDataStoreVO = null ;
3600+ if (templateId != null ) {
3601+ vmTemplateVO = _templateDao .findById (templateId );
3602+ templateDataStoreVO = _templateStoreDao .findByStoreTemplate (store .getId (), templateId );
3603+ if (templateDataStoreVO != null ) {
3604+ try {
3605+ if (systemVmTemplateRegistration .validateIfSeeded (templateDataStoreVO , url ,
3606+ templateDataStoreVO .getInstallPath (), nfsVersion )) {
3607+ return ;
3608+ }
3609+ } catch (Exception e ) {
3610+ logger .error ("Failed to validated if template is seeded" , e );
3611+ }
3612+ }
3613+ }
3614+ SystemVmTemplateRegistration .mountStore (storeUrlAndId .first (), filePath , nfsVersion );
3615+ if (templateDataStoreVO != null && vmTemplateVO != null ) {
3616+ systemVmTemplateRegistration .registerTemplate (hypervisorType , templateName , storeUrlAndId , vmTemplateVO ,
3617+ templateDataStoreVO , filePath );
3618+ } else {
3619+ systemVmTemplateRegistration .registerTemplate (hypervisorType , arch , templateName , storeUrlAndId , filePath );
3620+ }
3621+ }
3622+
35883623 private void registerSystemVmTemplateOnFirstNfsStore (Long zoneId , String providerName , String url , DataStore store ) {
35893624 if (DataStoreProvider .NFS_IMAGE .equals (providerName ) && zoneId != null ) {
35903625 Transaction .execute (new TransactionCallbackNoReturn () {
@@ -3593,8 +3628,8 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
35933628 List <ImageStoreVO > stores = _imageStoreDao .listAllStoresInZoneExceptId (zoneId , providerName ,
35943629 DataStoreRole .Image , store .getId ());
35953630 if (CollectionUtils .isEmpty (stores )) {
3596- List <HypervisorType > hypervisorTypes = _clusterDao . getAvailableHypervisorInZone ( zoneId );
3597- Set < HypervisorType > hypervisorTypeSet = new HashSet <>( hypervisorTypes );
3631+ List <Pair < HypervisorType , CPU . CPUArch >> hypervisorTypes =
3632+ _clusterDao . listDistinctHypervisorsArchAcrossClusters ( zoneId );
35983633 TransactionLegacy txn = TransactionLegacy .open ("AutomaticTemplateRegister" );
35993634 SystemVmTemplateRegistration systemVmTemplateRegistration = new SystemVmTemplateRegistration ();
36003635 String filePath = null ;
@@ -3605,38 +3640,15 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
36053640 }
36063641 Pair <String , Long > storeUrlAndId = new Pair <>(url , store .getId ());
36073642 String nfsVersion = imageStoreDetailsUtil .getNfsVersion (store .getId ());
3608- for (HypervisorType hypervisorType : hypervisorTypeSet ) {
3643+ for (Pair < HypervisorType , CPU . CPUArch > hypervisorArchType : hypervisorTypes ) {
36093644 try {
3610- if (HypervisorType .Simulator == hypervisorType ) {
3611- continue ;
3612- }
3613- String templateName = getValidTemplateName (zoneId , hypervisorType );
3614- Long templateId = systemVmTemplateRegistration .getRegisteredTemplateId (templateName );
3615- VMTemplateVO vmTemplateVO = null ;
3616- TemplateDataStoreVO templateDataStoreVO = null ;
3617- if (templateId != null ) {
3618- vmTemplateVO = _templateDao .findById (templateId );
3619- templateDataStoreVO = _templateStoreDao .findByStoreTemplate (store .getId (), templateId );
3620- if (templateDataStoreVO != null ) {
3621- try {
3622- if (systemVmTemplateRegistration .validateIfSeeded (templateDataStoreVO ,
3623- url , templateDataStoreVO .getInstallPath (), nfsVersion )) {
3624- continue ;
3625- }
3626- } catch (Exception e ) {
3627- logger .error ("Failed to validated if template is seeded" , e );
3628- }
3629- }
3630- }
3631- SystemVmTemplateRegistration .mountStore (storeUrlAndId .first (), filePath , nfsVersion );
3632- if (templateDataStoreVO != null && vmTemplateVO != null ) {
3633- systemVmTemplateRegistration .registerTemplate (hypervisorType , templateName , storeUrlAndId , vmTemplateVO , templateDataStoreVO , filePath );
3634- } else {
3635- systemVmTemplateRegistration .registerTemplate (hypervisorType , templateName , storeUrlAndId , filePath );
3636- }
3645+ registerSystemVmTemplateForHypervisorArch (hypervisorArchType .first (),
3646+ hypervisorArchType .second (), zoneId , url , store ,
3647+ systemVmTemplateRegistration , filePath , storeUrlAndId , nfsVersion );
36373648 } catch (CloudRuntimeException e ) {
36383649 SystemVmTemplateRegistration .unmountStore (filePath );
3639- logger .error (String .format ("Failed to register systemVM template for hypervisor: %s" , hypervisorType .name ()), e );
3650+ logger .error ("Failed to register system VM template for hypervisor: {} {}" ,
3651+ hypervisorArchType .first ().name (), hypervisorArchType .second ().name (), e );
36403652 }
36413653 }
36423654 } catch (Exception e ) {
0 commit comments