use of com.cloud.agent.api.storage.GetDatadisksAnswer in project cloudstack by apache.
the class NfsSecondaryStorageResource method execute.
public Answer execute(GetDatadisksCommand cmd) {
DataTO srcData = cmd.getData();
String configurationId = cmd.getConfigurationId();
TemplateObjectTO template = (TemplateObjectTO) srcData;
DataStoreTO srcStore = srcData.getDataStore();
if (!(srcStore instanceof NfsTO)) {
return new CreateDatadiskTemplateAnswer("Unsupported protocol");
}
NfsTO nfsImageStore = (NfsTO) srcStore;
String secondaryStorageUrl = nfsImageStore.getUrl();
assert (secondaryStorageUrl != null);
String templateUrl = secondaryStorageUrl + File.separator + srcData.getPath();
Pair<String, String> templateInfo = decodeTemplateRelativePathAndNameFromUrl(secondaryStorageUrl, templateUrl, template.getName());
String templateRelativeFolderPath = templateInfo.first();
try {
String secondaryMountPoint = getRootDir(secondaryStorageUrl, _nfsVersion);
s_logger.info("MDOVE Secondary storage mount point: " + secondaryMountPoint);
String srcOVAFileName = getTemplateOnSecStorageFilePath(secondaryMountPoint, templateRelativeFolderPath, templateInfo.second(), ImageFormat.OVA.getFileExtension());
String ovfFilePath = getOVFFilePath(srcOVAFileName);
if (ovfFilePath == null) {
Script command = new Script("tar", 0, s_logger);
command.add("--no-same-owner");
command.add("--no-same-permissions");
command.add("-xf", srcOVAFileName);
command.setWorkDir(secondaryMountPoint + File.separator + templateRelativeFolderPath);
s_logger.info("Executing command: " + command.toString());
String result = command.execute();
if (result != null) {
String msg = "Unable to unpack snapshot OVA file at: " + srcOVAFileName;
s_logger.error(msg);
throw new Exception(msg);
}
command = new Script("chmod", 0, s_logger);
command.add("-R");
command.add("666", secondaryMountPoint + File.separator + templateRelativeFolderPath);
result = command.execute();
if (result != null) {
s_logger.warn("Unable to set permissions for " + secondaryMountPoint + File.separator + templateRelativeFolderPath + " due to " + result);
}
}
Script command = new Script("cp", _timeout, s_logger);
command.add(ovfFilePath);
command.add(ovfFilePath + ORIGINAL_FILE_EXTENSION);
String result = command.execute();
if (result != null) {
String msg = "Unable to rename original OVF, error msg: " + result;
s_logger.error(msg);
}
s_logger.debug("Reading OVF " + ovfFilePath + " to retrive the number of disks present in OVA");
OVFHelper ovfHelper = new OVFHelper();
List<DatadiskTO> disks = ovfHelper.getOVFVolumeInfoFromFile(ovfFilePath, configurationId);
return new GetDatadisksAnswer(disks);
} catch (Exception e) {
String msg = "Get Datadisk Template Count failed due to " + e.getMessage();
s_logger.error(msg, e);
return new GetDatadisksAnswer(msg);
}
}
use of com.cloud.agent.api.storage.GetDatadisksAnswer in project cloudstack by apache.
the class BaseImageStoreDriverImpl method getDataDiskTemplates.
@Override
public List<DatadiskTO> getDataDiskTemplates(DataObject obj, String configurationId) {
List<DatadiskTO> dataDiskDetails = new ArrayList<DatadiskTO>();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Get the data disks present in the OVA template");
}
DataStore store = obj.getDataStore();
GetDatadisksCommand cmd = new GetDatadisksCommand(obj.getTO(), configurationId);
EndPoint ep = _defaultEpSelector.select(store);
Answer answer = null;
if (ep == null) {
String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
LOGGER.error(errMsg);
answer = new Answer(cmd, false, errMsg);
} else {
answer = ep.sendMessage(cmd);
}
if (answer != null && answer.getResult()) {
GetDatadisksAnswer getDatadisksAnswer = (GetDatadisksAnswer) answer;
// Details - Disk path, virtual size
dataDiskDetails = getDatadisksAnswer.getDataDiskDetails();
} else {
throw new CloudRuntimeException("Get Data disk command failed " + answer.getDetails());
}
return dataDiskDetails;
}
Aggregations