Search in sources :

Example 11 with TemplateFormatInfo

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;
}
Also used : TemplateFormatInfo(com.cloud.legacymodel.storage.TemplateFormatInfo) IOException(java.io.IOException) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) File(java.io.File)

Example 12 with TemplateFormatInfo

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;
}
Also used : TemplateFormatInfo(com.cloud.legacymodel.storage.TemplateFormatInfo) IOException(java.io.IOException) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) File(java.io.File)

Example 13 with TemplateFormatInfo

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;
}
Also used : TemplateFormatInfo(com.cloud.legacymodel.storage.TemplateFormatInfo)

Example 14 with TemplateFormatInfo

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;
}
Also used : TemplateFormatInfo(com.cloud.legacymodel.storage.TemplateFormatInfo) File(java.io.File)

Example 15 with TemplateFormatInfo

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;
}
Also used : FileOutputStream(java.io.FileOutputStream) TemplateFormatInfo(com.cloud.legacymodel.storage.TemplateFormatInfo) IOException(java.io.IOException)

Aggregations

TemplateFormatInfo (com.cloud.legacymodel.storage.TemplateFormatInfo)19 InternalErrorException (com.cloud.legacymodel.exceptions.InternalErrorException)11 IOException (java.io.IOException)11 Processor (com.cloud.common.storageprocessor.Processor)9 TemplateLocation (com.cloud.common.storageprocessor.TemplateLocation)9 File (java.io.File)9 ConfigurationException (javax.naming.ConfigurationException)7 Script (com.cloud.utils.script.Script)6 KvmPhysicalDisk (com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk)5 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)5 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)5 QCOW2Processor (com.cloud.common.storageprocessor.QCOW2Processor)5 StorageLayer (com.cloud.utils.storage.StorageLayer)5 Test (org.junit.Test)5 NfsStoragePool (com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool)3 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)3 LibvirtUtilitiesHelper (com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper)3 RawImageProcessor (com.cloud.common.storageprocessor.RawImageProcessor)3 TARProcessor (com.cloud.common.storageprocessor.TARProcessor)3 VhdProcessor (com.cloud.common.storageprocessor.VhdProcessor)3