Skip to content

Commit 306c095

Browse files
Merge branch '4.20' into 4.20-fix-vmware-test-restore-vm
2 parents fc5c8be + badf3e1 commit 306c095

File tree

30 files changed

+951
-369
lines changed

30 files changed

+951
-369
lines changed

api/src/main/java/org/apache/cloudstack/api/response/UnmanagedInstanceResponse.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ public class UnmanagedInstanceResponse extends BaseResponse {
7979
@Param(description = "the operating system of the virtual machine")
8080
private String operatingSystem;
8181

82+
@SerializedName(ApiConstants.BOOT_MODE)
83+
@Param(description = "indicates the boot mode")
84+
private String bootMode;
85+
86+
@SerializedName(ApiConstants.BOOT_TYPE)
87+
@Param(description = "indicates the boot type")
88+
private String bootType;
89+
8290
@SerializedName(ApiConstants.DISK)
8391
@Param(description = "the list of disks associated with the virtual machine", responseObject = UnmanagedInstanceDiskResponse.class)
8492
private Set<UnmanagedInstanceDiskResponse> disks;
@@ -211,4 +219,20 @@ public void setNics(Set<NicResponse> nics) {
211219
public void addNic(NicResponse nic) {
212220
this.nics.add(nic);
213221
}
222+
223+
public String getBootMode() {
224+
return bootMode;
225+
}
226+
227+
public void setBootMode(String bootMode) {
228+
this.bootMode = bootMode;
229+
}
230+
231+
public String getBootType() {
232+
return bootType;
233+
}
234+
235+
public void setBootType(String bootType) {
236+
this.bootType = bootType;
237+
}
214238
}

api/src/main/java/org/apache/cloudstack/vm/UnmanagedInstanceTO.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public enum PowerState {
6161

6262
private String vncPassword;
6363

64+
private String bootType;
65+
private String bootMode;
66+
6467
public String getName() {
6568
return name;
6669
}
@@ -196,6 +199,22 @@ public String toString() {
196199
this, "name", "internalCSName", "hostName", "clusterName"));
197200
}
198201

202+
public String getBootType() {
203+
return bootType;
204+
}
205+
206+
public void setBootType(String bootType) {
207+
this.bootType = bootType;
208+
}
209+
210+
public String getBootMode() {
211+
return bootMode;
212+
}
213+
214+
public void setBootMode(String bootMode) {
215+
this.bootMode = bootMode;
216+
}
217+
199218
public static class Disk {
200219
private String diskId;
201220

engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@
6161
import org.apache.cloudstack.context.CallContext;
6262
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
6363
import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService;
64+
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver;
6465
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
66+
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider;
67+
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager;
68+
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
6569
import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
6670
import org.apache.cloudstack.framework.ca.Certificate;
6771
import org.apache.cloudstack.framework.config.ConfigKey;
@@ -411,6 +415,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
411415
VmWorkJobDao vmWorkJobDao;
412416

413417
private SingleCache<List<Long>> vmIdsInProgressCache;
418+
DataStoreProviderManager dataStoreProviderManager;
414419

415420
VmWorkJobHandlerProxy _jobHandlerProxy = new VmWorkJobHandlerProxy(this);
416421

@@ -1224,6 +1229,11 @@ public void orchestrateStart(final String vmUuid, final Map<VirtualMachineProfil
12241229
planChangedByVolume = true;
12251230
}
12261231
}
1232+
DataStoreProvider storeProvider = dataStoreProviderManager.getDataStoreProvider(pool.getStorageProviderName());
1233+
DataStoreDriver storeDriver = storeProvider.getDataStoreDriver();
1234+
if (storeDriver instanceof PrimaryDataStoreDriver) {
1235+
((PrimaryDataStoreDriver)storeDriver).detachVolumeFromAllStorageNodes(vol);
1236+
}
12271237
}
12281238
}
12291239

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

Lines changed: 71 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import javax.naming.ConfigurationException;
4444
import javax.persistence.EntityExistsException;
4545

