Search in sources :

Example 1 with DiskProfile

use of com.cloud.vm.DiskProfile 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);
    }
}
Also used : CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) FenceAnswer(com.cloud.agent.api.FenceAnswer) ConsoleProxyLoadAnswer(com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer) DeleteSnapshotBackupAnswer(com.cloud.agent.api.DeleteSnapshotBackupAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) AttachVolumeAnswer(com.cloud.agent.api.AttachVolumeAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) IpAssocAnswer(com.cloud.agent.api.routing.IpAssocAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) SecurityGroupRuleAnswer(com.cloud.agent.api.SecurityGroupRuleAnswer) VolumeTO(com.cloud.agent.api.to.VolumeTO) KVMStoragePool(com.cloud.agent.storage.KVMStoragePool) KVMPhysicalDisk(com.cloud.agent.storage.KVMPhysicalDisk) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) DiskProfile(com.cloud.vm.DiskProfile)

Example 2 with DiskProfile

use of com.cloud.vm.DiskProfile in project cloudstack by apache.

the class StorageAllocatorTest method testClusterAllocatorWithTags.

@Test
public void testClusterAllocatorWithTags() {
    try {
        createDb();
        StoragePoolDetailVO detailVO = new StoragePoolDetailVO(this.storagePoolId, "high", "true", true);
        poolDetailsDao.persist(detailVO);
        DiskOfferingVO diskOff = this.diskOfferingDao.findById(diskOffering.getId());
        List<String> tags = new ArrayList<String>();
        tags.add("high");
        diskOff.setTagsArray(tags);
        diskOfferingDao.update(diskOff.getId(), diskOff);
        DiskProfile profile = new DiskProfile(volume, diskOff, HypervisorType.XenServer);
        VirtualMachineProfile vmProfile = Mockito.mock(VirtualMachineProfile.class);
        Mockito.when(storageMgr.storagePoolHasEnoughSpace(Matchers.anyListOf(Volume.class), Matchers.any(StoragePool.class))).thenReturn(true);
        DeploymentPlan plan = new DataCenterDeployment(dcId, podId, clusterId, null, null, null);
        int foundAcct = 0;
        for (StoragePoolAllocator allocator : allocators) {
            List<StoragePool> pools = allocator.allocateToPool(profile, vmProfile, plan, new ExcludeList(), 1);
            if (!pools.isEmpty()) {
                Assert.assertEquals(pools.get(0).getId(), storage.getId());
                foundAcct++;
            }
        }
        if (foundAcct > 1 || foundAcct == 0) {
            Assert.fail();
        }
    } catch (Exception e) {
        cleanDb();
        Assert.fail();
    }
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) StoragePool(com.cloud.storage.StoragePool) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) ArrayList(java.util.ArrayList) StoragePoolDetailVO(org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO) DiskProfile(com.cloud.vm.DiskProfile) Volume(com.cloud.storage.Volume) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DeploymentPlan(com.cloud.deploy.DeploymentPlan) StoragePoolAllocator(org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator) Test(org.junit.Test)

Example 3 with DiskProfile

use of com.cloud.vm.DiskProfile in project cloudstack by apache.

the class StorageAllocatorTest method testZoneWideStorageAllocator.

@Test
public void testZoneWideStorageAllocator() {
    try {
        createDb();
        StoragePoolVO pool = storagePoolDao.findById(storagePoolId);
        pool.setHypervisor(HypervisorType.KVM);
        pool.setScope(ScopeType.ZONE);
        pool.setClusterId(null);
        pool.setPodId(null);
        storagePoolDao.update(pool.getId(), pool);
        DiskProfile profile = new DiskProfile(volume, diskOffering, HypervisorType.KVM);
        VirtualMachineProfile vmProfile = Mockito.mock(VirtualMachineProfile.class);
        Mockito.when(vmProfile.getHypervisorType()).thenReturn(HypervisorType.KVM);
        Mockito.when(storageMgr.storagePoolHasEnoughSpace(Matchers.anyListOf(Volume.class), Matchers.any(StoragePool.class))).thenReturn(true);
        Mockito.when(storageMgr.storagePoolHasEnoughIops(Matchers.anyListOf(Volume.class), Matchers.any(StoragePool.class))).thenReturn(true);
        DeploymentPlan plan = new DataCenterDeployment(dcId, podId, clusterId, null, null, null);
        int foundAcct = 0;
        for (StoragePoolAllocator allocator : allocators) {
            List<StoragePool> pools = allocator.allocateToPool(profile, vmProfile, plan, new ExcludeList(), 1);
            if (!pools.isEmpty()) {
                Assert.assertEquals(pools.get(0).getId(), storage.getId());
                foundAcct++;
            }
        }
        if (foundAcct > 1 || foundAcct == 0) {
            Assert.fail();
        }
    } catch (Exception e) {
        cleanDb();
        Assert.fail();
    }
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) StoragePool(com.cloud.storage.StoragePool) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) Volume(com.cloud.storage.Volume) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DeploymentPlan(com.cloud.deploy.DeploymentPlan) DiskProfile(com.cloud.vm.DiskProfile) StoragePoolAllocator(org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator) Test(org.junit.Test)

