mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	[VMware][Deploy-as-is] OVF properties not importing when template is uploaded from local (#5861)
* Fix ova upload missing details * Refactor and cleanup * Unused import
This commit is contained in:
		
							parent
							
								
									1ed0830bc4
								
							
						
					
					
						commit
						84f5768e64
					
				| @ -20,7 +20,7 @@ | ||||
| package org.apache.cloudstack.storage.command; | ||||
| 
 | ||||
| import com.cloud.agent.api.Answer; | ||||
| import com.cloud.utils.Pair; | ||||
| import com.cloud.agent.api.to.OVFInformationTO; | ||||
| 
 | ||||
| public class UploadStatusAnswer extends Answer { | ||||
|     public static enum UploadStatus { | ||||
| @ -32,8 +32,7 @@ public class UploadStatusAnswer extends Answer { | ||||
|     private long physicalSize = 0; | ||||
|     private String installPath = null; | ||||
|     private int downloadPercent = 0; | ||||
|     private Pair<String, String> guestOsInfo; | ||||
|     private String minimumHardwareVersion; | ||||
|     private OVFInformationTO ovfInformationTO; | ||||
| 
 | ||||
|     protected UploadStatusAnswer() { | ||||
|     } | ||||
| @ -89,19 +88,11 @@ public class UploadStatusAnswer extends Answer { | ||||
|         this.downloadPercent = downloadPercent; | ||||
|     } | ||||
| 
 | ||||
|     public Pair<String, String> getGuestOsInfo() { | ||||
|         return guestOsInfo; | ||||
|     public OVFInformationTO getOvfInformationTO() { | ||||
|         return ovfInformationTO; | ||||
|     } | ||||
| 
 | ||||
|     public void setGuestOsInfo(Pair<String, String> guestOsInfo) { | ||||
|         this.guestOsInfo = guestOsInfo; | ||||
|     } | ||||
| 
 | ||||
|     public void setMinimumHardwareVersion(String minimumHardwareVersion) { | ||||
|         this.minimumHardwareVersion = minimumHardwareVersion; | ||||
|     } | ||||
| 
 | ||||
|     public String getMinimumHardwareVersion() { | ||||
|         return minimumHardwareVersion; | ||||
|     public void setOvfInformationTO(OVFInformationTO ovfInformationTO) { | ||||
|         this.ovfInformationTO = ovfInformationTO; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -33,6 +33,7 @@ import java.util.stream.Collectors; | ||||
| import javax.inject.Inject; | ||||
| 
 | ||||
| import com.cloud.agent.api.to.NfsTO; | ||||
| import com.cloud.agent.api.to.OVFInformationTO; | ||||
| import com.cloud.storage.DataStoreRole; | ||||
| import com.cloud.storage.Upload; | ||||
| import org.apache.cloudstack.storage.image.deployasis.DeployAsIsHelper; | ||||
| @ -207,8 +208,9 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { | ||||
|         TemplateDataStoreVO tmpltStoreVO = _templateStoreDao.findByStoreTemplate(store.getId(), obj.getId()); | ||||
|         if (tmpltStoreVO != null) { | ||||
|             if (tmpltStoreVO.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) { | ||||
|                 if (template.isDeployAsIs()) { | ||||
|                     boolean persistDeployAsIs = deployAsIsHelper.persistTemplateDeployAsIsDetails(template.getId(), answer, tmpltStoreVO); | ||||
|                 if (template.isDeployAsIs() && answer != null) { | ||||
|                     OVFInformationTO ovfInformationTO = answer.getOvfInformationTO(); | ||||
|                     boolean persistDeployAsIs = deployAsIsHelper.persistTemplateOVFInformationAndUpdateGuestOS(template.getId(), ovfInformationTO, tmpltStoreVO); | ||||
|                     if (!persistDeployAsIs) { | ||||
|                         LOGGER.info("Failed persisting deploy-as-is template details for template " + template.getName()); | ||||
|                         return null; | ||||
|  | ||||
| @ -18,7 +18,6 @@ | ||||
|  */ | ||||
| package org.apache.cloudstack.storage.image.deployasis; | ||||
| 
 | ||||
| import com.cloud.agent.api.storage.DownloadAnswer; | ||||
| import com.cloud.agent.api.to.NicTO; | ||||
| import com.cloud.agent.api.to.OVFInformationTO; | ||||
| import com.cloud.agent.api.to.deployasis.OVFConfigurationTO; | ||||
| @ -100,41 +99,44 @@ public class DeployAsIsHelperImpl implements DeployAsIsHelper { | ||||
|         gson = builder.create(); | ||||
|     } | ||||
| 
 | ||||
|     public boolean persistTemplateDeployAsIsDetails(long templateId, DownloadAnswer answer, TemplateDataStoreVO tmpltStoreVO) { | ||||
|         try { | ||||
|             OVFInformationTO ovfInformationTO = answer.getOvfInformationTO(); | ||||
|             if (ovfInformationTO != null) { | ||||
|                 List<OVFPropertyTO> ovfProperties = ovfInformationTO.getProperties(); | ||||
|                 List<OVFNetworkTO> networkRequirements = ovfInformationTO.getNetworks(); | ||||
|                 OVFVirtualHardwareSectionTO ovfHardwareSection = ovfInformationTO.getHardwareSection(); | ||||
|                 List<OVFEulaSectionTO> eulaSections = ovfInformationTO.getEulaSections(); | ||||
|                 Pair<String, String> guestOsInfo = ovfInformationTO.getGuestOsInfo(); | ||||
|     private void persistTemplateOVFInformation(long templateId, OVFInformationTO ovfInformationTO) { | ||||
|         List<OVFPropertyTO> ovfProperties = ovfInformationTO.getProperties(); | ||||
|         List<OVFNetworkTO> networkRequirements = ovfInformationTO.getNetworks(); | ||||
|         OVFVirtualHardwareSectionTO ovfHardwareSection = ovfInformationTO.getHardwareSection(); | ||||
|         List<OVFEulaSectionTO> eulaSections = ovfInformationTO.getEulaSections(); | ||||
|         Pair<String, String> guestOsInfo = ovfInformationTO.getGuestOsInfo(); | ||||
| 
 | ||||
|                 if (CollectionUtils.isNotEmpty(ovfProperties)) { | ||||
|                     persistTemplateDeployAsIsInformationTOList(templateId, ovfProperties); | ||||
|                 } | ||||
|                 if (CollectionUtils.isNotEmpty(networkRequirements)) { | ||||
|                     persistTemplateDeployAsIsInformationTOList(templateId, networkRequirements); | ||||
|                 } | ||||
|                 if (CollectionUtils.isNotEmpty(eulaSections)) { | ||||
|                     persistTemplateDeployAsIsInformationTOList(templateId, eulaSections); | ||||
|                 } | ||||
|                 String minimumHardwareVersion = null; | ||||
|                 if (ovfHardwareSection != null) { | ||||
|                     if (CollectionUtils.isNotEmpty(ovfHardwareSection.getConfigurations())) { | ||||
|                         persistTemplateDeployAsIsInformationTOList(templateId, ovfHardwareSection.getConfigurations()); | ||||
|                     } | ||||
|                     if (CollectionUtils.isNotEmpty(ovfHardwareSection.getCommonHardwareItems())) { | ||||
|                         persistTemplateDeployAsIsInformationTOList(templateId, ovfHardwareSection.getCommonHardwareItems()); | ||||
|                     } | ||||
|                     minimumHardwareVersion = ovfHardwareSection.getMinimiumHardwareVersion(); | ||||
|                 } | ||||
|                 if (guestOsInfo != null) { | ||||
|                     String osType = guestOsInfo.first(); | ||||
|                     String osDescription = guestOsInfo.second(); | ||||
|                     LOGGER.info("Guest OS information retrieved from the template: " + osType + " - " + osDescription); | ||||
|                     handleGuestOsFromOVFDescriptor(templateId, osType, osDescription, minimumHardwareVersion); | ||||
|                 } | ||||
|         if (CollectionUtils.isNotEmpty(ovfProperties)) { | ||||
|             persistTemplateDeployAsIsInformationTOList(templateId, ovfProperties); | ||||
|         } | ||||
|         if (CollectionUtils.isNotEmpty(networkRequirements)) { | ||||
|             persistTemplateDeployAsIsInformationTOList(templateId, networkRequirements); | ||||
|         } | ||||
|         if (CollectionUtils.isNotEmpty(eulaSections)) { | ||||
|             persistTemplateDeployAsIsInformationTOList(templateId, eulaSections); | ||||
|         } | ||||
|         String minimumHardwareVersion = null; | ||||
|         if (ovfHardwareSection != null) { | ||||
|             if (CollectionUtils.isNotEmpty(ovfHardwareSection.getConfigurations())) { | ||||
|                 persistTemplateDeployAsIsInformationTOList(templateId, ovfHardwareSection.getConfigurations()); | ||||
|             } | ||||
|             if (CollectionUtils.isNotEmpty(ovfHardwareSection.getCommonHardwareItems())) { | ||||
|                 persistTemplateDeployAsIsInformationTOList(templateId, ovfHardwareSection.getCommonHardwareItems()); | ||||
|             } | ||||
|             minimumHardwareVersion = ovfHardwareSection.getMinimiumHardwareVersion(); | ||||
|         } | ||||
|         if (guestOsInfo != null) { | ||||
|             String osType = guestOsInfo.first(); | ||||
|             String osDescription = guestOsInfo.second(); | ||||
|             LOGGER.info("Guest OS information retrieved from the template: " + osType + " - " + osDescription); | ||||
|             handleGuestOsFromOVFDescriptor(templateId, osType, osDescription, minimumHardwareVersion); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public boolean persistTemplateOVFInformationAndUpdateGuestOS(long templateId, OVFInformationTO ovfInformationTO, TemplateDataStoreVO tmpltStoreVO) { | ||||
|         try { | ||||
|             if (ovfInformationTO != null) { | ||||
|                 persistTemplateOVFInformation(templateId, ovfInformationTO); | ||||
|             } | ||||
|         } catch (Exception e) { | ||||
|             LOGGER.error("Error persisting deploy-as-is details for template " + templateId, e); | ||||
| @ -151,7 +153,7 @@ public class DeployAsIsHelperImpl implements DeployAsIsHelper { | ||||
|     /** | ||||
|      * Returns the mapped guest OS from the OVF file of the template to the CloudStack database OS ID | ||||
|      */ | ||||
|     public Long retrieveTemplateGuestOsIdFromGuestOsInfo(long templateId, String guestOsType, String guestOsDescription, | ||||
|     private Long retrieveTemplateGuestOsIdFromGuestOsInfo(long templateId, String guestOsType, String guestOsDescription, | ||||
|                                                          String minimumHardwareVersion) { | ||||
|         VMTemplateVO template = templateDao.findById(templateId); | ||||
|         Hypervisor.HypervisorType hypervisor = template.getHypervisorType(); | ||||
| @ -337,7 +339,7 @@ public class DeployAsIsHelperImpl implements DeployAsIsHelper { | ||||
|         return map; | ||||
|     } | ||||
| 
 | ||||
|     private void persistTemplateDeployAsIsInformationTOList(long templateId, | ||||
|     public void persistTemplateDeployAsIsInformationTOList(long templateId, | ||||
|                                                             List<? extends TemplateDeployAsIsInformationTO> informationTOList) { | ||||
|         for (TemplateDeployAsIsInformationTO informationTO : informationTOList) { | ||||
|             String propKey = getKeyFromInformationTO(informationTO); | ||||
|  | ||||
| @ -25,8 +25,7 @@ import java.util.concurrent.TimeUnit; | ||||
| import javax.inject.Inject; | ||||
| import javax.naming.ConfigurationException; | ||||
| 
 | ||||
| import com.cloud.hypervisor.Hypervisor; | ||||
| import com.cloud.utils.Pair; | ||||
| import com.cloud.agent.api.to.OVFInformationTO; | ||||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; | ||||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; | ||||
| import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint; | ||||
| @ -412,18 +411,14 @@ public class ImageStoreUploadMonitorImpl extends ManagerBase implements ImageSto | ||||
| 
 | ||||
|                             VMTemplateVO templateUpdate = _templateDao.createForUpdate(); | ||||
|                             templateUpdate.setSize(answer.getVirtualSize()); | ||||
|                             if (template.getHypervisorType() == Hypervisor.HypervisorType.VMware) { | ||||
|                                 Pair<String, String> guestOsInfo = answer.getGuestOsInfo(); | ||||
|                                 String minimumHardwareVersion = answer.getMinimumHardwareVersion(); | ||||
|                                 String osType = guestOsInfo.first(); | ||||
|                                 String osDescription = guestOsInfo.second(); | ||||
|                                 s_logger.info("Guest OS information retrieved from the template: " + osType + " - " + osDescription); | ||||
|                                 try { | ||||
|                                     Long guestOsId = deployAsIsHelper.retrieveTemplateGuestOsIdFromGuestOsInfo(template.getId(), | ||||
|                                             osType, osDescription, minimumHardwareVersion); | ||||
|                                     templateUpdate.setGuestOSId(guestOsId); | ||||
|                                 } catch (CloudRuntimeException e) { | ||||
|                                     s_logger.error("Could not map the guest OS to a CloudStack guest OS", e); | ||||
| 
 | ||||
|                             OVFInformationTO ovfInformationTO = answer.getOvfInformationTO(); | ||||
|                             if (template.isDeployAsIs() && ovfInformationTO != null) { | ||||
|                                 s_logger.debug("Received OVF information from the uploaded template"); | ||||
|                                 boolean persistDeployAsIs = deployAsIsHelper.persistTemplateOVFInformationAndUpdateGuestOS(tmpTemplate.getId(), ovfInformationTO, tmpTemplateDataStore); | ||||
|                                 if (!persistDeployAsIs) { | ||||
|                                     s_logger.info("Failed persisting deploy-as-is template details for template " + template.getName()); | ||||
|                                     break; | ||||
|                                 } | ||||
|                             } | ||||
|                             _templateDao.update(tmpTemplate.getId(), templateUpdate); | ||||
|  | ||||
| @ -16,8 +16,8 @@ | ||||
| // under the License. | ||||
| package org.apache.cloudstack.storage.image.deployasis; | ||||
| 
 | ||||
| import com.cloud.agent.api.storage.DownloadAnswer; | ||||
| import com.cloud.agent.api.to.NicTO; | ||||
| import com.cloud.agent.api.to.OVFInformationTO; | ||||
| import com.cloud.vm.VirtualMachineProfile; | ||||
| import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; | ||||
| 
 | ||||
| @ -25,9 +25,7 @@ import java.util.Map; | ||||
| 
 | ||||
| public interface DeployAsIsHelper { | ||||
| 
 | ||||
|     boolean persistTemplateDeployAsIsDetails(long templateId, DownloadAnswer answer, TemplateDataStoreVO tmpltStoreVO); | ||||
|     boolean persistTemplateOVFInformationAndUpdateGuestOS(long templateId, OVFInformationTO ovfInformationTO, TemplateDataStoreVO tmpltStoreVO); | ||||
|     Map<String, String> getVirtualMachineDeployAsIsProperties(VirtualMachineProfile vmId); | ||||
|     Map<Integer, String> getAllocatedVirtualMachineNicsAdapterMapping(VirtualMachineProfile vm, NicTO[] nics); | ||||
|     Long retrieveTemplateGuestOsIdFromGuestOsInfo(long templateId, String guestOsType, String guestOsDescription, | ||||
|                                                   String minimumHardwareVersion); | ||||
| } | ||||
|  | ||||
| @ -2280,8 +2280,9 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S | ||||
|                 answer.setInstallPath(uploadEntity.getTmpltPath()); | ||||
|                 answer.setPhysicalSize(uploadEntity.getPhysicalSize()); | ||||
|                 answer.setDownloadPercent(100); | ||||
|                 answer.setGuestOsInfo(uploadEntity.getGuestOsInfo()); | ||||
|                 answer.setMinimumHardwareVersion(uploadEntity.getMinimumHardwareVersion()); | ||||
|                 if (uploadEntity.getOvfInformationTO() != null) { | ||||
|                     answer.setOvfInformationTO(uploadEntity.getOvfInformationTO()); | ||||
|                 } | ||||
|                 uploadEntityStateMap.remove(entityUuid); | ||||
|                 return answer; | ||||
|             } else if (uploadEntity.getUploadState() == UploadEntity.Status.IN_PROGRESS) { | ||||
| @ -3424,12 +3425,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S | ||||
|                 uploadEntity.setVirtualSize(info.virtualSize); | ||||
|                 uploadEntity.setPhysicalSize(info.size); | ||||
|                 if (info.ovfInformationTO != null) { | ||||
|                     if (info.ovfInformationTO.getGuestOsInfo() != null) { | ||||
|                         uploadEntity.setGuestOsInfo(info.ovfInformationTO.getGuestOsInfo()); | ||||
|                     } | ||||
|                     if (info.ovfInformationTO.getHardwareSection() != null) { | ||||
|                         uploadEntity.setMinimumHardwareVersion(info.ovfInformationTO.getHardwareSection().getMinimiumHardwareVersion()); | ||||
|                     } | ||||
|                     uploadEntity.setOvfInformationTO(info.ovfInformationTO); | ||||
|                 } | ||||
|                 break; | ||||
|             } | ||||
|  | ||||
| @ -18,8 +18,8 @@ | ||||
| package org.apache.cloudstack.storage.template; | ||||
| 
 | ||||
| 
 | ||||
| import com.cloud.agent.api.to.OVFInformationTO; | ||||
| import com.cloud.storage.Storage; | ||||
| import com.cloud.utils.Pair; | ||||
| 
 | ||||
| public class UploadEntity { | ||||
|     private long downloadedsize; | ||||
| @ -36,8 +36,7 @@ public class UploadEntity { | ||||
|     private String description; | ||||
|     private long contentLength; | ||||
|     private long processTimeout; | ||||
|     private Pair<String, String> guestOsInfo; | ||||
|     private String minimumHardwareVersion; | ||||
|     private OVFInformationTO ovfInformationTO; | ||||
| 
 | ||||
|     public static enum ResourceType { | ||||
|         VOLUME, TEMPLATE | ||||
| @ -211,19 +210,11 @@ public class UploadEntity { | ||||
|         this.contentLength = contentLength; | ||||
|     } | ||||
| 
 | ||||
|     public Pair<String, String> getGuestOsInfo() { | ||||
|         return guestOsInfo; | ||||
|     public OVFInformationTO getOvfInformationTO() { | ||||
|         return ovfInformationTO; | ||||
|     } | ||||
| 
 | ||||
|     public void setGuestOsInfo(Pair<String, String> guestOsInfo) { | ||||
|         this.guestOsInfo = guestOsInfo; | ||||
|     } | ||||
| 
 | ||||
|     public void setMinimumHardwareVersion(String minimumHardwareVersion) { | ||||
|         this.minimumHardwareVersion = minimumHardwareVersion; | ||||
|     } | ||||
| 
 | ||||
|     public String getMinimumHardwareVersion() { | ||||
|         return minimumHardwareVersion; | ||||
|     public void setOvfInformationTO(OVFInformationTO ovfInformationTO) { | ||||
|         this.ovfInformationTO = ovfInformationTO; | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user