use of com.cloud.storage.to.VolumeObjectTO in project cosmic by MissionCriticalCloud.
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<>();
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 com.cloud.storage.to.VolumeObjectTO in project cosmic by MissionCriticalCloud.
the class KvmStoragePoolManager method disconnectPhysicalDisksViaVmSpec.
public boolean disconnectPhysicalDisksViaVmSpec(final VirtualMachineTO vmSpec) {
if (vmSpec == null) {
/*
* CloudStack often tries to stop VMs that shouldn't be running, to ensure a known state, for example if we lose
* communication with the agent and the VM is brought up elsewhere. We may not know about these yet. This might
* mean that we can't use the vmspec map, because when we restart the agent we lose all of the info about running
* VMs.
*/
s_logger.debug("disconnectPhysicalDiskViaVmSpec: Attempted to stop a VM that is not yet in our hash map");
return true;
}
boolean result = true;
final String vmName = vmSpec.getName();
final List<DiskTO> disks = Arrays.asList(vmSpec.getDisks());
for (final DiskTO disk : disks) {
if (disk.getType() != Volume.Type.ISO) {
s_logger.debug("Disconnecting disk " + disk.getPath());
final VolumeObjectTO vol = (VolumeObjectTO) disk.getData();
final PrimaryDataStoreTO store = (PrimaryDataStoreTO) vol.getDataStore();
final KvmStoragePool pool = getStoragePool(store.getPoolType(), store.getUuid());
if (pool == null) {
s_logger.error("Pool " + store.getUuid() + " of type " + store.getPoolType() + " was not found, skipping disconnect logic");
continue;
}
final StorageAdaptor adaptor = getStorageAdaptor(pool.getType());
// if a disk fails to disconnect, still try to disconnect remaining
final boolean subResult = adaptor.disconnectPhysicalDisk(vol.getPath(), pool);
if (!subResult) {
s_logger.error("Failed to disconnect disks via vm spec for vm: " + vmName + " volume:" + vol.toString());
result = false;
}
}
}
return result;
}
use of com.cloud.storage.to.VolumeObjectTO in project cosmic by MissionCriticalCloud.
the class KvmStorageProcessor method createVolume.
@Override
public Answer createVolume(final CreateObjectCommand cmd) {
final VolumeObjectTO volume = (VolumeObjectTO) cmd.getData();
final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) volume.getDataStore();
KvmStoragePool primaryPool = null;
KvmPhysicalDisk vol = null;
final long disksize;
try {
primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid());
disksize = volume.getSize();
final PhysicalDiskFormat format;
if (volume.getFormat() == null) {
format = primaryPool.getDefaultFormat();
} else {
format = PhysicalDiskFormat.valueOf(volume.getFormat().toString().toUpperCase());
}
vol = primaryPool.createPhysicalDisk(volume.getUuid(), format, volume.getProvisioningType(), disksize);
final VolumeObjectTO newVol = new VolumeObjectTO();
if (vol != null) {
newVol.setPath(vol.getName());
}
newVol.setSize(volume.getSize());
newVol.setFormat(ImageFormat.valueOf(format.toString().toUpperCase()));
return new CreateObjectAnswer(newVol);
} catch (final Exception e) {
logger.debug("Failed to create volume: ", e);
return new CreateObjectAnswer(e.toString());
}
}
use of com.cloud.storage.to.VolumeObjectTO in project cosmic by MissionCriticalCloud.
the class KvmStorageProcessor method dettachVolume.
@Override
public Answer dettachVolume(final DettachCommand cmd) {
final DiskTO disk = cmd.getDisk();
final VolumeObjectTO vol = (VolumeObjectTO) disk.getData();
final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) vol.getDataStore();
final String vmName = cmd.getVmName();
final String serial = resource.diskUuidToSerial(vol.getUuid());
try {
final Connect conn = LibvirtConnection.getConnectionByVmName(vmName);
final KvmPhysicalDisk phyDisk = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), vol.getPath());
attachOrDetachDisk(conn, false, vmName, phyDisk, disk.getDiskSeq().intValue(), serial);
storagePoolMgr.disconnectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), vol.getPath());
return new DettachAnswer(disk);
} catch (final LibvirtException e) {
logger.debug("Failed to attach volume: " + vol.getPath() + ", due to ", e);
return new DettachAnswer(e.toString());
} catch (final InternalErrorException e) {
logger.debug("Failed to attach volume: " + vol.getPath() + ", due to ", e);
return new DettachAnswer(e.toString());
}
}
use of com.cloud.storage.to.VolumeObjectTO in project cosmic by MissionCriticalCloud.
the class KvmStorageProcessor method cloneVolumeFromBaseTemplate.
@Override
public Answer cloneVolumeFromBaseTemplate(final CopyCommand cmd) {
final DataTO srcData = cmd.getSrcTO();
final DataTO destData = cmd.getDestTO();
final TemplateObjectTO template = (TemplateObjectTO) srcData;
final DataStoreTO imageStore = template.getDataStore();
final VolumeObjectTO volume = (VolumeObjectTO) destData;
final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) volume.getDataStore();
KvmPhysicalDisk baseVolume;
KvmStoragePool primaryPool;
KvmPhysicalDisk vol;
try {
primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid());
String templatePath = template.getPath();
if (primaryPool.getType() == StoragePoolType.CLVM) {
templatePath = imageStore.getUrl() + File.separator + templatePath;
vol = templateToPrimaryDownload(templatePath, primaryPool, volume.getUuid(), volume.getSize(), cmd.getWaitInMillSeconds());
} else {
if (templatePath.contains("/mnt")) {
// upgrade issue, if the path contains path, need to extract the volume uuid from path
templatePath = templatePath.substring(templatePath.lastIndexOf(File.separator) + 1);
}
baseVolume = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), templatePath);
vol = storagePoolMgr.createDiskFromTemplate(baseVolume, volume.getUuid(), volume.getProvisioningType(), baseVolume.getPool(), volume.getSize(), cmd.getWaitInMillSeconds());
}
if (vol == null) {
return new CopyCmdAnswer(" Can't create storage volume on storage pool");
}
final VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setPath(vol.getName());
newVol.setSize(volume.getSize());
if (vol.getFormat() == PhysicalDiskFormat.RAW) {
newVol.setFormat(ImageFormat.RAW);
} else if (vol.getFormat() == PhysicalDiskFormat.QCOW2) {
newVol.setFormat(ImageFormat.QCOW2);
} else if (vol.getFormat() == PhysicalDiskFormat.DIR) {
newVol.setFormat(ImageFormat.DIR);
}
return new CopyCmdAnswer(newVol);
} catch (final CloudRuntimeException e) {
logger.debug("Failed to create volume: ", e);
return new CopyCmdAnswer(e.toString());
}
}
Aggregations