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);
}
}
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();
}
}
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);
}
}
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;
}
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);
}
Aggregations