6464import com .cloud .dc .dao .DataCenterDaoImpl ;
6565import com .cloud .hypervisor .Hypervisor ;
6666import com .cloud .storage .DataStoreRole ;
67+ import com .cloud .storage .GuestOSVO ;
6768import com .cloud .storage .Storage ;
6869import com .cloud .storage .Storage .ImageFormat ;
6970import com .cloud .storage .VMTemplateStorageResourceAssoc ;
7071import com .cloud .storage .VMTemplateVO ;
7172import com .cloud .storage .VMTemplateZoneVO ;
73+ import com .cloud .storage .dao .GuestOSDao ;
74+ import com .cloud .storage .dao .GuestOSDaoImpl ;
7275import com .cloud .storage .dao .VMTemplateDao ;
7376import com .cloud .storage .dao .VMTemplateDaoImpl ;
7477import com .cloud .storage .dao .VMTemplateZoneDao ;
@@ -102,15 +105,13 @@ public class SystemVmTemplateRegistration {
102105 private static final String PARTIAL_TEMPLATE_FOLDER = String .format ("/template/tmpl/%d/" , Account .ACCOUNT_ID_SYSTEM );
103106 private static final String storageScriptsDir = "scripts/storage/secondary" ;
104107 private static final Integer OTHER_LINUX_ID = 99 ;
105- private static final Integer LINUX_5_ID = 15 ;
106- private static final Integer LINUX_7_ID = 183 ;
108+ private static Integer LINUX_12_ID = 363 ;
107109 private static final Integer SCRIPT_TIMEOUT = 1800000 ;
108110 private static final Integer LOCK_WAIT_TIMEOUT = 1200 ;
109111 protected static final List <CPU .CPUArch > DOWNLOADABLE_TEMPLATE_ARCH_TYPES = Arrays .asList (
110112 CPU .CPUArch .arm64
111113 );
112114
113-
114115 public static String CS_MAJOR_VERSION = null ;
115116 public static String CS_TINY_VERSION = null ;
116117
@@ -132,6 +133,8 @@ public class SystemVmTemplateRegistration {
132133 ClusterDao clusterDao ;
133134 @ Inject
134135 ConfigurationDao configurationDao ;
136+ @ Inject
137+ private GuestOSDao guestOSDao ;
135138
136139 private String systemVmTemplateVersion ;
137140
@@ -147,6 +150,7 @@ public SystemVmTemplateRegistration() {
147150 imageStoreDetailsDao = new ImageStoreDetailsDaoImpl ();
148151 clusterDao = new ClusterDaoImpl ();
149152 configurationDao = new ConfigurationDaoImpl ();
153+ guestOSDao = new GuestOSDaoImpl ();
150154 tempDownloadDir = new File (System .getProperty ("java.io.tmpdir" ));
151155 }
152156
@@ -320,7 +324,7 @@ public void setUpdated(Date updated) {
320324
321325 public static final Map <String , MetadataTemplateDetails > NewTemplateMap = new HashMap <>();
322326
323- public static final Map <Hypervisor .HypervisorType , String > RouterTemplateConfigurationNames = new HashMap <Hypervisor . HypervisorType , String >() {
327+ public static final Map <Hypervisor .HypervisorType , String > RouterTemplateConfigurationNames = new HashMap <>() {
324328 {
325329 put (Hypervisor .HypervisorType .KVM , "router.template.kvm" );
326330 put (Hypervisor .HypervisorType .VMware , "router.template.vmware" );
@@ -331,14 +335,14 @@ public void setUpdated(Date updated) {
331335 }
332336 };
333337
334- public static final Map <Hypervisor .HypervisorType , Integer > hypervisorGuestOsMap = new HashMap <Hypervisor . HypervisorType , Integer >() {
338+ public static Map <Hypervisor .HypervisorType , Integer > hypervisorGuestOsMap = new HashMap <>() {
335339 {
336- put (Hypervisor .HypervisorType .KVM , LINUX_5_ID );
340+ put (Hypervisor .HypervisorType .KVM , LINUX_12_ID );
337341 put (Hypervisor .HypervisorType .XenServer , OTHER_LINUX_ID );
338342 put (Hypervisor .HypervisorType .VMware , OTHER_LINUX_ID );
339- put (Hypervisor .HypervisorType .Hyperv , LINUX_5_ID );
340- put (Hypervisor .HypervisorType .LXC , LINUX_5_ID );
341- put (Hypervisor .HypervisorType .Ovm3 , LINUX_7_ID );
343+ put (Hypervisor .HypervisorType .Hyperv , LINUX_12_ID );
344+ put (Hypervisor .HypervisorType .LXC , LINUX_12_ID );
345+ put (Hypervisor .HypervisorType .Ovm3 , LINUX_12_ID );
342346 }
343347 };
344348
@@ -595,6 +599,23 @@ public void updateSystemVMEntries(Long templateId, Hypervisor.HypervisorType hyp
595599 vmInstanceDao .updateSystemVmTemplateId (templateId , hypervisorType );
596600 }
597601
602+ private void updateSystemVmTemplateGuestOsId () {
603+ String systemVmGuestOsName = "Debian GNU/Linux 12 (64-bit)" ; // default
604+ try {
605+ GuestOSVO guestOS = guestOSDao .findOneByDisplayName (systemVmGuestOsName );
606+ if (guestOS != null ) {
607+ LOGGER .debug ("Updating SystemVM Template Guest OS [{}] id" , systemVmGuestOsName );
608+ SystemVmTemplateRegistration .LINUX_12_ID = Math .toIntExact (guestOS .getId ());
609+ hypervisorGuestOsMap .put (Hypervisor .HypervisorType .KVM , LINUX_12_ID );
610+ hypervisorGuestOsMap .put (Hypervisor .HypervisorType .Hyperv , LINUX_12_ID );
611+ hypervisorGuestOsMap .put (Hypervisor .HypervisorType .LXC , LINUX_12_ID );
612+ hypervisorGuestOsMap .put (Hypervisor .HypervisorType .Ovm3 , LINUX_12_ID );
613+ }
614+ } catch (Exception e ) {
615+ LOGGER .warn ("Couldn't update SystemVM Template Guest OS id, due to {}" , e .getMessage ());
616+ }
617+ }
618+
598619 public void updateConfigurationParams (Map <String , String > configParams ) {
599620 for (Map .Entry <String , String > config : configParams .entrySet ()) {
600621 boolean updated = configurationDao .update (config .getKey (), config .getValue ());
@@ -813,7 +834,8 @@ public static String parseMetadataFile() {
813834 section .get ("filename" ),
814835 section .get ("downloadurl" ),
815836 section .get ("checksum" ),
816- hypervisorType .second ()));
837+ hypervisorType .second (),
838+ section .get ("guestos" )));
817839 }
818840 Ini .Section defaultSection = ini .get ("default" );
819841 return defaultSection .get ("version" ).trim ();
@@ -965,6 +987,10 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
965987 private void updateRegisteredTemplateDetails (Long templateId , MetadataTemplateDetails templateDetails ) {
966988 VMTemplateVO templateVO = vmTemplateDao .findById (templateId );
967989 templateVO .setTemplateType (Storage .TemplateType .SYSTEM );
990+ GuestOSVO guestOS = guestOSDao .findOneByDisplayName (templateDetails .getGuestOs ());
991+ if (guestOS != null ) {
992+ templateVO .setGuestOSId (guestOS .getId ());
993+ }
968994 boolean updated = vmTemplateDao .update (templateVO .getId (), templateVO );
969995 if (!updated ) {
970996 String errMsg = String .format ("updateSystemVmTemplates:Exception while updating template with id %s to be marked as 'system'" , templateId );
@@ -980,9 +1006,13 @@ private void updateRegisteredTemplateDetails(Long templateId, MetadataTemplateDe
9801006 updateConfigurationParams (configParams );
9811007 }
9821008
983- private void updateTemplateUrlAndChecksum (VMTemplateVO templateVO , MetadataTemplateDetails templateDetails ) {
1009+ private void updateTemplateUrlChecksumAndGuestOsId (VMTemplateVO templateVO , MetadataTemplateDetails templateDetails ) {
9841010 templateVO .setUrl (templateDetails .getUrl ());
9851011 templateVO .setChecksum (templateDetails .getChecksum ());
1012+ GuestOSVO guestOS = guestOSDao .findOneByDisplayName (templateDetails .getGuestOs ());
1013+ if (guestOS != null ) {
1014+ templateVO .setGuestOSId (guestOS .getId ());
1015+ }
9861016 boolean updated = vmTemplateDao .update (templateVO .getId (), templateVO );
9871017 if (!updated ) {
9881018 String errMsg = String .format ("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type %s" , templateDetails .getHypervisorType ());
@@ -1020,7 +1050,7 @@ protected boolean registerOrUpdateSystemVmTemplate(MetadataTemplateDetails templ
10201050 VMTemplateVO templateVO = vmTemplateDao .findLatestTemplateByTypeAndHypervisorAndArch (
10211051 templateDetails .getHypervisorType (), templateDetails .getArch (), Storage .TemplateType .SYSTEM );
10221052 if (templateVO != null ) {
1023- updateTemplateUrlAndChecksum (templateVO , templateDetails );
1053+ updateTemplateUrlChecksumAndGuestOsId (templateVO , templateDetails );
10241054 }
10251055 }
10261056 }
@@ -1029,6 +1059,7 @@ protected boolean registerOrUpdateSystemVmTemplate(MetadataTemplateDetails templ
10291059
10301060 public void updateSystemVmTemplates (final Connection conn ) {
10311061 LOGGER .debug ("Updating System Vm template IDs" );
1062+ updateSystemVmTemplateGuestOsId ();
10321063 Transaction .execute (new TransactionCallbackNoReturn () {
10331064 @ Override
10341065 public void doInTransactionWithoutResult (final TransactionStatus status ) {
@@ -1076,15 +1107,17 @@ protected static class MetadataTemplateDetails {
10761107 private final String checksum ;
10771108 private final CPU .CPUArch arch ;
10781109 private String downloadedFilePath ;
1110+ private final String guestOs ;
10791111
10801112 MetadataTemplateDetails (Hypervisor .HypervisorType hypervisorType , String name , String filename , String url ,
1081- String checksum , CPU .CPUArch arch ) {
1113+ String checksum , CPU .CPUArch arch , String guestOs ) {
10821114 this .hypervisorType = hypervisorType ;
10831115 this .name = name ;
10841116 this .filename = filename ;
10851117 this .url = url ;
10861118 this .checksum = checksum ;
10871119 this .arch = arch ;
1120+ this .guestOs = guestOs ;
10881121 }
10891122
10901123 public Hypervisor .HypervisorType getHypervisorType () {
@@ -1111,6 +1144,10 @@ public CPU.CPUArch getArch() {
11111144 return arch ;
11121145 }
11131146
1147+ public String getGuestOs () {
1148+ return guestOs ;
1149+ }
1150+
11141151 public String getDownloadedFilePath () {
11151152 return downloadedFilePath ;
11161153 }
0 commit comments