use of com.cloud.legacymodel.storage.TemplateFormatInfo in project cosmic by MissionCriticalCloud.
the class VhdProcessor method process.
@Override
public TemplateFormatInfo process(final String templatePath, final ImageFormat format, final String templateName) throws InternalErrorException {
if (format != null) {
s_logger.debug("We currently don't handle conversion from " + format + " to VHD.");
return null;
}
final String vhdPath = templatePath + File.separator + templateName + "." + ImageFormat.VHD.toString().toLowerCase();
if (!this._storage.exists(vhdPath)) {
s_logger.debug("Unable to find the vhd file: " + vhdPath);
return null;
}
final File vhdFile = this._storage.getFile(vhdPath);
final TemplateFormatInfo info = new TemplateFormatInfo();
info.format = ImageFormat.VHD;
info.filename = templateName + "." + ImageFormat.VHD.toString().toLowerCase();
info.size = this._storage.getSize(vhdPath);
try {
info.virtualSize = getTemplateVirtualSize(vhdFile);
} catch (final IOException e) {
s_logger.error("Unable to get the virtual size for " + vhdPath);
throw new InternalErrorException("unable to get virtual size from vhd file");
}
return info;
}
use of com.cloud.legacymodel.storage.TemplateFormatInfo in project cosmic by MissionCriticalCloud.
the class QCOW2Processor method process.
@Override
public TemplateFormatInfo process(final String templatePath, final ImageFormat format, final String templateName) throws InternalErrorException {
if (format != null) {
s_logger.debug("We currently don't handle conversion from " + format + " to QCOW2.");
return null;
}
final String qcow2Path = templatePath + File.separator + templateName + "." + ImageFormat.QCOW2.toString().toLowerCase();
if (!this._storage.exists(qcow2Path)) {
s_logger.debug("Unable to find the qcow2 file: " + qcow2Path);
return null;
}
final TemplateFormatInfo info = new TemplateFormatInfo();
info.format = ImageFormat.QCOW2;
info.filename = templateName + "." + ImageFormat.QCOW2.toString().toLowerCase();
final File qcow2File = this._storage.getFile(qcow2Path);
info.size = this._storage.getSize(qcow2Path);
try {
info.virtualSize = getTemplateVirtualSize(qcow2File);
} catch (final IOException e) {
s_logger.error("Unable to get virtual size from " + qcow2File.getName());
throw new InternalErrorException("unable to get virtual size from qcow2 file");
}
return info;
}
use of com.cloud.legacymodel.storage.TemplateFormatInfo in project cosmic by MissionCriticalCloud.
the class RawImageProcessor method process.
@Override
public TemplateFormatInfo process(final String templatePath, final ImageFormat format, final String templateName) throws InternalErrorException {
if (format != null) {
s_logger.debug("We currently don't handle conversion from " + format + " to raw image.");
return null;
}
final String imgPath = templatePath + File.separator + templateName + "." + ImageFormat.RAW.toString().toLowerCase();
if (!this._storage.exists(imgPath)) {
s_logger.debug("Unable to find raw image:" + imgPath);
return null;
}
final TemplateFormatInfo info = new TemplateFormatInfo();
info.format = ImageFormat.RAW;
info.filename = templateName + "." + ImageFormat.RAW.toString().toLowerCase();
info.size = this._storage.getSize(imgPath);
info.virtualSize = info.size;
s_logger.debug("Process raw image " + info.filename + " successfully");
return info;
}
use of com.cloud.legacymodel.storage.TemplateFormatInfo in project cosmic by MissionCriticalCloud.
the class TARProcessor method process.
@Override
public TemplateFormatInfo process(final String templatePath, final ImageFormat format, final String templateName) {
if (format != null) {
s_logger.debug("We currently don't handle conversion from " + format + " to TAR.");
return null;
}
final String tarPath = templatePath + File.separator + templateName + "." + ImageFormat.TAR.toString().toLowerCase();
if (!this._storage.exists(tarPath)) {
s_logger.debug("Unable to find the tar file: " + tarPath);
return null;
}
final TemplateFormatInfo info = new TemplateFormatInfo();
info.format = ImageFormat.TAR;
info.filename = templateName + "." + ImageFormat.TAR.toString().toLowerCase();
final File tarFile = this._storage.getFile(tarPath);
info.size = this._storage.getSize(tarPath);
info.virtualSize = getVirtualSize(tarFile);
return info;
}
use of com.cloud.legacymodel.storage.TemplateFormatInfo in project cosmic by MissionCriticalCloud.
the class TemplateLocation method save.
public boolean save() {
for (final TemplateFormatInfo info : this._formats) {
this._props.setProperty(info.format.toString().toLowerCase(), "true");
this._props.setProperty(info.format.toString().toLowerCase() + ".filename", info.filename);
this._props.setProperty(info.format.toString().toLowerCase() + ".size", Long.toString(info.size));
this._props.setProperty(info.format.toString().toLowerCase() + ".virtualsize", Long.toString(info.virtualSize));
}
try (final FileOutputStream strm = new FileOutputStream(this._file)) {
this._props.store(strm, "");
} catch (final IOException e) {
s_logger.warn("Unable to save the template properties ", e);
return false;
}
return true;
}
Aggregations