Search in sources :

Example 1 with NexentaStorZvol

use of org.apache.cloudstack.storage.datastore.util.NexentaStorAppliance.NexentaStorZvol in project cloudstack by apache.

the class NexentaPrimaryDataStoreDriver method createAsync.

@Override
public void createAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback<CreateCmdResult> callback) {
    String iqn = null;
    String errorMessage = null;
    if (dataObject.getType() != DataObjectType.VOLUME) {
        errorMessage = "Invalid DataObjectType (" + dataObject.getType() + ") passed to createAsync";
    } else {
        VolumeInfo volumeInfo = (VolumeInfo) dataObject;
        long storagePoolId = dataStore.getId();
        NexentaStorAppliance appliance = getNexentaStorAppliance(storagePoolId);
        // TODO: maybe we should use md5(volume name) as volume name
        NexentaStorZvol zvol = (NexentaStorZvol) appliance.createVolume(volumeInfo.getName(), volumeInfo.getSize());
        iqn = zvol.getIqn();
        VolumeVO volume = this._volumeDao.findById(volumeInfo.getId());
        volume.set_iScsiName(iqn);
        volume.setFolder(zvol.getName());
        volume.setPoolType(Storage.StoragePoolType.IscsiLUN);
        volume.setPoolId(storagePoolId);
        _volumeDao.update(volume.getId(), volume);
        StoragePoolVO storagePool = _storagePoolDao.findById(storagePoolId);
        long capacityBytes = storagePool.getCapacityBytes();
        long usedBytes = storagePool.getUsedBytes();
        usedBytes += volumeInfo.getSize();
        storagePool.setUsedBytes(usedBytes > capacityBytes ? capacityBytes : usedBytes);
        _storagePoolDao.update(storagePoolId, storagePool);
    }
    CreateCmdResult result = new CreateCmdResult(iqn, new Answer(null, errorMessage == null, errorMessage));
    result.setResult(errorMessage);
    callback.complete(result);
}
Also used : NexentaStorZvol(org.apache.cloudstack.storage.datastore.util.NexentaStorAppliance.NexentaStorZvol) Answer(com.cloud.agent.api.Answer) VolumeVO(com.cloud.storage.VolumeVO) NexentaStorAppliance(org.apache.cloudstack.storage.datastore.util.NexentaStorAppliance) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)

Aggregations

Answer (com.cloud.agent.api.Answer)1 VolumeVO (com.cloud.storage.VolumeVO)1 CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)1 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)1 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)1 NexentaStorAppliance (org.apache.cloudstack.storage.datastore.util.NexentaStorAppliance)1 NexentaStorZvol (org.apache.cloudstack.storage.datastore.util.NexentaStorAppliance.NexentaStorZvol)1