mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-4139: [VMWARE][ZWPS] Failed to resize the volumes which are created from snapshot
Description:
Support offline volume resize on ESX by creating a worker VM
to attach the unattached volume to and then resize it.
This commit is contained in:
parent
4161303060
commit
c850f0a0e3
|
|
@ -610,11 +610,39 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
String path = cmd.getPath();
|
||||
String vmName = cmd.getInstanceName();
|
||||
long newSize = cmd.getNewSize()/1024;
|
||||
boolean useWorkerVm = false;
|
||||
|
||||
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
|
||||
String poolId = cmd.getPoolUuid();
|
||||
VirtualMachineMO vmMo = null;
|
||||
DatastoreMO dsMo = null;
|
||||
ManagedObjectReference morDS = null;
|
||||
String vmdkDataStorePath = null;
|
||||
|
||||
|
||||
try {
|
||||
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
|
||||
if (vmName.equalsIgnoreCase("none")) {
|
||||
// we need to spawn a worker VM to attach the volume to and
|
||||
// resize the volume.
|
||||
useWorkerVm = true;
|
||||
vmName = this.getWorkerName(getServiceContext(), cmd, 0);
|
||||
|
||||
morDS = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, poolId);
|
||||
dsMo = new DatastoreMO(hyperHost.getContext(), morDS);
|
||||
s_logger.info("Create worker VM " + vmName);
|
||||
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, vmName);
|
||||
if (vmMo == null) {
|
||||
throw new Exception("Unable to create a worker VM for volume resize");
|
||||
}
|
||||
|
||||
synchronized (this) {
|
||||
vmdkDataStorePath = VmwareStorageLayoutHelper.getLegacyDatastorePathFromVmdkFileName(dsMo, path + ".vmdk");
|
||||
vmMo.attachDisk(new String[] { vmdkDataStorePath }, morDS);
|
||||
}
|
||||
}
|
||||
|
||||
// find VM through datacenter (VM is not at the target host yet)
|
||||
VirtualMachineMO vmMo = hyperHost.findVmOnPeerHyperHost(vmName);
|
||||
vmMo = hyperHost.findVmOnPeerHyperHost(vmName);
|
||||
if (vmMo == null) {
|
||||
String msg = "VM " + vmName + " does not exist in VMware datacenter";
|
||||
s_logger.error(msg);
|
||||
|
|
@ -642,9 +670,16 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
|
||||
vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
|
||||
if (!vmMo.configureVm(vmConfigSpec)) {
|
||||
if (useWorkerVm == true) {
|
||||
vmMo.detachDisk(vmdkDataStorePath, false);
|
||||
vmMo.destroy();
|
||||
}
|
||||
throw new Exception("Failed to configure VM to resize disk. vmName: " + vmName);
|
||||
}
|
||||
|
||||
if (useWorkerVm == true) {
|
||||
vmMo.detachDisk(vmdkDataStorePath, false);
|
||||
vmMo.destroy();
|
||||
}
|
||||
return new ResizeVolumeAnswer(cmd, true, "success", newSize*1024);
|
||||
} catch (Exception e) {
|
||||
s_logger.error("Unable to resize volume",e);
|
||||
|
|
|
|||
|
|
@ -1096,12 +1096,12 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
|
|||
"Can't resize a volume that has never been attached, not sure which hypervisor type. Recreate volume to resize.");
|
||||
}
|
||||
|
||||
/* Only works for KVM/Xen for now */
|
||||
/* Only works for KVM/Xen/VMware for now */
|
||||
if (_volsDao.getHypervisorType(volume.getId()) != HypervisorType.KVM
|
||||
&& _volsDao.getHypervisorType(volume.getId()) != HypervisorType.XenServer
|
||||
&& _volsDao.getHypervisorType(volume.getId()) != HypervisorType.VMware) {
|
||||
throw new InvalidParameterValueException(
|
||||
"Cloudstack currently only supports volumes marked as KVM or XenServer hypervisor for resize");
|
||||
"Cloudstack currently only supports volumes marked as KVM or XenServer or ESX hypervisor for resize");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue