Search in sources :

Example 41 with NfsTO

use of com.cloud.agent.api.to.NfsTO in project cloudstack by apache.

the class MockStorageManagerImpl method ListTemplates.

@Override
public Answer ListTemplates(ListTemplateCommand cmd) {
    DataStoreTO store = cmd.getDataStore();
    if (!(store instanceof NfsTO)) {
        return new Answer(cmd, false, "Unsupported image data store: " + store);
    }
    MockSecStorageVO storage = null;
    String nfsUrl = ((NfsTO) store).getUrl();
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    storage = _mockSecStorageDao.findByUrl(nfsUrl);
    try {
        txn.start();
        List<MockVolumeVO> templates = _mockVolumeDao.findByStorageIdAndType(storage.getId(), MockVolumeType.TEMPLATE);
        Map<String, TemplateProp> templateInfos = new HashMap<String, TemplateProp>();
        for (MockVolumeVO template : templates) {
            templateInfos.put(template.getName(), new TemplateProp(template.getName(), template.getPath().replaceAll(storage.getMountPoint(), ""), template.getSize(), template.getSize(), true, false));
        }
        return new ListTemplateAnswer(nfsUrl, templateInfos);
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Error when finding template on sec storage " + storage.getId(), ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) HashMap(java.util.HashMap) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) NfsTO(com.cloud.agent.api.to.NfsTO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) Answer(com.cloud.agent.api.Answer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) ListTemplateAnswer(com.cloud.agent.api.storage.ListTemplateAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) GetVolumeStatsAnswer(com.cloud.agent.api.GetVolumeStatsAnswer) UploadStatusAnswer(org.apache.cloudstack.storage.command.UploadStatusAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) ListVolumeAnswer(com.cloud.agent.api.storage.ListVolumeAnswer) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ListTemplateAnswer(com.cloud.agent.api.storage.ListTemplateAnswer) MockVolumeVO(com.cloud.simulator.MockVolumeVO)

Example 42 with NfsTO

use of com.cloud.agent.api.to.NfsTO in project cloudstack by apache.

the class Ovm3HypervisorResourceTest method addDiskToSpec.

public void addDiskToSpec(VirtualMachineTO vmspec, String uuid, String dsuuid, String path) {
    ArrayList<DiskTO> disks;
    if (vmspec.getDisks() != null) {
        disks = new ArrayList<DiskTO>(Arrays.asList(vmspec.getDisks()));
    } else {
        disks = new ArrayList<DiskTO>();
    }
    DiskTO disk = new DiskTO();
    VolumeObjectTO volume = new VolumeObjectTO();
    NfsTO nfsDataStore = new NfsTO();
    nfsDataStore.setUuid(dsuuid);
    volume.setDataStore(nfsDataStore);
    volume.setPath(path);
    volume.setUuid(uuid);
    disk.setData(volume);
    disk.setType(Volume.Type.ROOT);
    disks.add(disk);
    vmspec.setDisks(disks.toArray(new DiskTO[disks.size()]));
}
Also used : VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) NfsTO(com.cloud.agent.api.to.NfsTO) DiskTO(com.cloud.agent.api.to.DiskTO)

Example 43 with NfsTO

use of com.cloud.agent.api.to.NfsTO in project cloudstack by apache.

the class TemplateManagerImpl method prepareIso.

// for ISO, we need to consider whether to copy to cache storage or not if it is not on NFS, since our hypervisor resource always assumes that they are in NFS
@Override
public TemplateInfo prepareIso(long isoId, long dcId, Long hostId, Long poolId) {
    TemplateInfo tmplt;
    boolean bypassed = false;
    if (_tmplFactory.isTemplateMarkedForDirectDownload(isoId)) {
        tmplt = _tmplFactory.getReadyBypassedTemplateOnPrimaryStore(isoId, poolId, hostId);
        bypassed = true;
    } else {
        tmplt = _tmplFactory.getTemplate(isoId, DataStoreRole.Image, dcId);
    }
    if (tmplt == null || tmplt.getFormat() != ImageFormat.ISO) {
        s_logger.warn("ISO: " + isoId + " does not exist in vm_template table");
        return null;
    }
    if (!bypassed && tmplt.getDataStore() != null && !(tmplt.getDataStore().getTO() instanceof NfsTO)) {
        // if it is s3, need to download into cache storage first
        Scope destScope = new ZoneScope(dcId);
        TemplateInfo cacheData = (TemplateInfo) cacheMgr.createCacheObject(tmplt, destScope);
        if (cacheData == null) {
            s_logger.error("Failed in copy iso from S3 to cache storage");
            return null;
        }
        return cacheData;
    } else {
        return tmplt;
    }
}
Also used : ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) Scope(org.apache.cloudstack.engine.subsystem.api.storage.Scope) ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) PublishScope(org.apache.cloudstack.framework.messagebus.PublishScope) NfsTO(com.cloud.agent.api.to.NfsTO)

