Use network adapter from OVF on deploy-as-is

This commit is contained in:
nvazquez 2020-09-21 00:12:28 -03:00 committed by Harikrishna Patnala
parent 0f5a6ee589
commit edfbed34ad
5 changed files with 41 additions and 5 deletions

View File

@ -27,14 +27,17 @@ public class DeployAsIsInfoTO {
private String destStoragePool;
@LogLevel(LogLevel.Log4jLevel.Off)
private Map<String, String> properties = new HashMap<>();
private Map<Integer, String> nicAdapterMap = new HashMap();
public DeployAsIsInfoTO() {
}
public DeployAsIsInfoTO(String templatePath, String destStoragePool, Map<String, String> properties) {
public DeployAsIsInfoTO(String templatePath, String destStoragePool, Map<String, String> properties,
Map<Integer, String> nicAdapterMap) {
this.templatePath = templatePath;
this.destStoragePool = destStoragePool;
this.properties = properties;
this.nicAdapterMap = nicAdapterMap;
}
public String getTemplatePath() {
@ -49,4 +52,7 @@ public class DeployAsIsInfoTO {
return destStoragePool;
}
public Map<Integer, String> getNicAdapterMap() {
return nicAdapterMap;
}
}

View File

@ -17,6 +17,7 @@
package org.apache.cloudstack.storage.image.deployasis;
import com.cloud.agent.api.storage.DownloadAnswer;
import com.cloud.agent.api.to.NicTO;
import com.cloud.vm.VirtualMachineProfile;
import java.util.Map;
@ -28,4 +29,6 @@ public interface DeployAsIsHelper {
String getAllocatedVirtualMachineTemplatePath(VirtualMachineProfile vm, String configuration, String destStoragePool);
String getAllocatedVirtualMachineDestinationStoragePool(VirtualMachineProfile vm);
Map<Integer, String> getAllocatedVirtualMachineNicsAdapterMapping(VirtualMachineProfile vm, NicTO[] nics);
}

View File

@ -22,6 +22,7 @@ import com.cloud.agent.api.storage.DownloadAnswer;
import com.cloud.agent.api.to.DataStoreTO;
import com.cloud.agent.api.to.DataTO;
import com.cloud.agent.api.to.DiskTO;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.deployasis.OVFConfigurationTO;
import com.cloud.agent.api.to.deployasis.OVFEulaSectionTO;
import com.cloud.agent.api.to.deployasis.OVFPropertyTO;
@ -45,6 +46,7 @@ import com.cloud.agent.api.to.deployasis.OVFNetworkTO;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@ -146,6 +148,24 @@ public class DeployAsIsHelperImpl implements DeployAsIsHelper {
return null;
}
@Override
public Map<Integer, String> getAllocatedVirtualMachineNicsAdapterMapping(VirtualMachineProfile vm, NicTO[] nics) {
Map<Integer, String> map = new HashMap<>();
List<OVFNetworkTO> networks = templateDeployAsIsDetailsDao.listNetworkRequirementsByTemplateId(vm.getTemplateId());
if (ArrayUtils.isNotEmpty(nics)) {
if (nics.length != networks.size()) {
String msg = "Different number of networks provided vs networks defined in deploy-as-is template";
LOGGER.error(msg);
return map;
}
for (int i = 0; i < nics.length; i++) {
// The nic Adapter is defined on the resource sub type
map.put(nics[i].getDeviceId(), networks.get(i).getResourceSubType());
}
}
return map;
}
private void persistTemplateDeployAsIsInformationTOList(long templateId,
List<? extends TemplateDeployAsIsInformationTO> informationTOList) {
for (TemplateDeployAsIsInformationTO informationTO : informationTOList) {

View File

@ -190,7 +190,8 @@ class VmwareVmImplementer {
Map<String, String> properties = deployAsIsHelper.getVirtualMachineDeployAsIsProperties(vm);
String destStoragePool = deployAsIsHelper.getAllocatedVirtualMachineDestinationStoragePool(vm);
String templatePath = deployAsIsHelper.getAllocatedVirtualMachineTemplatePath(vm, configuration, destStoragePool);
DeployAsIsInfoTO info = new DeployAsIsInfoTO(templatePath, destStoragePool, properties);
Map<Integer, String> nicsAdapterMapping = deployAsIsHelper.getAllocatedVirtualMachineNicsAdapterMapping(vm, to.getNics());
DeployAsIsInfoTO info = new DeployAsIsInfoTO(templatePath, destStoragePool, properties, nicsAdapterMapping);
to.setDeployAsIsInfo(info);
}

View File

@ -2223,9 +2223,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
}
}
VirtualEthernetCardType nicDeviceType = VirtualEthernetCardType.valueOf(vmSpec.getDetails().get(VmDetailConstants.NIC_ADAPTER));
if (s_logger.isDebugEnabled())
s_logger.debug("VM " + vmInternalCSName + " will be started with NIC device type: " + nicDeviceType);
VirtualEthernetCardType nicDeviceType;
NiciraNvpApiVersion.logNiciraApiVersion();
@ -2233,6 +2231,14 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
for (NicTO nicTo : sortNicsByDeviceId(nics)) {
s_logger.info("Prepare NIC device based on NicTO: " + _gson.toJson(nicTo));
String adapterTypeStr = deployAsIs ?
deployAsIsInfo.getNicAdapterMap().get(nicTo.getDeviceId()) :
vmSpec.getDetails().get(VmDetailConstants.NIC_ADAPTER);
nicDeviceType = VirtualEthernetCardType.valueOf(adapterTypeStr);
if (s_logger.isDebugEnabled()) {
s_logger.debug("VM " + vmInternalCSName + " will be started with NIC device type: " + nicDeviceType + " on NIC device " + nicTo.getDeviceId());
}
boolean configureVServiceInNexus = (nicTo.getType() == TrafficType.Guest) && (vmSpec.getDetails().containsKey("ConfigureVServiceInNexus"));
VirtualMachine.Type vmType = cmd.getVirtualMachine().getType();
Pair<ManagedObjectReference, String> networkInfo = prepareNetworkFromNicInfo(vmMo.getRunningHost(), nicTo, configureVServiceInNexus, vmType);