Search in sources :

Example 1 with GetDatadisksAnswer

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);
    }
}
Also used : Script(com.cloud.utils.script.Script) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) GetDatadisksAnswer(com.cloud.agent.api.storage.GetDatadisksAnswer) NfsTO(com.cloud.agent.api.to.NfsTO) 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) DataTO(com.cloud.agent.api.to.DataTO) DatadiskTO(com.cloud.agent.api.to.DatadiskTO) CreateDatadiskTemplateAnswer(com.cloud.agent.api.storage.CreateDatadiskTemplateAnswer) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) OVFHelper(com.cloud.agent.api.storage.OVFHelper)

Example 2 with GetDatadisksAnswer

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;
}
Also used : GetDatadisksAnswer(com.cloud.agent.api.storage.GetDatadisksAnswer) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) Answer(com.cloud.agent.api.Answer) DatadiskTO(com.cloud.agent.api.to.DatadiskTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) GetDatadisksCommand(com.cloud.agent.api.storage.GetDatadisksCommand) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) GetDatadisksAnswer(com.cloud.agent.api.storage.GetDatadisksAnswer)

Aggregations

GetDatadisksAnswer (com.cloud.agent.api.storage.GetDatadisksAnswer)2 DatadiskTO (com.cloud.agent.api.to.DatadiskTO)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 Answer (com.cloud.agent.api.Answer)1 CreateDatadiskTemplateAnswer (com.cloud.agent.api.storage.CreateDatadiskTemplateAnswer)1 DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)1 GetDatadisksCommand (com.cloud.agent.api.storage.GetDatadisksCommand)1 OVFHelper (com.cloud.agent.api.storage.OVFHelper)1 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)1 DataTO (com.cloud.agent.api.to.DataTO)1 NfsTO (com.cloud.agent.api.to.NfsTO)1 InternalErrorException (com.cloud.exception.InternalErrorException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 Script (com.cloud.utils.script.Script)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 UnknownHostException (java.net.UnknownHostException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1 ConfigurationException (javax.naming.ConfigurationException)1