Search in sources :

Example 21 with TemplateObjectTO

use of org.apache.cloudstack.storage.to.TemplateObjectTO in project cloudstack by apache.

the class Ovm3VmSupport method createVbds.

/*
     * Add rootdisk, datadisk and iso's
     */
public Boolean createVbds(Xen.Vm vm, VirtualMachineTO spec) {
    if (spec.getDisks() == null) {
        LOGGER.info("No disks defined for " + vm.getVmName());
        return false;
    }
    for (DiskTO disk : spec.getDisks()) {
        try {
            if (disk.getType() == Volume.Type.ROOT) {
                VolumeObjectTO vol = (VolumeObjectTO) disk.getData();
                String diskFile = processor.getVirtualDiskPath(vol.getUuid(), vol.getDataStore().getUuid());
                vm.addRootDisk(diskFile);
                vm.setPrimaryPoolUuid(vol.getDataStore().getUuid());
                LOGGER.debug("Adding root disk: " + diskFile);
            } else if (disk.getType() == Volume.Type.ISO) {
                DataTO isoTO = disk.getData();
                if (isoTO.getPath() != null) {
                    TemplateObjectTO template = (TemplateObjectTO) isoTO;
                    DataStoreTO store = template.getDataStore();
                    if (!(store instanceof NfsTO)) {
                        throw new CloudRuntimeException("unsupported protocol");
                    }
                    NfsTO nfsStore = (NfsTO) store;
                    String secPoolUuid = pool.setupSecondaryStorage(nfsStore.getUrl());
                    String isoPath = config.getAgentSecStoragePath() + "/" + secPoolUuid + "/" + template.getPath();
                    vm.addIso(isoPath);
                    /* check if secondary storage is mounted */
                    LOGGER.debug("Adding ISO: " + isoPath);
                }
            } else if (disk.getType() == Volume.Type.DATADISK) {
                VolumeObjectTO vol = (VolumeObjectTO) disk.getData();
                String diskFile = processor.getVirtualDiskPath(vol.getUuid(), vol.getDataStore().getUuid());
                vm.addDataDisk(diskFile);
                LOGGER.debug("Adding data disk: " + diskFile);
            } else {
                throw new CloudRuntimeException("Unknown disk type: " + disk.getType());
            }
        } catch (Exception e) {
            LOGGER.debug("CreateVbds failed", e);
            throw new CloudRuntimeException("Exception" + e.getMessage(), e);
        }
    }
    return true;
}
Also used : DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DataTO(com.cloud.agent.api.to.DataTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) NfsTO(com.cloud.agent.api.to.NfsTO) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) DiskTO(com.cloud.agent.api.to.DiskTO)

Example 22 with TemplateObjectTO

use of org.apache.cloudstack.storage.to.TemplateObjectTO in project cloudstack by apache.

the class Ovm3StorageProcessorTest method deleteCommandTest.

/**
     * Delete an object
     *
     * @throws ConfigurationException
     */
@Test
public void deleteCommandTest() throws ConfigurationException {
    con = prepare();
    VolumeObjectTO vol = volume(ovmObject.newUuid(), ovmObject.newUuid(), linux.getRepoId(), linux.getVirtualDisksDir());
    DeleteCommand delete = new DeleteCommand(vol);
    Answer ra = hypervisor.executeRequest(delete);
    results.basicBooleanTest(ra.getResult());
    TemplateObjectTO template = template(ovmObject.newUuid(), ovmObject.newUuid(), ovmObject.newUuid(linux.getRemote()), linux.getRemote());
    delete = new DeleteCommand(template);
    ra = hypervisor.executeRequest(delete);
    results.basicBooleanTest(ra.getResult(), false);
    SnapshotObjectTO snap = snapshot(ovmObject.newUuid(), ovmObject.newUuid(), ovmObject.newUuid(linux.getRemote()), linux.getRemote());
    delete = new DeleteCommand(snap);
    ra = hypervisor.executeRequest(delete);
    results.basicBooleanTest(ra.getResult(), false);
}
Also used : DeleteCommand(org.apache.cloudstack.storage.command.DeleteCommand) SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) ConnectionTest(com.cloud.hypervisor.ovm3.objects.ConnectionTest) LinuxTest(com.cloud.hypervisor.ovm3.objects.LinuxTest) Test(org.junit.Test) XenTest(com.cloud.hypervisor.ovm3.objects.XenTest) StoragePluginTest(com.cloud.hypervisor.ovm3.objects.StoragePluginTest) Ovm3SupportTest(com.cloud.hypervisor.ovm3.support.Ovm3SupportTest) XmlTestResultTest(com.cloud.hypervisor.ovm3.objects.XmlTestResultTest) Ovm3ConfigurationTest(com.cloud.hypervisor.ovm3.resources.helpers.Ovm3ConfigurationTest)

Example 23 with TemplateObjectTO

use of org.apache.cloudstack.storage.to.TemplateObjectTO in project cloudstack by apache.

the class Ovm3StorageProcessorTest method createTemplateObjectCommandTest.