Example 4 with DiskProfile

use of com.cloud.vm.DiskProfile in project cloudstack by apache.

the class StorageAllocatorTest method testClusterAllocator.

@Test
public void testClusterAllocator() {
    try {
        createDb();
        DiskProfile profile = new DiskProfile(volume, diskOffering, HypervisorType.XenServer);
        VirtualMachineProfile vmProfile = Mockito.mock(VirtualMachineProfile.class);
        Mockito.when(storageMgr.storagePoolHasEnoughSpace(Matchers.anyListOf(Volume.class), Matchers.any(StoragePool.class))).thenReturn(true);
        DeploymentPlan plan = new DataCenterDeployment(dcId, podId, clusterId, null, null, null);
        int foundAcct = 0;
        for (StoragePoolAllocator allocator : allocators) {
            List<StoragePool> pools = allocator.allocateToPool(profile, vmProfile, plan, new ExcludeList(), 1);
            if (!pools.isEmpty()) {
                Assert.assertEquals(pools.get(0).getId(), storage.getId());
                foundAcct++;
            }
        }
        if (foundAcct > 1 || foundAcct == 0) {
            Assert.fail();
        }
    } catch (Exception e) {
        cleanDb();
        Assert.fail();
    }
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) StoragePool(com.cloud.storage.StoragePool) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) Volume(com.cloud.storage.Volume) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DeploymentPlan(com.cloud.deploy.DeploymentPlan) DiskProfile(com.cloud.vm.DiskProfile) StoragePoolAllocator(org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator) Test(org.junit.Test)

Example 5 with DiskProfile

use of com.cloud.vm.DiskProfile in project cloudstack by apache.

the class StorageAllocatorTest method testClusterAllocatorMultiplePools.

@Test
public void testClusterAllocatorMultiplePools() {
    Long newStorageId = null;
    try {
        createDb();
        DataStoreProvider provider = providerMgr.getDataStoreProvider(DataStoreProvider.DEFAULT_PRIMARY);
        storage = new StoragePoolVO();
        storage.setDataCenterId(dcId);
        storage.setPodId(podId);
        storage.setPoolType(StoragePoolType.NetworkFilesystem);
        storage.setClusterId(clusterId);
        storage.setStatus(StoragePoolStatus.Up);
        storage.setScope(ScopeType.CLUSTER);
        storage.setUsedBytes(1000);
        storage.setCapacityBytes(20000);
        storage.setHostAddress(UUID.randomUUID().toString());
        storage.setPath(UUID.randomUUID().toString());
        storage.setStorageProviderName(provider.getName());
        StoragePoolVO newStorage = storagePoolDao.persist(storage);
        newStorageId = newStorage.getId();
        DiskProfile profile = new DiskProfile(volume, diskOffering, HypervisorType.XenServer);
        VirtualMachineProfile vmProfile = Mockito.mock(VirtualMachineProfile.class);
        Mockito.when(storageMgr.storagePoolHasEnoughSpace(Matchers.anyListOf(Volume.class), Matchers.any(StoragePool.class))).thenReturn(true);
        DeploymentPlan plan = new DataCenterDeployment(dcId, podId, clusterId, null, null, null);
        int foundAcct = 0;
        for (StoragePoolAllocator allocator : allocators) {
            List<StoragePool> pools = allocator.allocateToPool(profile, vmProfile, plan, new ExcludeList(), 1);
            if (!pools.isEmpty()) {
                Assert.assertEquals(pools.size(), 1);
                foundAcct++;
            }
        }
        if (foundAcct > 1 || foundAcct == 0) {
            Assert.fail();
        }
    } catch (Exception e) {
        cleanDb();
        if (newStorageId != null) {
            storagePoolDao.remove(newStorageId);
        }
        Assert.fail();
    }
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) StoragePool(com.cloud.storage.StoragePool) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) DiskProfile(com.cloud.vm.DiskProfile) Volume(com.cloud.storage.Volume) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DeploymentPlan(com.cloud.deploy.DeploymentPlan) StoragePoolAllocator(org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator) Test(org.junit.Test)

Aggregations

DiskProfile (com.cloud.vm.DiskProfile)49 StoragePool (com.cloud.storage.StoragePool)26 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)18 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)16 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)16 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)16 Test (org.junit.Test)16 Volume (com.cloud.storage.Volume)15 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)14 Answer (com.cloud.agent.api.Answer)12 DiskOfferingVO (com.cloud.storage.DiskOfferingVO)12 ArrayList (java.util.ArrayList)12 StoragePoolAllocator (org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator)12 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)11 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)11 Pair (com.cloud.utils.Pair)10 VolumeTO (com.cloud.agent.api.to.VolumeTO)9 VolumeVO (com.cloud.storage.VolumeVO)9 HashSet (java.util.HashSet)9 CreateCommand (com.cloud.agent.api.storage.CreateCommand)8