mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-6170 (VMware root-disk support for managed storage)
This commit is contained in:
parent
5335ae7753
commit
a7e267b416
|
|
@ -90,7 +90,6 @@ import com.vmware.vim25.VirtualMachineRelocateSpecDiskLocator;
|
|||
import com.vmware.vim25.VirtualMachineRuntimeInfo;
|
||||
import com.vmware.vim25.VmwareDistributedVirtualSwitchVlanIdSpec;
|
||||
|
||||
import org.apache.cloudstack.storage.command.DeleteCommand;
|
||||
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
|
||||
import org.apache.cloudstack.storage.to.TemplateObjectTO;
|
||||
import org.apache.cloudstack.storage.to.VolumeObjectTO;
|
||||
|
|
@ -3823,151 +3822,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
}
|
||||
}
|
||||
|
||||
public Answer execute(DeleteCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource DeleteCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
/*
|
||||
* DestroyCommand content exafmple
|
||||
*
|
||||
* {"volume": {"id":5,"name":"Volume1", "mountPoint":"/export/home/kelven/vmware-test/primary",
|
||||
* "path":"6bb8762f-c34c-453c-8e03-26cc246ceec4", "size":0,"type":"DATADISK","resourceType":
|
||||
* "STORAGE_POOL","storagePoolType":"NetworkFilesystem", "poolId":0,"deviceId":0 } }
|
||||
*
|
||||
* {"volume": {"id":1, "name":"i-2-1-KY-ROOT", "mountPoint":"/export/home/kelven/vmware-test/primary",
|
||||
* "path":"i-2-1-KY-ROOT","size":0,"type":"ROOT", "resourceType":"STORAGE_POOL", "storagePoolType":"NetworkFilesystem",
|
||||
* "poolId":0,"deviceId":0 } }
|
||||
*/
|
||||
|
||||
try {
|
||||
VmwareContext context = getServiceContext();
|
||||
VmwareHypervisorHost hyperHost = getHyperHost(context);
|
||||
VolumeObjectTO vol = (VolumeObjectTO)cmd.getData();
|
||||
DataStoreTO store = vol.getDataStore();
|
||||
|
||||
ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, store.getUuid());
|
||||
if (morDs == null) {
|
||||
String msg = "Unable to find datastore based on volume mount point " + store.getUrl();
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
DatastoreMO dsMo = new DatastoreMO(context, morDs);
|
||||
|
||||
ManagedObjectReference morDc = hyperHost.getHyperHostDatacenter();
|
||||
ManagedObjectReference morCluster = hyperHost.getHyperHostCluster();
|
||||
ClusterMO clusterMo = new ClusterMO(context, morCluster);
|
||||
|
||||
if (vol.getVolumeType() == Volume.Type.ROOT) {
|
||||
String vmName = vol.getVmName();
|
||||
if (vmName != null) {
|
||||
VirtualMachineMO vmMo = clusterMo.findVmOnHyperHost(vmName);
|
||||
if (vmMo != null) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Destroy root volume and VM itself. vmName " + vmName);
|
||||
}
|
||||
|
||||
HostMO hostMo = vmMo.getRunningHost();
|
||||
List<NetworkDetails> networks = vmMo.getNetworksWithDetails();
|
||||
|
||||
// tear down all devices first before we destroy the VM to avoid accidently delete disk backing files
|
||||
if (getVmPowerState(vmMo) != PowerState.PowerOff)
|
||||
vmMo.safePowerOff(_shutdownWaitMs);
|
||||
vmMo.tearDownDevices(new Class<?>[] { /* VirtualDisk.class, */VirtualEthernetCard.class});
|
||||
vmMo.destroy();
|
||||
|
||||
for (NetworkDetails netDetails : networks) {
|
||||
if (netDetails.getGCTag() != null && netDetails.getGCTag().equalsIgnoreCase("true")) {
|
||||
if (netDetails.getVMMorsOnNetwork() == null || netDetails.getVMMorsOnNetwork().length == 1) {
|
||||
cleanupNetwork(hostMo, netDetails);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (s_logger.isInfoEnabled())
|
||||
s_logger.info("Destroy volume by original name: " + vol.getPath() + ".vmdk");
|
||||
dsMo.deleteFile(vol.getPath() + ".vmdk", morDc, true);
|
||||
|
||||
// root volume may be created via linked-clone, delete the delta disk as well
|
||||
if (_fullCloneFlag) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Destroy volume by derived name: " + vol.getPath() + "-flat.vmdk");
|
||||
}
|
||||
dsMo.deleteFile(vol.getPath() + "-flat.vmdk", morDc, true);
|
||||
} else {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Destroy volume by derived name: " + vol.getPath() + "-delta.vmdk");
|
||||
}
|
||||
dsMo.deleteFile(vol.getPath() + "-delta.vmdk", morDc, true);
|
||||
}
|
||||
return new Answer(cmd, true, "Success");
|
||||
}
|
||||
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Destroy root volume directly from datastore");
|
||||
}
|
||||
} else {
|
||||
// evitTemplate will be converted into DestroyCommand, test if we are running in this case
|
||||
VirtualMachineMO vmMo = clusterMo.findVmOnHyperHost(vol.getPath());
|
||||
if (vmMo != null) {
|
||||
if (s_logger.isInfoEnabled())
|
||||
s_logger.info("Destroy template volume " + vol.getPath());
|
||||
|
||||
vmMo.destroy();
|
||||
return new Answer(cmd, true, "Success");
|
||||
}
|
||||
}
|
||||
|
||||
String chainInfo = vol.getChainInfo();
|
||||
if (chainInfo != null && !chainInfo.isEmpty()) {
|
||||
s_logger.info("Destroy volume by chain info: " + chainInfo);
|
||||
String[] diskChain = _gson.fromJson(chainInfo, String[].class);
|
||||
|
||||
if (diskChain != null && diskChain.length > 0) {
|
||||
for (String backingName : diskChain) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Delete volume backing file: " + backingName);
|
||||
}
|
||||
dsMo.deleteFile(backingName, morDc, true);
|
||||
}
|
||||
} else {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Empty disk chain info, fall back to try to delete by original backing file name");
|
||||
}
|
||||
dsMo.deleteFile(vol.getPath() + ".vmdk", morDc, true);
|
||||
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Destroy volume by derived name: " + vol.getPath() + "-flat.vmdk");
|
||||
}
|
||||
dsMo.deleteFile(vol.getPath() + "-flat.vmdk", morDc, true);
|
||||
}
|
||||
} else {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Destroy volume by original name: " + vol.getPath() + ".vmdk");
|
||||
}
|
||||
dsMo.deleteFile(vol.getPath() + ".vmdk", morDc, true);
|
||||
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Destroy volume by derived name: " + vol.getPath() + "-flat.vmdk");
|
||||
}
|
||||
dsMo.deleteFile(vol.getPath() + "-flat.vmdk", morDc, true);
|
||||
}
|
||||
|
||||
return new Answer(cmd, true, "Success");
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
invalidateServiceContext();
|
||||
}
|
||||
|
||||
String msg = "DestroyCommand failed due to " + VmwareHelper.getExceptionMessage(e);
|
||||
s_logger.error(msg, e);
|
||||
return new Answer(cmd, false, msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void cleanupNetwork(HostMO hostMo, NetworkDetails netDetails) {
|
||||
// we will no longer cleanup VLAN networks in order to support native VMware HA
|
||||
/*
|
||||
|
|
|
|||
Loading…
Reference in New Issue