/*
     * unused ?
     *
     * @Test
     * public void createCommandTest() throws ConfigurationException {
     * con = prepare();
     * DiskProfile disk = diskProfile();
     * String templateUrl = null;
     * StoragePoolVO poolio = new StoragePoolVO();
     * poolio.setPath(linux.getTemplatesDir());
     * poolio.setHostAddress(linux.getRemoteHost());
     *
     * CreateCommand create = new CreateCommand(disk, templateUrl, poolio ,
     * false);
     * Answer ra = hypervisor.executeRequest(create);
     * results.basicBooleanTest(ra.getResult());
     * }
     */
@Test
public void createTemplateObjectCommandTest() throws ConfigurationException {
    con = prepare();
    String tempuuid = ovmObject.newUuid();
    TemplateObjectTO template = template(tempuuid, ovmObject.newUuid(), ovmObject.newUuid(linux.getRemote()), linux.getRemote());
    template.setSize(storageplugin.getFileSize());
    String response = storageplugin.getFileCreateXml().replace(storageplugin.getFileName(), tempuuid + ".raw");
    response = response.replace(storageplugin.getPoolUuid(), ovmObject.deDash(linux.getRepoId()));
    con.setMethodResponse("storage_plugin_create", results.simpleResponseWrapWrapper(response));
    CreateObjectCommand create = new CreateObjectCommand(template);
    Answer ra = hypervisor.executeRequest(create);
    results.basicBooleanTest(ra.getResult(), false);
}
Also used : Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) CreateObjectCommand(org.apache.cloudstack.storage.command.CreateObjectCommand) ConnectionTest(com.cloud.hypervisor.ovm3.objects.ConnectionTest) LinuxTest(com.cloud.hypervisor.ovm3.objects.LinuxTest) Test(org.junit.Test) XenTest(com.cloud.hypervisor.ovm3.objects.XenTest) StoragePluginTest(com.cloud.hypervisor.ovm3.objects.StoragePluginTest) Ovm3SupportTest(com.cloud.hypervisor.ovm3.support.Ovm3SupportTest) XmlTestResultTest(com.cloud.hypervisor.ovm3.objects.XmlTestResultTest) Ovm3ConfigurationTest(com.cloud.hypervisor.ovm3.resources.helpers.Ovm3ConfigurationTest)

Example 24 with TemplateObjectTO

use of org.apache.cloudstack.storage.to.TemplateObjectTO in project cloudstack by apache.

the class NfsSecondaryStorageResource method copySnapshotToTemplateFromNfsToNfsXenserver.

protected Answer copySnapshotToTemplateFromNfsToNfsXenserver(CopyCommand cmd, SnapshotObjectTO srcData, NfsTO srcDataStore, TemplateObjectTO destData, NfsTO destDataStore) {
    String srcMountPoint = getRootDir(srcDataStore.getUrl(), _nfsVersion);
    String snapshotPath = srcData.getPath();
    int index = snapshotPath.lastIndexOf("/");
    String snapshotName = snapshotPath.substring(index + 1);
    if (!snapshotName.startsWith("VHD-") && !snapshotName.endsWith(".vhd")) {
        snapshotName = snapshotName + ".vhd";
    }
    snapshotPath = snapshotPath.substring(0, index);
    snapshotPath = srcMountPoint + File.separator + snapshotPath;
    String destMountPoint = getRootDir(destDataStore.getUrl(), _nfsVersion);
    String destPath = destMountPoint + File.separator + destData.getPath();
    String errMsg = null;
    try {
        _storage.mkdir(destPath);
        String templateUuid = UUID.randomUUID().toString();
        String templateName = templateUuid + ".vhd";
        Script command = new Script(createTemplateFromSnapshotXenScript, cmd.getWait() * 1000, s_logger);
        command.add("-p", snapshotPath);
        command.add("-s", snapshotName);
        command.add("-n", templateName);
        command.add("-t", destPath);
        String result = command.execute();
        if (result != null && !result.equalsIgnoreCase("")) {
            return new CopyCmdAnswer(result);
        }
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(StorageLayer.InstanceConfigKey, _storage);
        Processor processor = new VhdProcessor();
        processor.configure("Vhd Processor", params);
        FormatInfo info = processor.process(destPath, null, templateUuid);
        TemplateLocation loc = new TemplateLocation(_storage, destPath);
        loc.create(1, true, templateUuid);
        loc.addFormat(info);
        loc.save();
        TemplateProp prop = loc.getTemplateInfo();
        TemplateObjectTO newTemplate = new TemplateObjectTO();
        newTemplate.setPath(destData.getPath() + File.separator + templateName);
        newTemplate.setFormat(ImageFormat.VHD);
        newTemplate.setSize(prop.getSize());
        newTemplate.setPhysicalSize(prop.getPhysicalSize());
        newTemplate.setName(templateUuid);
        return new CopyCmdAnswer(newTemplate);
    } catch (ConfigurationException e) {
        s_logger.debug("Failed to create template from snapshot: " + e.toString());
        errMsg = e.toString();
    } catch (InternalErrorException e) {
        s_logger.debug("Failed to create template from snapshot: " + e.toString());
        errMsg = e.toString();
    } catch (IOException e) {
        s_logger.debug("Failed to create template from snapshot: " + e.toString());
        errMsg = e.toString();
    }
    return new CopyCmdAnswer(errMsg);
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) Script(com.cloud.utils.script.Script) OVAProcessor(com.cloud.storage.template.OVAProcessor) VhdProcessor(com.cloud.storage.template.VhdProcessor) QCOW2Processor(com.cloud.storage.template.QCOW2Processor) TARProcessor(com.cloud.storage.template.TARProcessor) Processor(com.cloud.storage.template.Processor) VmdkProcessor(com.cloud.storage.template.VmdkProcessor) RawImageProcessor(com.cloud.storage.template.RawImageProcessor) HashMap(java.util.HashMap) InternalErrorException(com.cloud.exception.InternalErrorException) IOException(java.io.IOException) ConfigurationException(javax.naming.ConfigurationException) TemplateLocation(com.cloud.storage.template.TemplateLocation) VhdProcessor(com.cloud.storage.template.VhdProcessor) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) FormatInfo(com.cloud.storage.template.Processor.FormatInfo) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 25 with TemplateObjectTO

