Search in sources :

Example 1 with ListTemplateAnswer

use of com.cloud.agent.api.storage.ListTemplateAnswer in project cosmic by MissionCriticalCloud.

the class NfsSecondaryStorageResource method execute.

private Answer execute(final ListTemplateCommand cmd) {
    if (!_inSystemVM) {
        return new ListTemplateAnswer(null, null);
    }
    final DataStoreTO store = cmd.getDataStore();
    if (store instanceof NfsTO) {
        final NfsTO nfs = (NfsTO) store;
        final String secUrl = nfs.getUrl();
        final String root = getRootDir(secUrl);
        final Map<String, TemplateProp> templateInfos = _dlMgr.gatherTemplateInfo(root);
        return new ListTemplateAnswer(secUrl, templateInfos);
    } else {
        return new Answer(cmd, false, "Unsupported image data store: " + store);
    }
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) ListTemplateAnswer(com.cloud.agent.api.storage.ListTemplateAnswer) UploadStatusAnswer(com.cloud.storage.command.UploadStatusAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer) ListVolumeAnswer(com.cloud.agent.api.storage.ListVolumeAnswer) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) Answer(com.cloud.agent.api.Answer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) ListTemplateAnswer(com.cloud.agent.api.storage.ListTemplateAnswer) NfsTO(com.cloud.agent.api.to.NfsTO)

Example 2 with ListTemplateAnswer

use of com.cloud.agent.api.storage.ListTemplateAnswer 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 3 with ListTemplateAnswer

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

the class NfsSecondaryStorageResource method execute.

private Answer execute(ListTemplateCommand cmd) {
    if (!_inSystemVM) {
        return new ListTemplateAnswer(null, null);
    }
    DataStoreTO store = cmd.getDataStore();
    if (store instanceof NfsTO) {
        NfsTO nfs = (NfsTO) store;
        String secUrl = nfs.getUrl();
        String root = getRootDir(secUrl, cmd.getNfsVersion());
        Map<String, TemplateProp> templateInfos = _dlMgr.gatherTemplateInfo(root);
        return new ListTemplateAnswer(secUrl, templateInfos);
    } else if (store instanceof SwiftTO) {
        SwiftTO swift = (SwiftTO) store;
        Map<String, TemplateProp> templateInfos = swiftListTemplate(swift);
        return new ListTemplateAnswer(swift.toString(), templateInfos);
    } else if (store instanceof S3TO) {
        S3TO s3 = (S3TO) store;
        Map<String, TemplateProp> templateInfos = s3ListTemplate(s3);
        return new ListTemplateAnswer(s3.getBucketName(), templateInfos);
    } else {
        return new Answer(cmd, false, "Unsupported image data store: " + store);
    }
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) GetDatadisksAnswer(com.cloud.agent.api.storage.GetDatadisksAnswer) CreateDatadiskTemplateAnswer(com.cloud.agent.api.storage.CreateDatadiskTemplateAnswer) ListTemplateAnswer(com.cloud.agent.api.storage.ListTemplateAnswer) HandleConfigDriveIsoAnswer(com.cloud.agent.api.HandleConfigDriveIsoAnswer) UploadStatusAnswer(org.apache.cloudstack.storage.command.UploadStatusAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) ListVolumeAnswer(com.cloud.agent.api.storage.ListVolumeAnswer) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) Answer(com.cloud.agent.api.Answer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) SwiftTO(com.cloud.agent.api.to.SwiftTO) ListTemplateAnswer(com.cloud.agent.api.storage.ListTemplateAnswer) NfsTO(com.cloud.agent.api.to.NfsTO) Map(java.util.Map) HashMap(java.util.HashMap) S3TO(com.cloud.agent.api.to.S3TO)

Example 4 with ListTemplateAnswer

use of com.cloud.agent.api.storage.ListTemplateAnswer in project cosmic by MissionCriticalCloud.

