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