use of com.cloud.hypervisor.kvm.storage.KvmStoragePool in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResource method getVolumePath.
public String getVolumePath(final Connect conn, final DiskTO volume) throws LibvirtException, URISyntaxException {
final DataTO data = volume.getData();
final DataStoreTO store = data.getDataStore();
if (volume.getType() == Volume.Type.ISO && data.getPath() != null) {
final NfsTO nfsStore = (NfsTO) store;
final String isoPath = nfsStore.getUrl() + File.separator + data.getPath();
final int index = isoPath.lastIndexOf("/");
final String path = isoPath.substring(0, index);
final String name = isoPath.substring(index + 1);
final KvmStoragePool secondaryPool = storagePoolMgr.getStoragePoolByUri(path);
final KvmPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name);
return isoVol.getPath();
} else {
return data.getPath();
}
}
use of com.cloud.hypervisor.kvm.storage.KvmStoragePool in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResource method initialize.
@Override
public StartupCommand[] initialize() {
final List<Object> info = getHostInfo();
totalMemory = (Long) info.get(1);
final StartupRoutingCommand cmd = new StartupRoutingCommand((Integer) info.get(0), (Long) info.get(1), (Long) info.get(3), (String) info.get(2), getHypervisorType(), RouterPrivateIpStrategy.HostLocal);
cmd.setCpuSockets((Integer) info.get(4));
fillNetworkInformation(cmd);
privateIp = cmd.getPrivateIpAddress();
cmd.getHostDetails().putAll(getVersionStrings());
cmd.setPool(getPool());
cmd.setCluster(getCluster());
cmd.setGatewayIpAddress(localGateway);
cmd.setIqn(getIqn());
cmd.setVersion(LibvirtComputingResource.class.getPackage().getImplementationVersion());
StartupStorageCommand sscmd = null;
try {
final String localStoragePath = getLocalStoragePath();
final KvmStoragePool localStoragePool = storagePoolMgr.createStoragePool(getLocalStorageUuid(), "localhost", -1, localStoragePath, "", StoragePoolType.Filesystem);
final com.cloud.agent.api.StoragePoolInfo pi = new com.cloud.agent.api.StoragePoolInfo(localStoragePool.getUuid(), cmd.getPrivateIpAddress(), localStoragePath, localStoragePath, StoragePoolType.Filesystem, localStoragePool.getCapacity(), localStoragePool.getAvailable());
sscmd = new StartupStorageCommand();
sscmd.setPoolInfo(pi);
sscmd.setGuid(pi.getUuid());
sscmd.setDataCenter(getZone());
sscmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
} catch (final CloudRuntimeException e) {
logger.debug("Unable to initialize local storage pool: " + e);
}
if (sscmd != null) {
return new StartupCommand[] { cmd, sscmd };
} else {
return new StartupCommand[] { cmd };
}
}
use of com.cloud.hypervisor.kvm.storage.KvmStoragePool in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResource method attachOrDetachIso.
public synchronized String attachOrDetachIso(final Connect conn, final String vmName, String isoPath, final boolean isAttach) throws LibvirtException, URISyntaxException, InternalErrorException {
String isoXml = null;
if (isoPath != null && isAttach) {
final int index = isoPath.lastIndexOf("/");
final String path = isoPath.substring(0, index);
final String name = isoPath.substring(index + 1);
final KvmStoragePool secondaryPool = storagePoolMgr.getStoragePoolByUri(path);
final KvmPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name);
isoPath = isoVol.getPath();
final LibvirtDiskDef iso = new LibvirtDiskDef();
iso.defIsoDisk(isoPath);
isoXml = iso.toString();
} else {
final LibvirtDiskDef iso = new LibvirtDiskDef();
iso.defIsoDisk(null);
isoXml = iso.toString();
}
final List<LibvirtDiskDef> disks = getDisks(conn, vmName);
final String result = attachOrDetachDevice(conn, true, vmName, isoXml);
if (result == null && !isAttach) {
for (final LibvirtDiskDef disk : disks) {
if (disk.getDeviceType() == LibvirtDiskDef.DeviceType.CDROM) {
cleanupDisk(disk);
}
}
}
return result;
}
use of com.cloud.hypervisor.kvm.storage.KvmStoragePool in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testCreateCommandNoTemplate.
@Test
public void testCreateCommandNoTemplate() {
final DiskProfile diskCharacteristics = Mockito.mock(DiskProfile.class);
final StorageFilerTO pool = Mockito.mock(StorageFilerTO.class);
final boolean executeInSequence = false;
final CreateCommand command = new CreateCommand(diskCharacteristics, pool, executeInSequence);
final KvmStoragePoolManager poolManager = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool primary = Mockito.mock(KvmStoragePool.class);
final KvmPhysicalDisk vol = Mockito.mock(KvmPhysicalDisk.class);
when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(poolManager);
when(poolManager.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primary);
when(primary.createPhysicalDisk(diskCharacteristics.getPath(), diskCharacteristics.getProvisioningType(), diskCharacteristics.getSize())).thenReturn(vol);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertTrue(answer.getResult());
verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
verify(poolManager, times(1)).getStoragePool(pool.getType(), pool.getUuid());
}
use of com.cloud.hypervisor.kvm.storage.KvmStoragePool in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testManageSnapshotCommandLibvirt.
@Test
public void testManageSnapshotCommandLibvirt() {
final StoragePool storagePool = Mockito.mock(StoragePool.class);
final String volumePath = "/123/vol";
final String vmName = "Test";
final long snapshotId = 1l;
final String preSnapshotPath = "/snapshot/path";
final String snapshotName = "snap";
final ManageSnapshotCommand command = new ManageSnapshotCommand(snapshotId, volumePath, storagePool, preSnapshotPath, snapshotName, vmName);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final Connect conn = Mockito.mock(Connect.class);
final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool primaryPool = Mockito.mock(KvmStoragePool.class);
final Domain vm = Mockito.mock(Domain.class);
final DomainInfo info = Mockito.mock(DomainInfo.class);
final DomainState state = DomainInfo.DomainState.VIR_DOMAIN_RUNNING;
info.state = state;
final KvmPhysicalDisk disk = Mockito.mock(KvmPhysicalDisk.class);
final StorageFilerTO pool = command.getPool();
when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
when(libvirtComputingResource.getDomain(conn, command.getVmName())).thenReturn(vm);
when(vm.getInfo()).thenReturn(info);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primaryPool);
when(primaryPool.getPhysicalDisk(command.getVolumePath())).thenReturn(disk);
when(primaryPool.isExternalSnapshot()).thenReturn(false);
try {
when(vm.getUUIDString()).thenReturn("cdb18980-546d-4153-b916-70ee9edf0908");
} catch (final LibvirtException e) {
fail(e.getMessage());
}
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertTrue(answer.getResult());
verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
}
Aggregations