Search in sources :

Example 11 with StoragePoolInfo

use of com.cloud.agent.api.StoragePoolInfo in project cloudstack by apache.

the class CitrixResourceBase method initializeLocalSR.

protected StartupStorageCommand initializeLocalSR(final Connection conn) {
    final SR lvmsr = getLocalLVMSR(conn);
    if (lvmsr != null) {
        try {
            _host.setLocalSRuuid(lvmsr.getUuid(conn));
            final String lvmuuid = lvmsr.getUuid(conn);
            final long cap = lvmsr.getPhysicalSize(conn);
            if (cap > 0) {
                final long avail = cap - lvmsr.getPhysicalUtilisation(conn);
                lvmsr.setNameLabel(conn, lvmuuid);
                final String name = "Cloud Stack Local LVM Storage Pool for " + _host.getUuid();
                lvmsr.setNameDescription(conn, name);
                final Host host = Host.getByUuid(conn, _host.getUuid());
                final String address = host.getAddress(conn);
                final StoragePoolInfo pInfo = new StoragePoolInfo(lvmuuid, address, SRType.LVM.toString(), SRType.LVM.toString(), StoragePoolType.LVM, cap, avail);
                final StartupStorageCommand cmd = new StartupStorageCommand();
                cmd.setPoolInfo(pInfo);
                cmd.setGuid(_host.getUuid());
                cmd.setDataCenter(Long.toString(_dcId));
                cmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
                return cmd;
            }
        } catch (final XenAPIException e) {
            final String msg = "build local LVM info err in host:" + _host.getUuid() + e.toString();
            s_logger.warn(msg);
        } catch (final XmlRpcException e) {
            final String msg = "build local LVM info err in host:" + _host.getUuid() + e.getMessage();
            s_logger.warn(msg);
        }
    }
    final SR extsr = getLocalEXTSR(conn);
    if (extsr != null) {
        try {
            final String extuuid = extsr.getUuid(conn);
            _host.setLocalSRuuid(extuuid);
            final long cap = extsr.getPhysicalSize(conn);
            if (cap > 0) {
                final long avail = cap - extsr.getPhysicalUtilisation(conn);
                extsr.setNameLabel(conn, extuuid);
                final String name = "Cloud Stack Local EXT Storage Pool for " + _host.getUuid();
                extsr.setNameDescription(conn, name);
                final Host host = Host.getByUuid(conn, _host.getUuid());
                final String address = host.getAddress(conn);
                final StoragePoolInfo pInfo = new StoragePoolInfo(extuuid, address, SRType.EXT.toString(), SRType.EXT.toString(), StoragePoolType.EXT, cap, avail);
                final StartupStorageCommand cmd = new StartupStorageCommand();
                cmd.setPoolInfo(pInfo);
                cmd.setGuid(_host.getUuid());
                cmd.setDataCenter(Long.toString(_dcId));
                cmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
                return cmd;
            }
        } catch (final XenAPIException e) {
            final String msg = "build local EXT info err in host:" + _host.getUuid() + e.toString();
            s_logger.warn(msg);
        } catch (final XmlRpcException e) {
            final String msg = "build local EXT info err in host:" + _host.getUuid() + e.getMessage();
            s_logger.warn(msg);
        }
    }
    return null;
}
Also used : StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) StoragePoolInfo(com.cloud.agent.api.StoragePoolInfo) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) XmlRpcException(org.apache.xmlrpc.XmlRpcException) SR(com.xensource.xenapi.SR)

Example 12 with StoragePoolInfo

use of com.cloud.agent.api.StoragePoolInfo in project cloudstack by apache.

the class MockStorageManagerImpl method getLocalStorage.

@Override
public StoragePoolInfo getLocalStorage(String hostGuid) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    MockHost host = null;
    MockStoragePoolVO storagePool = null;
    try {
        txn.start();
        host = _mockHostDao.findByGuid(hostGuid);
        storagePool = _mockStoragePoolDao.findByHost(hostGuid);
        txn.commit();
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Unable to find host " + hostGuid, ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    if (storagePool == null) {
        String uuid = UUID.randomUUID().toString();
        storagePool = new MockStoragePoolVO();
        storagePool.setUuid(uuid);
        storagePool.setMountPoint("/mnt/" + uuid);
        storagePool.setCapacity(DEFAULT_HOST_STORAGE_SIZE);
        storagePool.setHostGuid(hostGuid);
        storagePool.setStorageType(StoragePoolType.Filesystem);
        txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
        try {
            txn.start();
            storagePool = _mockStoragePoolDao.persist(storagePool);
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Error when saving storagePool " + storagePool, ex);
        } finally {
            txn.close();
            txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
            txn.close();
        }
    }
    return new StoragePoolInfo(storagePool.getUuid(), host.getPrivateIpAddress(), storagePool.getMountPoint(), storagePool.getMountPoint(), storagePool.getPoolType(), storagePool.getCapacity(), storagePool.getCapacity());
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) MockHost(com.cloud.simulator.MockHost) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolInfo(com.cloud.agent.api.StoragePoolInfo) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

StoragePoolInfo (com.cloud.agent.api.StoragePoolInfo)12 StartupStorageCommand (com.cloud.agent.api.StartupStorageCommand)8 MockHost (com.cloud.simulator.MockHost)4 MockStoragePoolVO (com.cloud.simulator.MockStoragePoolVO)4 StartupCommand (com.cloud.agent.api.StartupCommand)3 StartupRoutingCommand (com.cloud.agent.api.StartupRoutingCommand)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 ConfigurationException (javax.naming.ConfigurationException)3 VmState (com.cloud.agent.api.StartupRoutingCommand.VmState)2 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)2 URISyntaxException (java.net.URISyntaxException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 HashMap (java.util.HashMap)2 CloudException (com.cloud.exception.CloudException)1 InternalErrorException (com.cloud.exception.InternalErrorException)1 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)1 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)1 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)1 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)1 TemplateInfo (com.cloud.storage.template.TemplateInfo)1