use of com.cloud.agent.api.to.VolumeTO in project cloudstack by apache.
the class VmwareStorageMotionStrategy method migrateVmWithVolumesWithinCluster.
private Answer migrateVmWithVolumesWithinCluster(VMInstanceVO vm, VirtualMachineTO to, Host srcHost, Host destHost, Map<VolumeInfo, DataStore> volumeToPool) throws AgentUnavailableException {
// Initiate migration of a virtual machine with it's volumes.
try {
List<Pair<VolumeTO, StorageFilerTO>> volumeToFilerto = new ArrayList<Pair<VolumeTO, StorageFilerTO>>();
for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
VolumeInfo volume = entry.getKey();
VolumeTO volumeTo = new VolumeTO(volume, storagePoolDao.findById(volume.getPoolId()));
StorageFilerTO filerTo = new StorageFilerTO((StoragePool) entry.getValue());
volumeToFilerto.add(new Pair<VolumeTO, StorageFilerTO>(volumeTo, filerTo));
}
MigrateWithStorageCommand command = new MigrateWithStorageCommand(to, volumeToFilerto, destHost.getGuid());
MigrateWithStorageAnswer answer = (MigrateWithStorageAnswer) agentMgr.send(srcHost.getId(), command);
if (answer == null) {
s_logger.error("Migration with storage of vm " + vm + " failed.");
throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
} else if (!answer.getResult()) {
s_logger.error("Migration with storage of vm " + vm + " failed. Details: " + answer.getDetails());
throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost + ". " + answer.getDetails());
} else {
// Update the volume details after migration.
updateVolumesAfterMigration(volumeToPool, answer.getVolumeTos());
}
return answer;
} catch (OperationTimedoutException e) {
s_logger.error("Error while migrating vm " + vm + " to host " + destHost, e);
throw new AgentUnavailableException("Operation timed out on storage motion for " + vm, destHost.getId());
}
}
use of com.cloud.agent.api.to.VolumeTO in project cloudstack by apache.
the class VmwareResource method execute.
@Override
public Answer execute(DestroyCommand cmd) {
if (s_logger.isInfoEnabled()) {
s_logger.info("Executing resource DestroyCommand to evict template from storage pool: " + _gson.toJson(cmd));
}
try {
VmwareContext context = getServiceContext(null);
VmwareHypervisorHost hyperHost = getHyperHost(context, null);
VolumeTO vol = cmd.getVolume();
VirtualMachineMO vmMo = findVmOnDatacenter(context, hyperHost, vol);
if (vmMo != null && vmMo.isTemplate()) {
if (s_logger.isInfoEnabled()) {
s_logger.info("Destroy template volume " + vol.getPath());
}
vmMo.destroy();
} else {
if (s_logger.isInfoEnabled()) {
s_logger.info("Template volume " + vol.getPath() + " is not found, no need to delete.");
}
}
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(null);
}
String msg = "DestroyCommand failed due to " + VmwareHelper.getExceptionMessage(e);
s_logger.error(msg, e);
return new Answer(cmd, false, msg);
}
}
use of com.cloud.agent.api.to.VolumeTO in project cloudstack by apache.
the class CitrixDestroyCommandWrapper method execute.
@Override
public Answer execute(final DestroyCommand command, final CitrixResourceBase citrixResourceBase) {
final Connection conn = citrixResourceBase.getConnection();
final VolumeTO vol = command.getVolume();
// Look up the VDI
final String volumeUUID = vol.getPath();
VDI vdi = null;
try {
vdi = citrixResourceBase.getVDIbyUuid(conn, volumeUUID);
} catch (final Exception e) {
return new Answer(command, true, "Success");
}
Set<VBD> vbds = null;
try {
vbds = vdi.getVBDs(conn);
} catch (final Exception e) {
final String msg = "VDI getVBDS for " + volumeUUID + " failed due to " + e.toString();
s_logger.warn(msg, e);
return new Answer(command, false, msg);
}
for (final VBD vbd : vbds) {
try {
vbd.unplug(conn);
vbd.destroy(conn);
} catch (final Exception e) {
final String msg = "VM destroy for " + volumeUUID + " failed due to " + e.toString();
s_logger.warn(msg, e);
return new Answer(command, false, msg);
}
}
try {
final Set<VDI> snapshots = vdi.getSnapshots(conn);
for (final VDI snapshot : snapshots) {
snapshot.destroy(conn);
}
vdi.destroy(conn);
} catch (final Exception e) {
final String msg = "VDI destroy for " + volumeUUID + " failed due to " + e.toString();
s_logger.warn(msg, e);
return new Answer(command, false, msg);
}
return new Answer(command, true, "Success");
}
use of com.cloud.agent.api.to.VolumeTO in project cloudstack by apache.
the class LibvirtDestroyCommandWrapper method execute.
@Override
public Answer execute(final DestroyCommand command, final LibvirtComputingResource libvirtComputingResource) {
final VolumeTO vol = command.getVolume();
try {
final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
final KVMStoragePool pool = storagePoolMgr.getStoragePool(vol.getPoolType(), vol.getPoolUuid());
pool.deletePhysicalDisk(vol.getPath(), null);
return new Answer(command, true, "Success");
} catch (final CloudRuntimeException e) {
s_logger.debug("Failed to delete volume: " + e.toString());
return new Answer(command, false, e.toString());
}
}
use of com.cloud.agent.api.to.VolumeTO in project cloudstack by apache.
the class Ovm3StorageProcessor method execute.
/* Destroy a volume (image) */
public Answer execute(DestroyCommand cmd) {
LOGGER.debug("execute: " + cmd.getClass());
VolumeTO vol = cmd.getVolume();
String vmName = cmd.getVmName();
try {
StoragePlugin store = new StoragePlugin(c);
store.storagePluginDestroy(vol.getPoolUuid(), vol.getPath());
return new Answer(cmd, true, "Success");
} catch (Ovm3ResourceException e) {
LOGGER.debug("Destroy volume " + vol.getName() + " failed for " + vmName + " ", e);
return new Answer(cmd, false, e.getMessage());
}
}
Aggregations