Example 44 with NfsTO

use of com.cloud.agent.api.to.NfsTO in project cloudstack by apache.

the class NfsSecondaryStorageResource method execute.

public Answer execute(CreateDatadiskTemplateCommand cmd) {
    TemplateObjectTO diskTemplate = new TemplateObjectTO();
    TemplateObjectTO dataDiskTemplate = (TemplateObjectTO) cmd.getDataDiskTemplate();
    DataStoreTO dataStore = dataDiskTemplate.getDataStore();
    if (!(dataStore instanceof NfsTO)) {
        return new CreateDatadiskTemplateAnswer("Unsupported protocol");
    }
    NfsTO nfsImageStore = (NfsTO) dataStore;
    String secondaryStorageUrl = nfsImageStore.getUrl();
    assert (secondaryStorageUrl != null);
    try {
        String secondaryMountPoint = getRootDir(secondaryStorageUrl, _nfsVersion);
        long templateId = dataDiskTemplate.getId();
        String templateUniqueName = dataDiskTemplate.getUniqueName();
        String origDisk = cmd.getPath();
        long virtualSize = dataDiskTemplate.getSize();
        String diskName = origDisk.substring((origDisk.lastIndexOf(File.separator)) + 1);
        long physicalSize = new File(origDisk).length();
        String newTmplDir = getTemplateRelativeDirInSecStorage(dataDiskTemplate.getAccountId(), dataDiskTemplate.getId());
        String newTmplDirAbsolute = secondaryMountPoint + File.separator + newTmplDir;
        String ovfFilePath = getOVFFilePath(origDisk);
        if (!cmd.getBootable()) {
            // Create folder to hold datadisk template
            synchronized (newTmplDir.intern()) {
                Script command = new Script("mkdir", _timeout, s_logger);
                command.add("-p");
                command.add(newTmplDirAbsolute);
                String result = command.execute();
                if (result != null) {
                    String msg = "Unable to prepare template directory: " + newTmplDir + ", storage: " + secondaryStorageUrl + ", error msg: " + result;
                    s_logger.error(msg);
                    throw new Exception(msg);
                }
            }
            // Move Datadisk VMDK from parent template folder to Datadisk template folder
            synchronized (origDisk.intern()) {
                Script command = new Script("mv", _timeout, s_logger);
                command.add(origDisk);
                command.add(newTmplDirAbsolute);
                String result = command.execute();
                if (result != null) {
                    String msg = "Unable to copy VMDK from parent template folder to datadisk template folder" + ", error msg: " + result;
                    s_logger.error(msg);
                    throw new Exception(msg);
                }
                command = new Script("cp", _timeout, s_logger);
                command.add(ovfFilePath + ORIGINAL_FILE_EXTENSION);
                command.add(newTmplDirAbsolute);
                result = command.execute();
                if (result != null) {
                    String msg = "Unable to copy VMDK from parent template folder to datadisk template folder" + ", error msg: " + result;
                    s_logger.error(msg);
                    throw new Exception(msg);
                }
            }
        }
        // Create OVF for the disk
        String newOvfFilePath = newTmplDirAbsolute + File.separator + ovfFilePath.substring(ovfFilePath.lastIndexOf(File.separator) + 1);
        OVFHelper ovfHelper = new OVFHelper();
        ovfHelper.rewriteOVFFileForSingleDisk(ovfFilePath + ORIGINAL_FILE_EXTENSION, newOvfFilePath, diskName);
        postCreatePrivateTemplate(newTmplDirAbsolute, templateId, templateUniqueName, physicalSize, virtualSize);
        writeMetaOvaForTemplate(newTmplDirAbsolute, ovfFilePath.substring(ovfFilePath.lastIndexOf(File.separator) + 1), diskName, templateUniqueName, physicalSize);
        diskTemplate.setId(templateId);
        if (diskName.endsWith("iso")) {
            diskTemplate.setPath(newTmplDir + File.separator + diskName);
        } else {
            diskTemplate.setPath(newTmplDir + File.separator + templateUniqueName + ".ova");
        }
        diskTemplate.setSize(virtualSize);
        diskTemplate.setPhysicalSize(physicalSize);
    } catch (Exception e) {
        String msg = "Create Datadisk template failed due to " + e.getMessage();
        s_logger.error(msg, e);
        return new CreateDatadiskTemplateAnswer(msg);
    }
    return new CreateDatadiskTemplateAnswer(diskTemplate);
}
Also used : Script(com.cloud.utils.script.Script) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) CreateDatadiskTemplateAnswer(com.cloud.agent.api.storage.CreateDatadiskTemplateAnswer) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) OVFHelper(com.cloud.agent.api.storage.OVFHelper) NfsTO(com.cloud.agent.api.to.NfsTO) File(java.io.File) S3Utils.putFile(com.cloud.utils.storage.S3.S3Utils.putFile) 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)

