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