the class TemplateServiceImpl method listTemplate.

private Map<String, TemplateProp> listTemplate(final DataStore ssStore) {
    final ListTemplateCommand cmd = new ListTemplateCommand(ssStore.getTO());
    final EndPoint ep = _epSelector.select(ssStore);
    Answer answer = null;
    if (ep == null) {
        final String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
        s_logger.error(errMsg);
        answer = new Answer(cmd, false, errMsg);
    } else {
        answer = ep.sendMessage(cmd);
    }
    if (answer != null && answer.getResult()) {
        final ListTemplateAnswer tanswer = (ListTemplateAnswer) answer;
        return tanswer.getTemplateInfo();
    } else {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("can not list template for secondary storage host " + ssStore.getId());
        }
    }
    return null;
}
Also used : Answer(com.cloud.agent.api.Answer) ListTemplateAnswer(com.cloud.agent.api.storage.ListTemplateAnswer) ListTemplateAnswer(com.cloud.agent.api.storage.ListTemplateAnswer) ListTemplateCommand(com.cloud.agent.api.storage.ListTemplateCommand) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint)

Example 5 with ListTemplateAnswer

use of com.cloud.agent.api.storage.ListTemplateAnswer in project CloudStack-archive by CloudStack-extras.

the class MockStorageManagerImpl method ListTemplates.

@Override
public Answer ListTemplates(ListTemplateCommand cmd) {
    MockSecStorageVO storage = _mockSecStorageDao.findByUrl(cmd.getSecUrl());
    if (storage == null) {
        return new Answer(cmd, false, "Failed to get secondary storage");
    }
    List<MockVolumeVO> templates = _mockVolumeDao.findByStorageIdAndType(storage.getId(), MockVolumeType.TEMPLATE);
    Map<String, TemplateInfo> templateInfos = new HashMap<String, TemplateInfo>();
    for (MockVolumeVO template : templates) {
        templateInfos.put(template.getName(), new TemplateInfo(template.getName(), template.getPath().replaceAll(storage.getMountPoint(), ""), template.getSize(), template.getSize(), true, false));
    }
    return new ListTemplateAnswer(cmd.getSecUrl(), templateInfos);
}
Also used : 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) AttachVolumeAnswer(com.cloud.agent.api.AttachVolumeAnswer) 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) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) TemplateInfo(com.cloud.storage.template.TemplateInfo) HashMap(java.util.HashMap) ListTemplateAnswer(com.cloud.agent.api.storage.ListTemplateAnswer) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) MockVolumeVO(com.cloud.simulator.MockVolumeVO)

Aggregations

ListTemplateAnswer (com.cloud.agent.api.storage.ListTemplateAnswer)7 Answer (com.cloud.agent.api.Answer)6 DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)5 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)4 SecStorageSetupAnswer (com.cloud.agent.api.SecStorageSetupAnswer)4 NfsTO (com.cloud.agent.api.to.NfsTO)4 ListTemplateCommand (com.cloud.agent.api.storage.ListTemplateCommand)3 ListVolumeAnswer (com.cloud.agent.api.storage.ListVolumeAnswer)3 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)3 TemplateProp (com.cloud.storage.template.TemplateProp)3 HashMap (java.util.HashMap)3 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)2 CheckHealthAnswer (com.cloud.agent.api.CheckHealthAnswer)2 CreateVolumeFromSnapshotAnswer (com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)2 ManageSnapshotAnswer (com.cloud.agent.api.ManageSnapshotAnswer)2 ModifyStoragePoolAnswer (com.cloud.agent.api.ModifyStoragePoolAnswer)2 ReadyAnswer (com.cloud.agent.api.ReadyAnswer)2 CopyVolumeAnswer (com.cloud.agent.api.storage.CopyVolumeAnswer)2 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)2 CreatePrivateTemplateAnswer (com.cloud.agent.api.storage.CreatePrivateTemplateAnswer)2