use of com.cloud.agent.api.storage.CreateAnswer in project cloudstack by apache.
the class OvmResourceBase method execute.
protected CreateAnswer execute(CreateCommand cmd) {
StorageFilerTO primaryStorage = cmd.getPool();
DiskProfile disk = cmd.getDiskCharacteristics();
try {
OvmVolume.Details vol = null;
if (cmd.getTemplateUrl() != null) {
vol = OvmVolume.createFromTemplate(_conn, primaryStorage.getUuid(), cmd.getTemplateUrl());
} else {
vol = OvmVolume.createDataDsik(_conn, primaryStorage.getUuid(), Long.toString(disk.getSize()), disk.getType() == Volume.Type.ROOT);
}
VolumeTO volume = new VolumeTO(cmd.getVolumeId(), disk.getType(), primaryStorage.getType(), primaryStorage.getUuid(), primaryStorage.getPath(), vol.name, vol.path, vol.size, null);
return new CreateAnswer(cmd, volume);
} catch (Exception e) {
s_logger.debug("CreateCommand failed", e);
return new CreateAnswer(cmd, e.getMessage());
}
}
use of com.cloud.agent.api.storage.CreateAnswer in project cloudstack by apache.
the class MockStorageManagerImpl method createVolume.
@Override
public CreateAnswer createVolume(CreateCommand cmd) {
StorageFilerTO sf = cmd.getPool();
DiskProfile dskch = cmd.getDiskCharacteristics();
MockStoragePoolVO storagePool = null;
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
storagePool = _mockStoragePoolDao.findByUuid(sf.getUuid());
txn.commit();
if (storagePool == null) {
return new CreateAnswer(cmd, "Failed to find storage pool: " + sf.getUuid());
}
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when finding storage " + sf.getUuid(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
String volumeName = UUID.randomUUID().toString();
MockVolumeVO volume = new MockVolumeVO();
volume.setPoolId(storagePool.getId());
volume.setName(volumeName);
volume.setPath(storagePool.getMountPoint() + volumeName);
volume.setSize(dskch.getSize());
volume.setType(MockVolumeType.VOLUME);
txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
volume = _mockVolumeDao.persist(volume);
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when saving volume " + volume, ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
VolumeTO volumeTo = new VolumeTO(cmd.getVolumeId(), dskch.getType(), sf.getType(), sf.getUuid(), volume.getName(), storagePool.getMountPoint(), volume.getPath(), volume.getSize(), null);
return new CreateAnswer(cmd, volumeTo);
}
use of com.cloud.agent.api.storage.CreateAnswer in project cloudstack by apache.
the class Ovm3StorageProcessor method execute.
public CreateAnswer execute(CreateCommand cmd) {
LOGGER.debug("execute: " + cmd.getClass());
StorageFilerTO primaryStorage = cmd.getPool();
DiskProfile disk = cmd.getDiskCharacteristics();
/* disk should have a uuid */
// should also be replaced with getVirtualDiskPath ?
String fileName = UUID.randomUUID().toString() + ".raw";
String dst = primaryStorage.getPath() + "/" + primaryStorage.getUuid() + "/" + fileName;
try {
StoragePlugin store = new StoragePlugin(c);
if (cmd.getTemplateUrl() != null) {
LOGGER.debug("CreateCommand " + cmd.getTemplateUrl() + " " + dst);
Linux host = new Linux(c);
host.copyFile(cmd.getTemplateUrl(), dst);
} else {
/* this is a dup with the createVolume ? */
LOGGER.debug("CreateCommand " + dst);
store.storagePluginCreate(primaryStorage.getUuid(), primaryStorage.getHost(), dst, disk.getSize(), false);
}
FileProperties fp = store.storagePluginGetFileInfo(primaryStorage.getUuid(), primaryStorage.getHost(), dst);
VolumeTO volume = new VolumeTO(cmd.getVolumeId(), disk.getType(), primaryStorage.getType(), primaryStorage.getUuid(), primaryStorage.getPath(), fileName, fp.getName(), fp.getSize(), null);
return new CreateAnswer(cmd, volume);
} catch (Exception e) {
LOGGER.debug("CreateCommand failed", e);
return new CreateAnswer(cmd, e.getMessage());
}
}
Aggregations