Search in sources :

Example 11 with CreatePrivateTemplateAnswer

use of com.cloud.agent.api.storage.CreatePrivateTemplateAnswer in project cloudstack by apache.

the class VmwareStorageManagerImpl method execute.

@Override
public Answer execute(VmwareHostService hostService, CreatePrivateTemplateFromSnapshotCommand cmd) {
    Long accountId = cmd.getAccountId();
    Long volumeId = cmd.getVolumeId();
    String secondaryStorageUrl = cmd.getSecondaryStorageUrl();
    String backedUpSnapshotUuid = cmd.getSnapshotUuid();
    Long newTemplateId = cmd.getNewTemplateId();
    String details;
    String uniqeName = UUID.randomUUID().toString();
    VmwareContext context = hostService.getServiceContext(cmd);
    try {
        Ternary<String, Long, Long> result = createTemplateFromSnapshot(accountId, newTemplateId, uniqeName, secondaryStorageUrl, volumeId, backedUpSnapshotUuid, cmd.getNfsVersion());
        return new CreatePrivateTemplateAnswer(cmd, true, null, result.first(), result.third(), result.second(), uniqeName, ImageFormat.OVA);
    } catch (Throwable e) {
        return new CreatePrivateTemplateAnswer(cmd, false, hostService.createLogMessageException(e, cmd));
    }
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer)

Example 12 with CreatePrivateTemplateAnswer

use of com.cloud.agent.api.storage.CreatePrivateTemplateAnswer in project cloudstack by apache.

the class VmwareStorageManagerImpl method execute.

@Override
public Answer execute(VmwareHostService hostService, CreatePrivateTemplateFromVolumeCommand cmd) {
    String secondaryStoragePoolURL = cmd.getSecondaryStorageUrl();
    String volumePath = cmd.getVolumePath();
    Long accountId = cmd.getAccountId();
    Long templateId = cmd.getTemplateId();
    String details = null;
    VmwareContext context = hostService.getServiceContext(cmd);
    try {
        VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
        VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName());
        if (vmMo == null) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Unable to find the owner VM for CreatePrivateTemplateFromVolumeCommand on host " + hyperHost.getHyperHostName() + ", try within datacenter");
            }
            vmMo = hyperHost.findVmOnPeerHyperHost(cmd.getVmName());
            if (vmMo == null) {
                String msg = "Unable to find the owner VM for volume operation. vm: " + cmd.getVmName();
                s_logger.error(msg);
                throw new Exception(msg);
            }
        }
        Ternary<String, Long, Long> result = createTemplateFromVolume(vmMo, accountId, templateId, cmd.getUniqueName(), secondaryStoragePoolURL, volumePath, hostService.getWorkerName(context, cmd, 0, null), cmd.getNfsVersion());
        return new CreatePrivateTemplateAnswer(cmd, true, null, result.first(), result.third(), result.second(), cmd.getUniqueName(), ImageFormat.OVA);
    } catch (Throwable e) {
        return new CreatePrivateTemplateAnswer(cmd, false, hostService.createLogMessageException(e, cmd));
    }
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 13 with CreatePrivateTemplateAnswer

use of com.cloud.agent.api.storage.CreatePrivateTemplateAnswer in project cloudstack by apache.

the class Ovm3StorageProcessor method execute.

/* check if a VM is running should be added */
public CreatePrivateTemplateAnswer execute(final CreatePrivateTemplateFromVolumeCommand cmd) {
    LOGGER.debug("execute: " + cmd.getClass());
    String volumePath = cmd.getVolumePath();
    Long accountId = cmd.getAccountId();
    Long templateId = cmd.getTemplateId();
    int wait = cmd.getWait();
    if (wait == 0) {
        /* Defaut timeout 2 hours */
        wait = 7200;
    }
    try {
        /* missing uuid */
        String installPath = config.getAgentOvmRepoPath() + "/" + config.getTemplateDir() + "/" + accountId + "/" + templateId;
        Linux host = new Linux(c);
        host.copyFile(volumePath, installPath);
        return new CreatePrivateTemplateAnswer(cmd, true, installPath);
    } catch (Exception e) {
        LOGGER.debug("Create template failed", e);
        return new CreatePrivateTemplateAnswer(cmd, false, e.getMessage());
    }
}
Also used : Linux(com.cloud.hypervisor.ovm3.objects.Linux) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) URISyntaxException(java.net.URISyntaxException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 14 with CreatePrivateTemplateAnswer

use of com.cloud.agent.api.storage.CreatePrivateTemplateAnswer in project cloudstack by apache.

the class OvmResourceBase method execute.

protected CreatePrivateTemplateAnswer execute(final CreatePrivateTemplateFromVolumeCommand cmd) {
    String secondaryStorageUrl = cmd.getSecondaryStorageUrl();
    String volumePath = cmd.getVolumePath();
    Long accountId = cmd.getAccountId();
    Long templateId = cmd.getTemplateId();
    int wait = cmd.getWait();
    if (wait == 0) {
        /* Defaut timeout 2 hours */
        wait = 7200;
    }
    try {
        URI uri;
        uri = new URI(secondaryStorageUrl);
        String secondaryStorageMountPath = uri.getHost() + ":" + uri.getPath();
        String installPath = "template/tmpl/" + accountId + "/" + templateId;
        Map<String, String> res = OvmStoragePool.createTemplateFromVolume(_conn, secondaryStorageMountPath, installPath, volumePath, wait);
        return new CreatePrivateTemplateAnswer(cmd, true, null, res.get("installPath"), Long.parseLong(res.get("virtualSize")), Long.parseLong(res.get("physicalSize")), res.get("templateFileName"), ImageFormat.RAW);
    } catch (Exception e) {
        s_logger.debug("Create template failed", e);
        return new CreatePrivateTemplateAnswer(cmd, false, e.getMessage());
    }
}
Also used : CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) URI(java.net.URI) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(javax.naming.ConfigurationException)