use of org.apache.cloudstack.storage.to.TemplateObjectTO in project cloudstack by apache.

the class NfsSecondaryStorageResource method copyFromNfsToS3.

protected Answer copyFromNfsToS3(CopyCommand cmd) {
    final DataTO srcData = cmd.getSrcTO();
    final DataTO destData = cmd.getDestTO();
    DataStoreTO srcDataStore = srcData.getDataStore();
    NfsTO srcStore = (NfsTO) srcDataStore;
    DataStoreTO destDataStore = destData.getDataStore();
    final S3TO s3 = (S3TO) destDataStore;
    try {
        final String templatePath = determineStorageTemplatePath(srcStore.getUrl(), srcData.getPath(), _nfsVersion);
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Found " + srcData.getObjectType() + " from directory " + templatePath + " to upload to S3.");
        }
        final String bucket = s3.getBucketName();
        File srcFile = findFile(templatePath);
        if (srcFile == null) {
            return new CopyCmdAnswer("Can't find src file:" + templatePath);
        }
        ImageFormat format = getTemplateFormat(srcFile.getName());
        String key = destData.getPath() + S3Utils.SEPARATOR + srcFile.getName();
        putFile(s3, srcFile, bucket, key).waitForCompletion();
        DataTO retObj = null;
        if (destData.getObjectType() == DataObjectType.TEMPLATE) {
            TemplateObjectTO newTemplate = new TemplateObjectTO();
            newTemplate.setPath(key);
            newTemplate.setSize(getVirtualSize(srcFile, format));
            newTemplate.setPhysicalSize(srcFile.length());
            newTemplate.setFormat(format);
            retObj = newTemplate;
        } else if (destData.getObjectType() == DataObjectType.VOLUME) {
            VolumeObjectTO newVol = new VolumeObjectTO();
            newVol.setPath(key);
            newVol.setSize(srcFile.length());
            retObj = newVol;
        } else if (destData.getObjectType() == DataObjectType.SNAPSHOT) {
            SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
            newSnapshot.setPath(key);
            retObj = newSnapshot;
        }
        return new CopyCmdAnswer(retObj);
    } catch (Exception e) {
        s_logger.error("failed to upload" + srcData.getPath(), e);
        return new CopyCmdAnswer("failed to upload" + srcData.getPath() + e.toString());
    }
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DataTO(com.cloud.agent.api.to.DataTO) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) NfsTO(com.cloud.agent.api.to.NfsTO) S3TO(com.cloud.agent.api.to.S3TO) File(java.io.File) S3Utils.putFile(com.cloud.utils.storage.S3.S3Utils.putFile) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) ImageFormat(com.cloud.storage.Storage.ImageFormat)

Aggregations

TemplateObjectTO (org.apache.cloudstack.storage.to.TemplateObjectTO)57 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)40 NfsTO (com.cloud.agent.api.to.NfsTO)34 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)28 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)26 DataTO (com.cloud.agent.api.to.DataTO)22 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)20 InternalErrorException (com.cloud.exception.InternalErrorException)19 PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)19 DiskTO (com.cloud.agent.api.to.DiskTO)13 XmlRpcException (org.apache.xmlrpc.XmlRpcException)12 XenAPIException (com.xensource.xenapi.Types.XenAPIException)11 SnapshotObjectTO (org.apache.cloudstack.storage.to.SnapshotObjectTO)11 Answer (com.cloud.agent.api.Answer)10 VDI (com.xensource.xenapi.VDI)10 Connection (com.xensource.xenapi.Connection)9 SR (com.xensource.xenapi.SR)9 URI (java.net.URI)9 ConfigurationException (javax.naming.ConfigurationException)9 IOException (java.io.IOException)8