@@ -106,7 +106,6 @@ public class SystemVmTemplateRegistration {
106106 private static final String storageScriptsDir = "scripts/storage/secondary" ;
107107 private static final Integer OTHER_LINUX_ID = 99 ;
108108 private static Integer LINUX_12_ID = 363 ;
109- private static final Integer LINUX_7_ID = 183 ;
110109 private static final Integer SCRIPT_TIMEOUT = 1800000 ;
111110 private static final Integer LOCK_WAIT_TIMEOUT = 1200 ;
112111 protected static final List <CPU .CPUArch > DOWNLOADABLE_TEMPLATE_ARCH_TYPES = Arrays .asList (
@@ -325,7 +324,7 @@ public void setUpdated(Date updated) {
325324
326325 public static final Map <String , MetadataTemplateDetails > NewTemplateMap = new HashMap <>();
327326
328- public static final Map <Hypervisor .HypervisorType , String > RouterTemplateConfigurationNames = new HashMap <Hypervisor . HypervisorType , String >() {
327+ public static final Map <Hypervisor .HypervisorType , String > RouterTemplateConfigurationNames = new HashMap <>() {
329328 {
330329 put (Hypervisor .HypervisorType .KVM , "router.template.kvm" );
331330 put (Hypervisor .HypervisorType .VMware , "router.template.vmware" );
@@ -336,14 +335,14 @@ public void setUpdated(Date updated) {
336335 }
337336 };
338337
339- public static Map <Hypervisor .HypervisorType , Integer > hypervisorGuestOsMap = new HashMap <Hypervisor . HypervisorType , Integer >() {
338+ public static Map <Hypervisor .HypervisorType , Integer > hypervisorGuestOsMap = new HashMap <>() {
340339 {
341340 put (Hypervisor .HypervisorType .KVM , LINUX_12_ID );
342341 put (Hypervisor .HypervisorType .XenServer , OTHER_LINUX_ID );
343342 put (Hypervisor .HypervisorType .VMware , OTHER_LINUX_ID );
344343 put (Hypervisor .HypervisorType .Hyperv , LINUX_12_ID );
345344 put (Hypervisor .HypervisorType .LXC , LINUX_12_ID );
346- put (Hypervisor .HypervisorType .Ovm3 , LINUX_7_ID );
345+ put (Hypervisor .HypervisorType .Ovm3 , LINUX_12_ID );
347346 }
348347 };
349348
@@ -600,15 +599,20 @@ public void updateSystemVMEntries(Long templateId, Hypervisor.HypervisorType hyp
600599 vmInstanceDao .updateSystemVmTemplateId (templateId , hypervisorType );
601600 }
602601
603- public void updateSystemVmTemplateGuestOsId () {
604- String systemVmGuestOsName = "Debian GNU/Linux 12 (64-bit)" ;
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 );
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 ());
612616 }
613617 }
614618
@@ -748,7 +752,6 @@ public void registerTemplateForNonExistingEntries(Hypervisor.HypervisorType hype
748752 Long templateId = null ;
749753 try {
750754 MetadataTemplateDetails templateDetails = getMetadataTemplateDetails (hypervisor , arch );
751- updateSystemVmTemplateGuestOsId ();
752755 templateId = performTemplateRegistrationOperations (hypervisor , name ,
753756 templateDetails .getArch (), templateDetails .getUrl (),
754757 templateDetails .getChecksum (), hypervisorImageFormat .get (hypervisor ),
@@ -831,7 +834,8 @@ public static String parseMetadataFile() {
831834 section .get ("filename" ),
832835 section .get ("downloadurl" ),
833836 section .get ("checksum" ),
834- hypervisorType .second ()));
837+ hypervisorType .second (),
838+ section .get ("guestos" )));
835839 }
836840 Ini .Section defaultSection = ini .get ("default" );
837841 return defaultSection .get ("version" ).trim ();
@@ -983,6 +987,10 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
983987 private void updateRegisteredTemplateDetails (Long templateId , MetadataTemplateDetails templateDetails ) {
984988 VMTemplateVO templateVO = vmTemplateDao .findById (templateId );
985989 templateVO .setTemplateType (Storage .TemplateType .SYSTEM );
990+ GuestOSVO guestOS = guestOSDao .findOneByDisplayName (templateDetails .getGuestOs ());
991+ if (guestOS != null ) {
992+ templateVO .setGuestOSId (guestOS .getId ());
993+ }
986994 boolean updated = vmTemplateDao .update (templateVO .getId (), templateVO );
987995 if (!updated ) {
988996 String errMsg = String .format ("updateSystemVmTemplates:Exception while updating template with id %s to be marked as 'system'" , templateId );
@@ -998,9 +1006,13 @@ private void updateRegisteredTemplateDetails(Long templateId, MetadataTemplateDe
9981006 updateConfigurationParams (configParams );
9991007 }
10001008
1001- private void updateTemplateUrlAndChecksum (VMTemplateVO templateVO , MetadataTemplateDetails templateDetails ) {
1009+ private void updateTemplateUrlChecksumAndGuestOsId (VMTemplateVO templateVO , MetadataTemplateDetails templateDetails ) {
10021010 templateVO .setUrl (templateDetails .getUrl ());
10031011 templateVO .setChecksum (templateDetails .getChecksum ());
1012+ GuestOSVO guestOS = guestOSDao .findOneByDisplayName (templateDetails .getGuestOs ());
1013+ if (guestOS != null ) {
1014+ templateVO .setGuestOSId (guestOS .getId ());
1015+ }
10041016 boolean updated = vmTemplateDao .update (templateVO .getId (), templateVO );
10051017 if (!updated ) {
10061018 String errMsg = String .format ("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type %s" , templateDetails .getHypervisorType ());
@@ -1038,7 +1050,7 @@ protected boolean registerOrUpdateSystemVmTemplate(MetadataTemplateDetails templ
10381050 VMTemplateVO templateVO = vmTemplateDao .findLatestTemplateByTypeAndHypervisorAndArch (
10391051 templateDetails .getHypervisorType (), templateDetails .getArch (), Storage .TemplateType .SYSTEM );
10401052 if (templateVO != null ) {
1041- updateTemplateUrlAndChecksum (templateVO , templateDetails );
1053+ updateTemplateUrlChecksumAndGuestOsId (templateVO , templateDetails );
10421054 }
10431055 }
10441056 }
@@ -1047,6 +1059,7 @@ protected boolean registerOrUpdateSystemVmTemplate(MetadataTemplateDetails templ
10471059
10481060 public void updateSystemVmTemplates (final Connection conn ) {
10491061 LOGGER .debug ("Updating System Vm template IDs" );
1062+ updateSystemVmTemplateGuestOsId ();
10501063 Transaction .execute (new TransactionCallbackNoReturn () {
10511064 @ Override
10521065 public void doInTransactionWithoutResult (final TransactionStatus status ) {
@@ -1094,15 +1107,17 @@ protected static class MetadataTemplateDetails {
10941107 private final String checksum ;
10951108 private final CPU .CPUArch arch ;
10961109 private String downloadedFilePath ;
1110+ private final String guestOs ;
10971111
10981112 MetadataTemplateDetails (Hypervisor .HypervisorType hypervisorType , String name , String filename , String url ,
1099- String checksum , CPU .CPUArch arch ) {
1113+ String checksum , CPU .CPUArch arch , String guestOs ) {
11001114 this .hypervisorType = hypervisorType ;
11011115 this .name = name ;
11021116 this .filename = filename ;
11031117 this .url = url ;
11041118 this .checksum = checksum ;
11051119 this .arch = arch ;
1120+ this .guestOs = guestOs ;
11061121 }
11071122
11081123 public Hypervisor .HypervisorType getHypervisorType () {
@@ -1129,6 +1144,10 @@ public CPU.CPUArch getArch() {
11291144 return arch ;
11301145 }
11311146
1147+ public String getGuestOs () {
1148+ return guestOs ;
1149+ }
1150+
11321151 public String getDownloadedFilePath () {
11331152 return downloadedFilePath ;
11341153 }
0 commit comments