Example 15 with CreatePrivateTemplateAnswer

use of com.cloud.agent.api.storage.CreatePrivateTemplateAnswer in project cloudstack by apache.

the class LibvirtCreatePrivateTemplateFromSnapshotCommandWrapper method execute.

@Override
public Answer execute(final CreatePrivateTemplateFromSnapshotCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
    final String templateFolder = command.getAccountId() + File.separator + command.getNewTemplateId();
    final String templateInstallFolder = "template/tmpl/" + templateFolder;
    final String tmplName = libvirtUtilitiesHelper.generateUUIDName();
    final String tmplFileName = tmplName + ".qcow2";
    KVMStoragePool secondaryPool = null;
    KVMStoragePool snapshotPool = null;
    final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
    try {
        String snapshotPath = command.getSnapshotUuid();
        final int index = snapshotPath.lastIndexOf("/");
        snapshotPath = snapshotPath.substring(0, index);
        snapshotPool = storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath);
        secondaryPool = storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl());
        final KVMPhysicalDisk snapshot = snapshotPool.getPhysicalDisk(command.getSnapshotName());
        final String templatePath = secondaryPool.getLocalPath() + File.separator + templateInstallFolder;
        final StorageLayer storage = libvirtComputingResource.getStorage();
        storage.mkdirs(templatePath);
        final String tmplPath = templateInstallFolder + File.separator + tmplFileName;
        final String createTmplPath = libvirtComputingResource.createTmplPath();
        final int cmdsTimeout = libvirtComputingResource.getCmdsTimeout();
        final Script scriptCommand = new Script(createTmplPath, cmdsTimeout, s_logger);
        scriptCommand.add("-t", templatePath);
        scriptCommand.add("-n", tmplFileName);
        scriptCommand.add("-f", snapshot.getPath());
        scriptCommand.execute();
        final Processor qcow2Processor = libvirtUtilitiesHelper.buildQCOW2Processor(storage);
        final FormatInfo info = qcow2Processor.process(templatePath, null, tmplName);
        final TemplateLocation loc = libvirtUtilitiesHelper.buildTemplateLocation(storage, templatePath);
        loc.create(1, true, tmplName);
        loc.addFormat(info);
        loc.save();
        return new CreatePrivateTemplateAnswer(command, true, "", tmplPath, info.virtualSize, info.size, tmplName, info.format);
    } catch (final ConfigurationException e) {
        return new CreatePrivateTemplateAnswer(command, false, e.getMessage());
    } catch (final InternalErrorException e) {
        return new CreatePrivateTemplateAnswer(command, false, e.getMessage());
    } catch (final IOException e) {
        return new CreatePrivateTemplateAnswer(command, false, e.getMessage());
    } catch (final CloudRuntimeException e) {
        return new CreatePrivateTemplateAnswer(command, false, e.getMessage());
    } finally {
        if (secondaryPool != null) {
            storagePoolMgr.deleteStoragePool(secondaryPool.getType(), secondaryPool.getUuid());
        }
        if (snapshotPool != null) {
            storagePoolMgr.deleteStoragePool(snapshotPool.getType(), snapshotPool.getUuid());
        }
    }
}
Also used : Script(com.cloud.utils.script.Script) KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) StorageLayer(com.cloud.storage.StorageLayer) Processor(com.cloud.storage.template.Processor) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk) InternalErrorException(com.cloud.exception.InternalErrorException) IOException(java.io.IOException) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) ConfigurationException(javax.naming.ConfigurationException) TemplateLocation(com.cloud.storage.template.TemplateLocation) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) FormatInfo(com.cloud.storage.template.Processor.FormatInfo)

Aggregations

CreatePrivateTemplateAnswer (com.cloud.agent.api.storage.CreatePrivateTemplateAnswer)15 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)10 ConfigurationException (javax.naming.ConfigurationException)9 IOException (java.io.IOException)7 InternalErrorException (com.cloud.exception.InternalErrorException)6 Processor (com.cloud.storage.template.Processor)6 FormatInfo (com.cloud.storage.template.Processor.FormatInfo)6 TemplateLocation (com.cloud.storage.template.TemplateLocation)6 Script (com.cloud.utils.script.Script)6 MockSecStorageVO (com.cloud.simulator.MockSecStorageVO)4 MockVolumeVO (com.cloud.simulator.MockVolumeVO)4 StorageLayer (com.cloud.storage.StorageLayer)4 QCOW2Processor (com.cloud.storage.template.QCOW2Processor)4 URISyntaxException (java.net.URISyntaxException)4 HashMap (java.util.HashMap)4 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)3 KVMPhysicalDisk (com.cloud.agent.storage.KVMPhysicalDisk)2 KVMStoragePool (com.cloud.agent.storage.KVMStoragePool)2 KVMPhysicalDisk (com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk)2 KVMStoragePool (com.cloud.hypervisor.kvm.storage.KVMStoragePool)2