use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.
the class Ovm3StorageProcessor method createVolumeFromSnapshot.
/**
* SnapshotObjectTO secondary to VolumeObjectTO primary in xenserver,
*/
@Override
public Answer createVolumeFromSnapshot(CopyCommand cmd) {
LOGGER.debug("execute createVolumeFromSnapshot: " + cmd.getClass());
try {
DataTO srcData = cmd.getSrcTO();
DataStoreTO srcStore = srcData.getDataStore();
NfsTO srcImageStore = (NfsTO) srcStore;
// source, should contain snap dir/filename
SnapshotObjectTO srcSnap = (SnapshotObjectTO) srcData;
String secPoolUuid = pool.setupSecondaryStorage(srcImageStore.getUrl());
String srcFile = config.getAgentSecStoragePath() + "/" + secPoolUuid + "/" + srcSnap.getPath();
// dest
DataTO destData = cmd.getDestTO();
VolumeObjectTO destVol = (VolumeObjectTO) destData;
String primaryPoolUuid = destData.getDataStore().getUuid();
String destFile = getVirtualDiskPath(destVol.getUuid(), ovmObject.deDash(primaryPoolUuid));
Linux host = new Linux(c);
host.copyFile(srcFile, destFile);
VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setUuid(destVol.getUuid());
// newVol.setPath(destFile);
newVol.setPath(destVol.getUuid());
newVol.setFormat(ImageFormat.RAW);
return new CopyCmdAnswer(newVol);
/* we assume the cache for templates is local */
} catch (Ovm3ResourceException e) {
LOGGER.debug("Failed to createVolumeFromSnapshot: ", e);
return new CopyCmdAnswer(e.toString());
}
}
use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.
the class Ovm3StorageProcessor method deleteVolume.
@Override
public Answer deleteVolume(DeleteCommand cmd) {
LOGGER.debug("execute deleteVolume: " + cmd.getClass());
DataTO data = cmd.getData();
VolumeObjectTO volume = (VolumeObjectTO) data;
try {
String poolUuid = data.getDataStore().getUuid();
String uuid = volume.getUuid();
String path = getVirtualDiskPath(uuid, poolUuid);
StoragePlugin sp = new StoragePlugin(c);
sp.storagePluginDestroy(poolUuid, path);
LOGGER.debug("Volume deletion success: " + path);
} catch (Ovm3ResourceException e) {
LOGGER.info("Volume deletion failed: " + e.toString(), e);
return new CreateObjectAnswer(e.toString());
}
return new Answer(cmd);
}
use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.
the class NotAValidCommand method testRevertToVMSnapshotCommand.
@Test
public void testRevertToVMSnapshotCommand() {
final Connection conn = Mockito.mock(Connection.class);
final VMSnapshotTO snapshotTO = Mockito.mock(VMSnapshotTO.class);
final List<VolumeObjectTO> volumeTOs = new ArrayList<VolumeObjectTO>();
final RevertToVMSnapshotCommand vmSnapshot = new RevertToVMSnapshotCommand("Test", "uuid", snapshotTO, volumeTOs, "Debian");
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(citrixResourceBase.getConnection()).thenReturn(conn);
final Answer answer = wrapper.execute(vmSnapshot, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
assertFalse(answer.getResult());
}
use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.
the class NotAValidCommand method testDeleteVMSnapshotCommand.
@Test
public void testDeleteVMSnapshotCommand() {
final Connection conn = Mockito.mock(Connection.class);
final VMSnapshotTO snapshotTO = Mockito.mock(VMSnapshotTO.class);
final List<VolumeObjectTO> volumeTOs = new ArrayList<VolumeObjectTO>();
final DeleteVMSnapshotCommand vmSnapshot = new DeleteVMSnapshotCommand("Test", snapshotTO, volumeTOs, "Debian");
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(citrixResourceBase.getConnection()).thenReturn(conn);
final Answer answer = wrapper.execute(vmSnapshot, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
assertTrue(answer.getResult());
}
use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.
the class XenServerStorageProcessor method copyVolumeFromPrimaryToSecondary.
@Override
public Answer copyVolumeFromPrimaryToSecondary(final CopyCommand cmd) {
final Connection conn = hypervisorResource.getConnection();
final VolumeObjectTO srcVolume = (VolumeObjectTO) cmd.getSrcTO();
final VolumeObjectTO destVolume = (VolumeObjectTO) cmd.getDestTO();
final int wait = cmd.getWait();
final DataStoreTO destStore = destVolume.getDataStore();
if (destStore instanceof NfsTO) {
SR secondaryStorage = null;
try {
final NfsTO nfsStore = (NfsTO) destStore;
final URI uri = new URI(nfsStore.getUrl());
// Create the volume folder
if (!hypervisorResource.createSecondaryStorageFolder(conn, uri.getHost() + ":" + uri.getPath(), destVolume.getPath())) {
throw new InternalErrorException("Failed to create the volume folder.");
}
// Create a SR for the volume UUID folder
secondaryStorage = hypervisorResource.createNfsSRbyURI(conn, new URI(nfsStore.getUrl() + nfsStore.getPathSeparator() + destVolume.getPath()), false);
// Look up the volume on the source primary storage pool
final VDI srcVdi = getVDIbyUuid(conn, srcVolume.getPath());
// Copy the volume to secondary storage
final VDI destVdi = hypervisorResource.cloudVDIcopy(conn, srcVdi, secondaryStorage, wait);
final String destVolumeUUID = destVdi.getUuid(conn);
final VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setPath(destVolume.getPath() + nfsStore.getPathSeparator() + destVolumeUUID + ".vhd");
newVol.setSize(srcVolume.getSize());
return new CopyCmdAnswer(newVol);
} catch (final Exception e) {
s_logger.debug("Failed to copy volume to secondary: " + e.toString());
return new CopyCmdAnswer("Failed to copy volume to secondary: " + e.toString());
} finally {
hypervisorResource.removeSR(conn, secondaryStorage);
}
}
return new CopyCmdAnswer("unsupported protocol");
}
Aggregations