use of com.cloud.agent.api.to.VolumeTO in project CloudStack-archive by CloudStack-extras.
the class LibvirtComputingResource method execute.
protected Answer execute(CreateCommand cmd) {
StorageFilerTO pool = cmd.getPool();
DiskProfile dskch = cmd.getDiskCharacteristics();
KVMPhysicalDisk BaseVol = null;
KVMStoragePool primaryPool = null;
KVMPhysicalDisk vol = null;
long disksize;
try {
primaryPool = _storagePoolMgr.getStoragePool(pool.getUuid());
if (cmd.getTemplateUrl() != null) {
BaseVol = primaryPool.getPhysicalDisk(cmd.getTemplateUrl());
vol = _storagePoolMgr.createDiskFromTemplate(BaseVol, UUID.randomUUID().toString(), primaryPool);
if (vol == null) {
return new Answer(cmd, false, " Can't create storage volume on storage pool");
}
disksize = vol.getSize();
} else {
disksize = dskch.getSize();
vol = primaryPool.createPhysicalDisk(UUID.randomUUID().toString(), dskch.getSize());
}
VolumeTO volume = new VolumeTO(cmd.getVolumeId(), dskch.getType(), pool.getType(), pool.getUuid(), pool.getPath(), vol.getName(), vol.getName(), disksize, null);
return new CreateAnswer(cmd, volume);
} catch (CloudRuntimeException e) {
s_logger.debug("Failed to create volume: " + e.toString());
return new CreateAnswer(cmd, e);
}
}
use of com.cloud.agent.api.to.VolumeTO in project CloudStack-archive by CloudStack-extras.
the class LibvirtComputingResource method execute.
private synchronized Answer execute(PrepareForMigrationCommand cmd) {
VirtualMachineTO vm = cmd.getVirtualMachine();
if (s_logger.isDebugEnabled()) {
s_logger.debug("Preparing host for migrating " + vm);
}
NicTO[] nics = vm.getNics();
try {
Connect conn = LibvirtConnection.getConnection();
for (NicTO nic : nics) {
String vlanId = null;
if (nic.getBroadcastType() == BroadcastDomainType.Vlan) {
URI broadcastUri = nic.getBroadcastUri();
vlanId = broadcastUri.getHost();
}
if (nic.getType() == TrafficType.Guest) {
if (nic.getBroadcastType() == BroadcastDomainType.Vlan && !vlanId.equalsIgnoreCase("untagged")) {
createVlanBr(vlanId, _pifs.first());
}
} else if (nic.getType() == TrafficType.Control) {
/* Make sure the network is still there */
createControlNetwork(conn);
} else if (nic.getType() == TrafficType.Public) {
if (nic.getBroadcastType() == BroadcastDomainType.Vlan && !vlanId.equalsIgnoreCase("untagged")) {
createVlanBr(vlanId, _pifs.second());
}
}
}
/* setup disks, e.g for iso */
VolumeTO[] volumes = vm.getDisks();
for (VolumeTO volume : volumes) {
if (volume.getType() == Volume.Type.ISO) {
getVolumePath(conn, volume);
}
}
synchronized (_vms) {
_vms.put(vm.getName(), State.Migrating);
}
return new PrepareForMigrationAnswer(cmd);
} catch (LibvirtException e) {
return new PrepareForMigrationAnswer(cmd, e.toString());
} catch (InternalErrorException e) {
return new PrepareForMigrationAnswer(cmd, e.toString());
} catch (URISyntaxException e) {
return new PrepareForMigrationAnswer(cmd, e.toString());
}
}
use of com.cloud.agent.api.to.VolumeTO in project CloudStack-archive by CloudStack-extras.
the class LibvirtComputingResource method execute.
public Answer execute(DestroyCommand cmd) {
VolumeTO vol = cmd.getVolume();
try {
KVMStoragePool pool = _storagePoolMgr.getStoragePool(vol.getPoolUuid());
pool.deletePhysicalDisk(vol.getPath());
return new Answer(cmd, true, "Success");
} catch (CloudRuntimeException e) {
s_logger.debug("Failed to delete volume: " + e.toString());
return new Answer(cmd, false, e.toString());
}
}
use of com.cloud.agent.api.to.VolumeTO in project cloudstack by apache.
the class LibvirtComputingResourceTest method testDestroyCommandError.
@SuppressWarnings("unchecked")
@Test
public void testDestroyCommandError() {
final StoragePool pool = Mockito.mock(StoragePool.class);
final Volume volume = Mockito.mock(Volume.class);
final String vmName = "Test";
final DestroyCommand command = new DestroyCommand(pool, volume, vmName);
final KVMStoragePoolManager poolManager = Mockito.mock(KVMStoragePoolManager.class);
final KVMStoragePool primary = Mockito.mock(KVMStoragePool.class);
final VolumeTO vol = command.getVolume();
when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(poolManager);
when(poolManager.getStoragePool(vol.getPoolType(), vol.getPoolUuid())).thenReturn(primary);
when(primary.deletePhysicalDisk(vol.getPath(), null)).thenThrow(CloudRuntimeException.class);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertFalse(answer.getResult());
verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
verify(poolManager, times(1)).getStoragePool(vol.getPoolType(), vol.getPoolUuid());
}
use of com.cloud.agent.api.to.VolumeTO in project cloudstack by apache.
the class VmwareStorageMotionStrategy method migrateVmWithVolumesAcrossCluster.
private Answer migrateVmWithVolumesAcrossCluster(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));
}
// Migration across cluster needs to be done in three phases.
// 1. Send a migrate command to source resource to initiate migration
// Run validations against target!!
// 2. Complete the process. Update the volume details.
MigrateWithStorageCommand migrateWithStorageCmd = new MigrateWithStorageCommand(to, volumeToFilerto, destHost.getGuid());
MigrateWithStorageAnswer migrateWithStorageAnswer = (MigrateWithStorageAnswer) agentMgr.send(srcHost.getId(), migrateWithStorageCmd);
if (migrateWithStorageAnswer == null) {
s_logger.error("Migration with storage of vm " + vm + " to host " + destHost + " failed.");
throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
} else if (!migrateWithStorageAnswer.getResult()) {
s_logger.error("Migration with storage of vm " + vm + " failed. Details: " + migrateWithStorageAnswer.getDetails());
throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost + ". " + migrateWithStorageAnswer.getDetails());
} else {
// Update the volume details after migration.
updateVolumesAfterMigration(volumeToPool, migrateWithStorageAnswer.getVolumeTos());
}
s_logger.debug("Storage migration of VM " + vm.getInstanceName() + " completed successfully. Migrated to host " + destHost.getName());
return migrateWithStorageAnswer;
} 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());
}
}
Aggregations