Example 45 with NfsTO

use of com.cloud.agent.api.to.NfsTO in project cloudstack by apache.

the class SecondaryStorageManagerImpl method generateSetupCommand.

@Override
public boolean generateSetupCommand(Long ssHostId) {
    HostVO cssHost = _hostDao.findById(ssHostId);
    Long zoneId = cssHost.getDataCenterId();
    if (cssHost.getType() == Host.Type.SecondaryStorageVM) {
        String hostName = cssHost.getName();
        SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findByInstanceName(hostName);
        if (secStorageVm == null) {
            s_logger.warn(String.format("Secondary storage VM [%s] does not exist.", hostName));
            return false;
        }
        List<DataStore> ssStores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId));
        for (DataStore ssStore : ssStores) {
            if (!(ssStore.getTO() instanceof NfsTO)) {
                continue;
            }
            String secUrl = ssStore.getUri();
            SecStorageSetupCommand setupCmd = null;
            if (!_useSSlCopy) {
                setupCmd = new SecStorageSetupCommand(ssStore.getTO(), secUrl, null);
            } else {
                KeystoreManager.Certificates certs = _keystoreMgr.getCertificates(ConsoleProxyManager.CERTIFICATE_NAME);
                setupCmd = new SecStorageSetupCommand(ssStore.getTO(), secUrl, certs);
            }
            String nfsVersion = imageStoreDetailsUtil.getNfsVersion(ssStore.getId());
            setupCmd.setNfsVersion(nfsVersion);
            String postUploadKey = _configDao.getValue(Config.SSVMPSK.key());
            setupCmd.setPostUploadKey(postUploadKey);
            Answer answer = _agentMgr.easySend(ssHostId, setupCmd);
            if (answer != null && answer.getResult()) {
                SecStorageSetupAnswer an = (SecStorageSetupAnswer) answer;
                if (an.get_dir() != null) {
                    ImageStoreVO svo = _imageStoreDao.findById(ssStore.getId());
                    svo.setParent(an.get_dir());
                    _imageStoreDao.update(ssStore.getId(), svo);
                }
                s_logger.debug(String.format("Successfully programmed secondary storage [%s] in secondary storage VM [%s].", ssStore.getName(), secStorageVm.getInstanceName()));
            } else {
                s_logger.debug(String.format("Unable to program secondary storage [%s] in secondary storage VM [%s] due to [%s].", ssStore.getName(), secStorageVm.getInstanceName(), answer == null ? "null answer" : answer.getDetails()));
                return false;
            }
        }
    }
    return true;
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) KeystoreManager(org.apache.cloudstack.framework.security.keystore.KeystoreManager) SecStorageSetupCommand(com.cloud.agent.api.SecStorageSetupCommand) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) NfsTO(com.cloud.agent.api.to.NfsTO) HostVO(com.cloud.host.HostVO) ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) Answer(com.cloud.agent.api.Answer) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO)

Aggregations

NfsTO (com.cloud.agent.api.to.NfsTO)142 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)110 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)79 DataTO (com.cloud.agent.api.to.DataTO)71 InternalErrorException (com.cloud.exception.InternalErrorException)58 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)52 PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)39 TemplateObjectTO (org.apache.cloudstack.storage.to.TemplateObjectTO)38 XmlRpcException (org.apache.xmlrpc.XmlRpcException)37 XenAPIException (com.xensource.xenapi.Types.XenAPIException)36 URI (java.net.URI)36 Connection (com.xensource.xenapi.Connection)34 SR (com.xensource.xenapi.SR)34 VDI (com.xensource.xenapi.VDI)34 CopyCmdAnswer (com.cloud.storage.command.CopyCmdAnswer)32 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)32 Answer (com.cloud.agent.api.Answer)29 IOException (java.io.IOException)28 File (java.io.File)27 PrimaryDataStoreTO (com.cloud.storage.to.PrimaryDataStoreTO)26