use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.
the class XenServerStorageProcessor method createVolume.
@Override
public Answer createVolume(final CreateObjectCommand cmd) {
final DataTO data = cmd.getData();
final VolumeObjectTO volume = (VolumeObjectTO) data;
try {
final Connection conn = hypervisorResource.getConnection();
final SR poolSr = hypervisorResource.getStorageRepository(conn, data.getDataStore().getUuid());
VDI.Record vdir = new VDI.Record();
vdir.nameLabel = volume.getName();
vdir.SR = poolSr;
vdir.type = Types.VdiType.USER;
vdir.virtualSize = volume.getSize();
VDI vdi;
vdi = VDI.create(conn, vdir);
vdir = vdi.getRecord(conn);
final VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setName(vdir.nameLabel);
newVol.setSize(vdir.virtualSize);
newVol.setPath(vdir.uuid);
return new CreateObjectAnswer(newVol);
} catch (final Exception e) {
s_logger.debug("create volume failed: " + e.toString());
return new CreateObjectAnswer(e.toString());
}
}
use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.
the class XenServerStorageProcessor method createTemplateFromVolume.
@Override
public Answer createTemplateFromVolume(final CopyCommand cmd) {
final Connection conn = hypervisorResource.getConnection();
final VolumeObjectTO volume = (VolumeObjectTO) cmd.getSrcTO();
final TemplateObjectTO template = (TemplateObjectTO) cmd.getDestTO();
final NfsTO destStore = (NfsTO) cmd.getDestTO().getDataStore();
final int wait = cmd.getWait();
final String secondaryStoragePoolURL = destStore.getUrl();
final String volumeUUID = volume.getPath();
final String userSpecifiedName = template.getName();
String details = null;
SR tmpltSR = null;
boolean result = false;
String secondaryStorageMountPath = null;
String installPath = null;
try {
final URI uri = new URI(secondaryStoragePoolURL);
secondaryStorageMountPath = uri.getHost() + ":" + uri.getPath();
installPath = template.getPath();
if (!hypervisorResource.createSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath)) {
details = " Filed to create folder " + installPath + " in secondary storage";
s_logger.warn(details);
return new CopyCmdAnswer(details);
}
final VDI vol = getVDIbyUuid(conn, volumeUUID);
// create template SR
final URI tmpltURI = new URI(secondaryStoragePoolURL + "/" + installPath);
tmpltSR = hypervisorResource.createNfsSRbyURI(conn, tmpltURI, false);
// copy volume to template SR
final VDI tmpltVDI = hypervisorResource.cloudVDIcopy(conn, vol, tmpltSR, wait);
// scan makes XenServer pick up VDI physicalSize
tmpltSR.scan(conn);
if (userSpecifiedName != null) {
tmpltVDI.setNameLabel(conn, userSpecifiedName);
}
final String tmpltUUID = tmpltVDI.getUuid(conn);
final String tmpltFilename = tmpltUUID + ".vhd";
final long virtualSize = tmpltVDI.getVirtualSize(conn);
final long physicalSize = tmpltVDI.getPhysicalUtilisation(conn);
// create the template.properties file
final String templatePath = secondaryStorageMountPath + "/" + installPath;
result = hypervisorResource.postCreatePrivateTemplate(conn, templatePath, tmpltFilename, tmpltUUID, userSpecifiedName, null, physicalSize, virtualSize, template.getId());
if (!result) {
throw new CloudRuntimeException("Could not create the template.properties file on secondary storage dir: " + tmpltURI);
}
installPath = installPath + "/" + tmpltFilename;
hypervisorResource.removeSR(conn, tmpltSR);
tmpltSR = null;
final TemplateObjectTO newTemplate = new TemplateObjectTO();
newTemplate.setPath(installPath);
newTemplate.setFormat(ImageFormat.VHD);
newTemplate.setSize(virtualSize);
newTemplate.setPhysicalSize(physicalSize);
newTemplate.setName(tmpltUUID);
final CopyCmdAnswer answer = new CopyCmdAnswer(newTemplate);
return answer;
} catch (final Exception e) {
if (tmpltSR != null) {
hypervisorResource.removeSR(conn, tmpltSR);
}
if (secondaryStorageMountPath != null) {
hypervisorResource.deleteSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath);
}
details = "Creating template from volume " + volumeUUID + " failed due to " + e.toString();
s_logger.error(details, e);
}
return new CopyCmdAnswer(details);
}
use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.
the class StorageManagerImpl method getDiskWithThrottling.
@Override
public DiskTO getDiskWithThrottling(final DataTO volTO, final Volume.Type volumeType, final long deviceId, final String path, final long offeringId, final long diskOfferingId) {
DiskTO disk = null;
if (volTO != null && volTO instanceof VolumeObjectTO) {
VolumeObjectTO volumeTO = (VolumeObjectTO) volTO;
ServiceOffering offering = _entityMgr.findById(ServiceOffering.class, offeringId);
DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, diskOfferingId);
if (volumeType == Volume.Type.ROOT) {
setVolumeObjectTOThrottling(volumeTO, offering, diskOffering);
} else {
setVolumeObjectTOThrottling(volumeTO, null, diskOffering);
}
disk = new DiskTO(volumeTO, deviceId, path, volumeType);
} else {
disk = new DiskTO(volTO, deviceId, path, volumeType);
}
return disk;
}
use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.
the class SimulatorStorageProcessor method createVolumeFromSnapshot.
@Override
public Answer createVolumeFromSnapshot(CopyCommand cmd) {
DataTO srcData = cmd.getSrcTO();
SnapshotObjectTO snapshot = (SnapshotObjectTO) srcData;
String snapshotPath = snapshot.getPath();
int index = snapshotPath.lastIndexOf("/");
String snapshotName = snapshotPath.substring(index + 1);
VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setPath(snapshotName);
return new CopyCmdAnswer(newVol);
}
use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.
the class SimulatorStorageProcessor method copyVolumeFromPrimaryToSecondary.
@Override
public Answer copyVolumeFromPrimaryToSecondary(CopyCommand cmd) {
VolumeObjectTO volume = new VolumeObjectTO();
volume.setPath(UUID.randomUUID().toString());
volume.setSize(100);
volume.setFormat(Storage.ImageFormat.RAW);
return new CopyCmdAnswer(volume);
}
Aggregations