DaanHoogland commented on a change in pull request #4021:
URL: https://github.com/apache/cloudstack/pull/4021#discussion_r419403819
##########
File path:
plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/guru/VMwareGuru.java
##########
@@ -172,326 +157,59 @@
public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru,
Configurable {
private static final Logger s_logger = Logger.getLogger(VMwareGuru.class);
- @Inject
- private NetworkDao _networkDao;
- @Inject
- private GuestOSDao _guestOsDao;
- @Inject
- private GuestOSHypervisorDao _guestOsHypervisorDao;
- @Inject
- private HostDao _hostDao;
- @Inject
- private HostDetailsDao _hostDetailsDao;
- @Inject
- private ClusterDetailsDao _clusterDetailsDao;
- @Inject
- private CommandExecLogDao _cmdExecLogDao;
- @Inject
- private VmwareManager _vmwareMgr;
- @Inject
- private SecondaryStorageVmManager _secStorageMgr;
- @Inject
- private NetworkModel _networkMgr;
- @Inject
- private NicDao _nicDao;
- @Inject
- private DomainRouterDao _domainRouterDao;
- @Inject
- private PhysicalNetworkTrafficTypeDao _physicalNetworkTrafficTypeDao;
- @Inject
- private VMInstanceDao _vmDao;
- @Inject
- private VirtualMachineManager vmManager;
- @Inject
- private ClusterManager _clusterMgr;
- @Inject
- VolumeDao _volumeDao;
- @Inject
- ResourceLimitService _resourceLimitService;
- @Inject
- PrimaryDataStoreDao _storagePoolDao;
- @Inject
- VolumeDataFactory _volFactory;
- @Inject
- private VmwareDatacenterDao vmwareDatacenterDao;
- @Inject
- private VmwareDatacenterZoneMapDao vmwareDatacenterZoneMapDao;
- @Inject
- private ServiceOfferingDao serviceOfferingDao;
- @Inject
- private VMTemplatePoolDao templateStoragePoolDao;
- @Inject
- private VMTemplateDao vmTemplateDao;
- @Inject
- private UserVmDao userVmDao;
- @Inject
- private DiskOfferingDao diskOfferingDao;
- @Inject
- private PhysicalNetworkDao physicalNetworkDao;
- @Inject
- private TemplateOVFPropertiesDao templateOVFPropertiesDao;
+
+ private VmwareVmImplementer vmwareVmImplementer;
+
+ @Inject NetworkDao _networkDao;
+ @Inject GuestOSDao _guestOsDao;
+ @Inject HostDao _hostDao;
+ @Inject HostDetailsDao _hostDetailsDao;
+ @Inject ClusterDetailsDao _clusterDetailsDao;
+ @Inject CommandExecLogDao _cmdExecLogDao;
+ @Inject VmwareManager _vmwareMgr;
+ @Inject SecondaryStorageVmManager _secStorageMgr;
+ @Inject NicDao _nicDao;
+ @Inject PhysicalNetworkTrafficTypeDao _physicalNetworkTrafficTypeDao;
+ @Inject VMInstanceDao _vmDao;
+ @Inject VirtualMachineManager vmManager;
+ @Inject ClusterManager _clusterMgr;
+ @Inject VolumeDao _volumeDao;
+ @Inject ResourceLimitService _resourceLimitService;
+ @Inject PrimaryDataStoreDao _storagePoolDao;
+ @Inject VolumeDataFactory _volFactory;
+ @Inject VmwareDatacenterDao vmwareDatacenterDao;
+ @Inject VmwareDatacenterZoneMapDao vmwareDatacenterZoneMapDao;
+ @Inject ServiceOfferingDao serviceOfferingDao;
+ @Inject VMTemplatePoolDao templateStoragePoolDao;
+ @Inject VMTemplateDao vmTemplateDao;
+ @Inject UserVmDao userVmDao;
+ @Inject DiskOfferingDao diskOfferingDao;
+ @Inject PhysicalNetworkDao physicalNetworkDao;
protected VMwareGuru() {
super();
}
public static final ConfigKey<Boolean> VmwareReserveCpu = new
ConfigKey<Boolean>(Boolean.class, "vmware.reserve.cpu", "Advanced", "false",
- "Specify whether or not to reserve CPU when deploying an instance.",
true, ConfigKey.Scope.Cluster,
- null);
+ "Specify whether or not to reserve CPU when deploying an
instance.", true, ConfigKey.Scope.Cluster, null);
public static final ConfigKey<Boolean> VmwareReserveMemory = new
ConfigKey<Boolean>(Boolean.class, "vmware.reserve.mem", "Advanced", "false",
- "Specify whether or not to reserve memory when deploying an
instance.", true,
- ConfigKey.Scope.Cluster, null);
+ "Specify whether or not to reserve memory when deploying an
instance.", true, ConfigKey.Scope.Cluster, null);
protected ConfigKey<Boolean> VmwareEnableNestedVirtualization = new
ConfigKey<Boolean>(Boolean.class, "vmware.nested.virtualization", "Advanced",
"false",
"When set to true this will enable nested virtualization when this
is supported by the hypervisor", true, ConfigKey.Scope.Global, null);
protected ConfigKey<Boolean> VmwareEnableNestedVirtualizationPerVM = new
ConfigKey<Boolean>(Boolean.class, "vmware.nested.virtualization.perVM",
"Advanced", "false",
"When set to true this will enable nested virtualization per vm",
true, ConfigKey.Scope.Global, null);
- @Override
- public HypervisorType getHypervisorType() {
+ @Override public HypervisorType getHypervisorType() {
return HypervisorType.VMware;
}
- @Override
- public VirtualMachineTO implement(VirtualMachineProfile vm) {
- VirtualMachineTO to = toVirtualMachineTO(vm);
- to.setBootloader(BootloaderType.HVM);
-
- Map<String, String> details = to.getDetails();
- if (details == null)
- details = new HashMap<String, String>();
-
- Type vmType = vm.getType();
- boolean userVm = !(vmType.equals(VirtualMachine.Type.DomainRouter) ||
vmType.equals(VirtualMachine.Type.ConsoleProxy)
- || vmType.equals(VirtualMachine.Type.SecondaryStorageVm));
-
- String nicDeviceType = details.get(VmDetailConstants.NIC_ADAPTER);
- if (!userVm) {
-
- if (nicDeviceType == null) {
- details.put(VmDetailConstants.NIC_ADAPTER,
_vmwareMgr.getSystemVMDefaultNicAdapterType());
- } else {
- try {
- VirtualEthernetCardType.valueOf(nicDeviceType);
- } catch (Exception e) {
- s_logger.warn("Invalid NIC device type " + nicDeviceType +
" is specified in VM details, switch to default E1000");
- details.put(VmDetailConstants.NIC_ADAPTER,
VirtualEthernetCardType.E1000.toString());
- }
- }
- } else {
- // for user-VM, use E1000 as default
- if (nicDeviceType == null) {
- details.put(VmDetailConstants.NIC_ADAPTER,
VirtualEthernetCardType.E1000.toString());
- } else {
- try {
- VirtualEthernetCardType.valueOf(nicDeviceType);
- } catch (Exception e) {
- s_logger.warn("Invalid NIC device type " + nicDeviceType +
" is specified in VM details, switch to default E1000");
- details.put(VmDetailConstants.NIC_ADAPTER,
VirtualEthernetCardType.E1000.toString());
- }
- }
- }
-
- details.put(VmDetailConstants.BOOT_MODE, to.getBootMode());
- String diskDeviceType =
details.get(VmDetailConstants.ROOT_DISK_CONTROLLER);
- if (userVm) {
- if (diskDeviceType == null) {
- details.put(VmDetailConstants.ROOT_DISK_CONTROLLER,
_vmwareMgr.getRootDiskController());
- }
- }
- String diskController =
details.get(VmDetailConstants.DATA_DISK_CONTROLLER);
- if (userVm) {
- if (diskController == null) {
- details.put(VmDetailConstants.DATA_DISK_CONTROLLER,
DiskControllerType.lsilogic.toString());
- }
- }
-
- if (vm.getType() == VirtualMachine.Type.NetScalerVm) {
- details.put(VmDetailConstants.ROOT_DISK_CONTROLLER, "scsi");
- }
-
- List<NicProfile> nicProfiles = vm.getNics();
-
- for (NicProfile nicProfile : nicProfiles) {
- if (nicProfile.getTrafficType() == TrafficType.Guest) {
- if
(_networkMgr.isProviderSupportServiceInNetwork(nicProfile.getNetworkId(),
Service.Firewall, Provider.CiscoVnmc)) {
- details.put("ConfigureVServiceInNexus",
Boolean.TRUE.toString());
- }
- break;
- }
- }
-
- long clusterId = getClusterId(vm.getId());
- details.put(VmwareReserveCpu.key(),
VmwareReserveCpu.valueIn(clusterId).toString());
- details.put(VmwareReserveMemory.key(),
VmwareReserveMemory.valueIn(clusterId).toString());
- to.setDetails(details);
-
- if (vmType.equals(VirtualMachine.Type.DomainRouter)) {
-
- NicProfile publicNicProfile = null;
- for (NicProfile nicProfile : nicProfiles) {
- if (nicProfile.getTrafficType() == TrafficType.Public) {
- publicNicProfile = nicProfile;
- break;
- }
- }
-
- if (publicNicProfile != null) {
- NicTO[] nics = to.getNics();
-
- // reserve extra NICs
- NicTO[] expandedNics = new NicTO[nics.length +
_vmwareMgr.getRouterExtraPublicNics()];
- int i = 0;
- int deviceId = -1;
- for (i = 0; i < nics.length; i++) {
- expandedNics[i] = nics[i];
- if (nics[i].getDeviceId() > deviceId)
- deviceId = nics[i].getDeviceId();
- }
- deviceId++;
-
- long networkId = publicNicProfile.getNetworkId();
- NetworkVO network = _networkDao.findById(networkId);
-
- for (; i < nics.length +
_vmwareMgr.getRouterExtraPublicNics(); i++) {
- NicTO nicTo = new NicTO();
-
- nicTo.setDeviceId(deviceId++);
-
nicTo.setBroadcastType(publicNicProfile.getBroadcastType());
- nicTo.setType(publicNicProfile.getTrafficType());
- nicTo.setIp("0.0.0.0");
- nicTo.setNetmask("255.255.255.255");
-
- try {
- String mac =
_networkMgr.getNextAvailableMacAddressInNetwork(networkId);
- nicTo.setMac(mac);
- } catch (InsufficientAddressCapacityException e) {
- throw new CloudRuntimeException("unable to allocate
mac address on network: " + networkId);
- }
- nicTo.setDns1(publicNicProfile.getIPv4Dns1());
- nicTo.setDns2(publicNicProfile.getIPv4Dns2());
- if (publicNicProfile.getIPv4Gateway() != null) {
- nicTo.setGateway(publicNicProfile.getIPv4Gateway());
- } else {
- nicTo.setGateway(network.getGateway());
- }
- nicTo.setDefaultNic(false);
- nicTo.setBroadcastUri(publicNicProfile.getBroadCastUri());
- nicTo.setIsolationuri(publicNicProfile.getIsolationUri());
-
- Integer networkRate =
_networkMgr.getNetworkRate(network.getId(), null);
- nicTo.setNetworkRateMbps(networkRate);
-
- expandedNics[i] = nicTo;
- }
-
- to.setNics(expandedNics);
-
- VirtualMachine router = vm.getVirtualMachine();
- DomainRouterVO routerVO =
_domainRouterDao.findById(router.getId());
- if (routerVO != null && routerVO.getIsRedundantRouter()) {
- Long peerRouterId =
_nicDao.getPeerRouterId(publicNicProfile.getMacAddress(), router.getId());
- DomainRouterVO peerRouterVO = null;
- if (peerRouterId != null) {
- peerRouterVO = _domainRouterDao.findById(peerRouterId);
- if (peerRouterVO != null) {
- details.put("PeerRouterInstanceName",
peerRouterVO.getInstanceName());
- }
- }
- }
- }
-
- StringBuffer sbMacSequence = new StringBuffer();
- for (NicTO nicTo : sortNicsByDeviceId(to.getNics())) {
- sbMacSequence.append(nicTo.getMac()).append("|");
- }
- if (!sbMacSequence.toString().isEmpty()) {
- sbMacSequence.deleteCharAt(sbMacSequence.length() - 1);
- String bootArgs = to.getBootArgs();
- to.setBootArgs(bootArgs + " nic_macs=" +
sbMacSequence.toString());
- }
-
- }
-
- // Don't do this if the virtual machine is one of the special types
- // Should only be done on user machines
- if (userVm) {
- configureNestedVirtualization(details, to);
- }
- // Determine the VM's OS description
- GuestOSVO guestOS =
_guestOsDao.findByIdIncludingRemoved(vm.getVirtualMachine().getGuestOSId());
- to.setOs(guestOS.getDisplayName());
- to.setHostName(vm.getHostName());
- HostVO host = _hostDao.findById(vm.getVirtualMachine().getHostId());
- GuestOSHypervisorVO guestOsMapping = null;
- if (host != null) {
- guestOsMapping =
_guestOsHypervisorDao.findByOsIdAndHypervisor(guestOS.getId(),
getHypervisorType().toString(), host.getHypervisorVersion());
- }
- if (guestOsMapping == null || host == null) {
- to.setPlatformEmulator(null);
- } else {
- to.setPlatformEmulator(guestOsMapping.getGuestOsName());
- }
-
- List<OVFPropertyTO> ovfProperties = new ArrayList<>();
- for (String detailKey : details.keySet()) {
- if (detailKey.startsWith(ApiConstants.OVF_PROPERTIES)) {
- String ovfPropKey =
detailKey.replace(ApiConstants.OVF_PROPERTIES + "-", "");
- TemplateOVFPropertyVO templateOVFPropertyVO =
templateOVFPropertiesDao.findByTemplateAndKey(vm.getTemplateId(), ovfPropKey);
- if (templateOVFPropertyVO == null) {
- s_logger.warn(String.format("OVF property %s not found on
template, discarding", ovfPropKey));
- continue;
- }
- String ovfValue = details.get(detailKey);
- boolean isPassword = templateOVFPropertyVO.isPassword();
- OVFPropertyTO propertyTO = new OVFPropertyTO(ovfPropKey,
ovfValue, isPassword);
- ovfProperties.add(propertyTO);
- }
- }
-
- if (CollectionUtils.isNotEmpty(ovfProperties)) {
- removeOvfPropertiesFromDetails(ovfProperties, details);
- String templateInstallPath = null;
- List<DiskTO> rootDiskList = vm.getDisks().stream().filter(x ->
x.getType() == Volume.Type.ROOT).collect(Collectors.toList());
- if (rootDiskList.size() != 1) {
- throw new CloudRuntimeException("Did not find only one root
disk for VM " + vm.getHostName());
- }
-
- DiskTO rootDiskTO = rootDiskList.get(0);
- DataStoreTO dataStore = rootDiskTO.getData().getDataStore();
- StoragePoolVO storagePoolVO =
_storagePoolDao.findByUuid(dataStore.getUuid());
- long dataCenterId = storagePoolVO.getDataCenterId();
- List<StoragePoolVO> pools =
_storagePoolDao.listByDataCenterId(dataCenterId);
- for (StoragePoolVO pool : pools) {
- VMTemplateStoragePoolVO ref =
templateStoragePoolDao.findByPoolTemplate(pool.getId(), vm.getTemplateId());
- if (ref != null && ref.getDownloadState() ==
VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
- templateInstallPath = ref.getInstallPath();
- break;
- }
- }
+ @Override public VirtualMachineTO implement(VirtualMachineProfile vm) {
+ vmwareVmImplementer = ComponentContext.inject(new
VmwareVmImplementer(this));
Review comment:
trying to clean it up enough to deal with the cyclic dependencies.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]