46+
import com.cloud.hypervisor.vmware.mo.VirtualMachineMO;
4647
import com.cloud.hypervisor.vmware.util.VmwareClient;
4748
import org.apache.cloudstack.api.command.admin.zone.AddVmwareDcCmd;
4849
import org.apache.cloudstack.api.command.admin.zone.ImportVsphereStoragePoliciesCmd;
@@ -171,8 +172,11 @@
171172
import com.vmware.pbm.PbmProfile;
172173
import com.vmware.vim25.AboutInfo;
173174
import com.vmware.vim25.ManagedObjectReference;
175+
import org.apache.logging.log4j.LogManager;
176+
import org.apache.logging.log4j.Logger;
174177

175178
public class VmwareManagerImpl extends ManagerBase implements VmwareManager, VmwareStorageMount, Listener, VmwareDatacenterService, Configurable {
179+
protected static Logger static_logger = LogManager.getLogger(VmwareManagerImpl.class);
176180

177181
private static final long SECONDS_PER_MINUTE = 60;
178182
private static final int DEFAULT_PORTS_PER_DV_PORT_GROUP_VSPHERE4_x = 256;
@@ -1585,14 +1589,26 @@ public List<StoragePool> listVsphereStoragePolicyCompatibleStoragePools(ListVsph
15851589
return compatiblePools;
15861590
}
15871591

1588-
@Override
1589-
public List<UnmanagedInstanceTO> listVMsInDatacenter(ListVmwareDcVmsCmd cmd) {
1592+
private static class VcenterData {
1593+
public final String vcenter;
1594+
public final String datacenterName;
1595+
public final String username;
1596+
public final String password;
1597+
1598+
public VcenterData(String vcenter, String datacenterName, String username, String password) {
1599+
this.vcenter = vcenter;
1600+
this.datacenterName = datacenterName;
1601+
this.username = username;
1602+
this.password = password;
1603+
}
1604+
}
1605+
1606+
private VcenterData getVcenterData(ListVmwareDcVmsCmd cmd) {
15901607
String vcenter = cmd.getVcenter();
15911608
String datacenterName = cmd.getDatacenterName();
15921609
String username = cmd.getUsername();
15931610
String password = cmd.getPassword();
15941611
Long existingVcenterId = cmd.getExistingVcenterId();
1595-
String keyword = cmd.getKeyword();
15961612

15971613
if ((existingVcenterId == null && StringUtils.isBlank(vcenter)) ||
15981614
(existingVcenterId != null && StringUtils.isNotBlank(vcenter))) {
@@ -1613,34 +1629,69 @@ public List<UnmanagedInstanceTO> listVMsInDatacenter(ListVmwareDcVmsCmd cmd) {
16131629
username = vmwareDc.getUser();
16141630
password = vmwareDc.getPassword();
16151631
}
1632+
VcenterData vmwaredc = new VcenterData(vcenter, datacenterName, username, password);
1633+
return vmwaredc;
1634+
}
1635+
1636+
private static VmwareContext getVmwareContext(String vcenter, String username, String password) throws Exception {
1637+
static_logger.debug(String.format("Connecting to the VMware vCenter %s", vcenter));
1638+
String serviceUrl = String.format("https://%s/sdk/vimService", vcenter);
1639+
VmwareClient vimClient = new VmwareClient(vcenter);
1640+
vimClient.connect(serviceUrl, username, password);
1641+
return new VmwareContext(vimClient, vcenter);
1642+
}
1643+
1644+
@Override
1645+
public List<UnmanagedInstanceTO> listVMsInDatacenter(ListVmwareDcVmsCmd cmd) {
1646+
VcenterData vmwareDC = getVcenterData(cmd);
1647+
String vcenter = vmwareDC.vcenter;
1648+
String username = vmwareDC.username;
1649+
String password = vmwareDC.password;
1650+
String datacenterName = vmwareDC.datacenterName;
1651+
String keyword = cmd.getKeyword();
1652+
String esxiHostName = cmd.getHostName();
1653+
String virtualMachineName = cmd.getInstanceName();
16161654

16171655
try {
16181656
logger.debug(String.format("Connecting to the VMware datacenter %s at vCenter %s to retrieve VMs",
16191657
datacenterName, vcenter));
1620-
String serviceUrl = String.format("https://%s/sdk/vimService", vcenter);
1621-
VmwareClient vimClient = new VmwareClient(vcenter);
1622-
vimClient.connect(serviceUrl, username, password);
1623-
VmwareContext context = new VmwareContext(vimClient, vcenter);
1624-
1625-
DatacenterMO dcMo = new DatacenterMO(context, datacenterName);
1626-
ManagedObjectReference dcMor = dcMo.getMor();
1627-
if (dcMor == null) {
1628-
String msg = String.format("Unable to find VMware datacenter %s in vCenter %s",
1629-
datacenterName, vcenter);
1630-
logger.error(msg);
1631-
throw new InvalidParameterValueException(msg);
1658+
VmwareContext context = getVmwareContext(vcenter, username, password);
1659+
DatacenterMO dcMo = getDatacenterMO(context, vcenter, datacenterName);
1660+
1661+
List<UnmanagedInstanceTO> instances;
1662+
if (StringUtils.isNotBlank(esxiHostName) && StringUtils.isNotBlank(virtualMachineName)) {
1663+
ManagedObjectReference hostMor = dcMo.findHost(esxiHostName);
1664+
if (hostMor == null) {
1665+
String errorMsg = String.format("Cannot find a host with name %s on vcenter %s", esxiHostName, vcenter);
1666+
logger.error(errorMsg);
1667+
throw new CloudRuntimeException(errorMsg);
1668+
}
1669+
HostMO hostMO = new HostMO(context, hostMor);
1670+
VirtualMachineMO vmMo = hostMO.findVmOnHyperHost(virtualMachineName);
1671+
instances = Collections.singletonList(VmwareHelper.getUnmanagedInstance(hostMO, vmMo));
1672+
} else {
1673+
instances = dcMo.getAllVmsOnDatacenter(keyword);
16321674
}
1633-
List<UnmanagedInstanceTO> instances = dcMo.getAllVmsOnDatacenter();
1634-
return StringUtils.isBlank(keyword) ? instances :
1635-
instances.stream().filter(x -> x.getName().toLowerCase().contains(keyword.toLowerCase())).collect(Collectors.toList());
1675+
return instances;
16361676
} catch (Exception e) {
1637-
String errorMsg = String.format("Error retrieving stopped VMs from the VMware VC %s datacenter %s: %s",
1677+
String errorMsg = String.format("Error retrieving VMs from the VMware VC %s datacenter %s: %s",
16381678
vcenter, datacenterName, e.getMessage());
16391679
logger.error(errorMsg, e);
16401680
throw new CloudRuntimeException(errorMsg);
16411681
}
16421682
}
16431683

1684+
private static DatacenterMO getDatacenterMO(VmwareContext context, String vcenter, String datacenterName) throws Exception {
1685+
DatacenterMO dcMo = new DatacenterMO(context, datacenterName);
1686+
ManagedObjectReference dcMor = dcMo.getMor();
1687+
if (dcMor == null) {
1688+
String msg = String.format("Unable to find VMware datacenter %s in vCenter %s", datacenterName, vcenter);
1689+
static_logger.error(msg);
1690+
throw new InvalidParameterValueException(msg);
1691+
}
1692+
return dcMo;
1693+
}
1694+
16441695
@Override
16451696
public boolean hasNexusVSM(Long clusterId) {
16461697
ClusterVSMMapVO vsmMapVo = null;
@@ -1693,7 +1744,7 @@ private void startTemplateCleanJobSchedule() {
16931744
}
16941745

16951746
/**
1696-
* This task is to cleanup templates from primary storage that are otherwise not cleaned by the {@link com.cloud.storage.StorageManagerImpl.StorageGarbageCollector}.
1747+
* This task is to cleanup templates from primary storage that are otherwise not cleaned by the {code}StorageGarbageCollector{code} from {@link com.cloud.storage.StorageManagerImpl}.
16971748
* it is called at regular intervals when storage.template.cleanup.enabled == true
16981749
* It collect all templates that
16991750
* - are deleted from cloudstack

0 commit comments

Comments
 (0)