Skip to content

Commit a542b6f

Browse files
author
Mike Tutkowski
committed
CLOUDSTACK-6170 (VMware root-disk support for managed storage)
1 parent 81adee3 commit a542b6f

1 file changed

Lines changed: 0 additions & 146 deletions

File tree

‎plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java‎

Lines changed: 0 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
import com.vmware.vim25.VirtualMachineRuntimeInfo;
9191
import com.vmware.vim25.VmwareDistributedVirtualSwitchVlanIdSpec;
9292

93-
import org.apache.cloudstack.storage.command.DeleteCommand;
9493
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
9594
import org.apache.cloudstack.storage.to.TemplateObjectTO;
9695
import org.apache.cloudstack.storage.to.VolumeObjectTO;
@@ -3823,151 +3822,6 @@ protected Answer execute(UnregisterNicCommand cmd) {
38233822
}
38243823
}
38253824

3826-
public Answer execute(DeleteCommand cmd) {
3827-
if (s_logger.isInfoEnabled()) {
3828-
s_logger.info("Executing resource DeleteCommand: " + _gson.toJson(cmd));
3829-
}
3830-
3831-
/*
3832-
* DestroyCommand content exafmple
3833-
*
3834-
* {"volume": {"id":5,"name":"Volume1", "mountPoint":"/export/home/kelven/vmware-test/primary",
3835-
* "path":"6bb8762f-c34c-453c-8e03-26cc246ceec4", "size":0,"type":"DATADISK","resourceType":
3836-
* "STORAGE_POOL","storagePoolType":"NetworkFilesystem", "poolId":0,"deviceId":0 } }
3837-
*
3838-
* {"volume": {"id":1, "name":"i-2-1-KY-ROOT", "mountPoint":"/export/home/kelven/vmware-test/primary",
3839-
* "path":"i-2-1-KY-ROOT","size":0,"type":"ROOT", "resourceType":"STORAGE_POOL", "storagePoolType":"NetworkFilesystem",
3840-
* "poolId":0,"deviceId":0 } }
3841-
*/
3842-
3843-
try {
3844-
VmwareContext context = getServiceContext();
3845-
VmwareHypervisorHost hyperHost = getHyperHost(context);
3846-
VolumeObjectTO vol = (VolumeObjectTO)cmd.getData();
3847-
DataStoreTO store = vol.getDataStore();
3848-
3849-
ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, store.getUuid());
3850-
if (morDs == null) {
3851-
String msg = "Unable to find datastore based on volume mount point " + store.getUrl();
3852-
s_logger.error(msg);
3853-
throw new Exception(msg);
3854-
}
3855-
3856-
DatastoreMO dsMo = new DatastoreMO(context, morDs);
3857-
3858-
ManagedObjectReference morDc = hyperHost.getHyperHostDatacenter();
3859-
ManagedObjectReference morCluster = hyperHost.getHyperHostCluster();
3860-
ClusterMO clusterMo = new ClusterMO(context, morCluster);
3861-
3862-
if (vol.getVolumeType() == Volume.Type.ROOT) {
3863-
String vmName = vol.getVmName();
3864-
if (vmName != null) {
3865-
VirtualMachineMO vmMo = clusterMo.findVmOnHyperHost(vmName);
3866-
if (vmMo != null) {
3867-
if (s_logger.isInfoEnabled()) {
3868-
s_logger.info("Destroy root volume and VM itself. vmName " + vmName);
3869-
}
3870-
3871-
HostMO hostMo = vmMo.getRunningHost();
3872-
List<NetworkDetails> networks = vmMo.getNetworksWithDetails();
3873-
3874-
// tear down all devices first before we destroy the VM to avoid accidently delete disk backing files
3875-
if (getVmPowerState(vmMo) != PowerState.PowerOff)
3876-
vmMo.safePowerOff(_shutdownWaitMs);
3877-
vmMo.tearDownDevices(new Class<?>[] { /* VirtualDisk.class, */VirtualEthernetCard.class});
3878-
vmMo.destroy();
3879-
3880-
for (NetworkDetails netDetails : networks) {
3881-
if (netDetails.getGCTag() != null && netDetails.getGCTag().equalsIgnoreCase("true")) {
3882-
if (netDetails.getVMMorsOnNetwork() == null || netDetails.getVMMorsOnNetwork().length == 1) {
3883-
cleanupNetwork(hostMo, netDetails);
3884-
}
3885-
}
3886-
}
3887-
}
3888-
3889-
if (s_logger.isInfoEnabled())
3890-
s_logger.info("Destroy volume by original name: " + vol.getPath() + ".vmdk");
3891-
dsMo.deleteFile(vol.getPath() + ".vmdk", morDc, true);
3892-
3893-
// root volume may be created via linked-clone, delete the delta disk as well
3894-
if (_fullCloneFlag) {
3895-
if (s_logger.isInfoEnabled()) {
3896-
s_logger.info("Destroy volume by derived name: " + vol.getPath() + "-flat.vmdk");
3897-
}
3898-
dsMo.deleteFile(vol.getPath() + "-flat.vmdk", morDc, true);
3899-
} else {
3900-
if (s_logger.isInfoEnabled()) {
3901-
s_logger.info("Destroy volume by derived name: " + vol.getPath() + "-delta.vmdk");
3902-
}
3903-
dsMo.deleteFile(vol.getPath() + "-delta.vmdk", morDc, true);
3904-
}
3905-
return new Answer(cmd, true, "Success");
3906-
}
3907-
3908-
if (s_logger.isInfoEnabled()) {
3909-
s_logger.info("Destroy root volume directly from datastore");
3910-
}
3911-
} else {
3912-
// evitTemplate will be converted into DestroyCommand, test if we are running in this case
3913-
VirtualMachineMO vmMo = clusterMo.findVmOnHyperHost(vol.getPath());
3914-
if (vmMo != null) {
3915-
if (s_logger.isInfoEnabled())
3916-
s_logger.info("Destroy template volume " + vol.getPath());
3917-
3918-
vmMo.destroy();
3919-
return new Answer(cmd, true, "Success");
3920-
}
3921-
}
3922-
3923-
String chainInfo = vol.getChainInfo();
3924-
if (chainInfo != null && !chainInfo.isEmpty()) {
3925-
s_logger.info("Destroy volume by chain info: " + chainInfo);
3926-
String[] diskChain = _gson.fromJson(chainInfo, String[].class);
3927-
3928-
if (diskChain != null && diskChain.length > 0) {
3929-
for (String backingName : diskChain) {
3930-
if (s_logger.isInfoEnabled()) {
3931-
s_logger.info("Delete volume backing file: " + backingName);
3932-
}
3933-
dsMo.deleteFile(backingName, morDc, true);
3934-
}
3935-
} else {
3936-
if (s_logger.isInfoEnabled()) {
3937-
s_logger.info("Empty disk chain info, fall back to try to delete by original backing file name");
3938-
}
3939-
dsMo.deleteFile(vol.getPath() + ".vmdk", morDc, true);
3940-
3941-
if (s_logger.isInfoEnabled()) {
3942-
s_logger.info("Destroy volume by derived name: " + vol.getPath() + "-flat.vmdk");
3943-
}
3944-
dsMo.deleteFile(vol.getPath() + "-flat.vmdk", morDc, true);
3945-
}
3946-
} else {
3947-
if (s_logger.isInfoEnabled()) {
3948-
s_logger.info("Destroy volume by original name: " + vol.getPath() + ".vmdk");
3949-
}
3950-
dsMo.deleteFile(vol.getPath() + ".vmdk", morDc, true);
3951-
3952-
if (s_logger.isInfoEnabled()) {
3953-
s_logger.info("Destroy volume by derived name: " + vol.getPath() + "-flat.vmdk");
3954-
}
3955-
dsMo.deleteFile(vol.getPath() + "-flat.vmdk", morDc, true);
3956-
}
3957-
3958-
return new Answer(cmd, true, "Success");
3959-
} catch (Throwable e) {
3960-
if (e instanceof RemoteException) {
3961-
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
3962-
invalidateServiceContext();
3963-
}
3964-
3965-
String msg = "DestroyCommand failed due to " + VmwareHelper.getExceptionMessage(e);
3966-
s_logger.error(msg, e);
3967-
return new Answer(cmd, false, msg);
3968-
}
3969-
}
3970-
39713825
public void cleanupNetwork(HostMO hostMo, NetworkDetails netDetails) {
39723826
// we will no longer cleanup VLAN networks in order to support native VMware HA
39733827
/*

0 commit comments

Comments
 (0)