Search in sources :

Example 1 with SecStorageSetupAnswer

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

the class NfsSecondaryStorageResource method execute.

private Answer execute(final SecStorageSetupCommand cmd) {
    if (!_inSystemVM) {
        return new Answer(cmd, true, null);
    }
    Answer answer = null;
    final DataStoreTO dStore = cmd.getDataStore();
    if (dStore instanceof NfsTO) {
        final String secUrl = cmd.getSecUrl();
        try {
            final URI uri = new URI(secUrl);
            final String nfsHostIp = getUriHostIp(uri);
            addRouteToInternalIpOrCidr(_storageGateway, _storageIp, _storageNetmask, nfsHostIp);
            final String dir = mountUri(uri);
            configCerts(cmd.getCerts());
            nfsIps.add(nfsHostIp);
            answer = new SecStorageSetupAnswer(dir);
        } catch (final Exception e) {
            final String msg = "GetRootDir for " + secUrl + " failed due to " + e.toString();
            s_logger.error(msg);
            answer = new Answer(cmd, false, msg);
        }
    } else {
        answer = new Answer(cmd, true, null);
    }
    savePostUploadPSK(cmd.getPostUploadKey());
    startPostUploadServer();
    return answer;
}
Also used : 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) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) NfsTO(com.cloud.agent.api.to.NfsTO) URI(java.net.URI) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException)

Example 2 with SecStorageSetupAnswer

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

the class MockStorageManagerImpl method SecStorageSetup.

@Override
public Answer SecStorageSetup(SecStorageSetupCommand cmd) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    MockSecStorageVO storage = null;
    try {
        txn.start();
        storage = _mockSecStorageDao.findByUrl(cmd.getSecUrl());
        if (storage == null) {
            return new Answer(cmd, false, "can't find the storage");
        }
        txn.commit();
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Error when setting up sec storage" + cmd.getSecUrl(), ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    return new SecStorageSetupAnswer(storage.getMountPoint());
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) 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) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 3 with SecStorageSetupAnswer

use of com.cloud.agent.api.SecStorageSetupAnswer 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;
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) KeystoreManager(org.apache.cloudstack.framework.security.keystore.KeystoreManager) SecStorageSetupCommand(com.cloud.agent.api.SecStorageSetupCommand) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) NfsTO(com.cloud.agent.api.to.NfsTO) HostVO(com.cloud.host.HostVO) ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) Answer(com.cloud.agent.api.Answer) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO)

Example 4 with SecStorageSetupAnswer

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

the class SecondaryStorageManagerImpl method generateSetupCommand.

@Override
public boolean generateSetupCommand(final Long ssHostId) {
    final HostVO cssHost = _hostDao.findById(ssHostId);
    final Long zoneId = cssHost.getDataCenterId();
    if (cssHost.getType() == Host.Type.SecondaryStorageVM) {
        final SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findByInstanceName(cssHost.getName());
        if (secStorageVm == null) {
            logger.warn("secondary storage VM " + cssHost.getName() + " doesn't exist");
            return false;
        }
        final List<DataStore> ssStores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId));
        for (final DataStore ssStore : ssStores) {
            if (!(ssStore.getTO() instanceof NfsTO)) {
                // only do this for Nfs
                continue;
            }
            final String secUrl = ssStore.getUri();
            final SecStorageSetupCommand setupCmd;
            if (!_useSSlCopy) {
                setupCmd = new SecStorageSetupCommand(ssStore.getTO(), secUrl, null);
            } else {
                final KeystoreManager.Certificates certs = _keystoreMgr.getCertificates(ConsoleProxyManager.CERTIFICATE_NAME);
                setupCmd = new SecStorageSetupCommand(ssStore.getTO(), secUrl, certs);
            }
            // template/volume file upload key
            final String postUploadKey = _configDao.getValue(Config.SSVMPSK.key());
            setupCmd.setPostUploadKey(postUploadKey);
            final Answer answer = _agentMgr.easySend(ssHostId, setupCmd);
            if (answer != null && answer.getResult()) {
                final SecStorageSetupAnswer an = (SecStorageSetupAnswer) answer;
                if (an.get_dir() != null) {
                    // update the parent path in image_store table for this image store
                    final ImageStoreVO svo = _imageStoreDao.findById(ssStore.getId());
                    svo.setParent(an.get_dir());
                    _imageStoreDao.update(ssStore.getId(), svo);
                }
                logger.debug("Successfully programmed secondary storage " + ssStore.getName() + " in secondary storage VM " + secStorageVm.getInstanceName());
            } else {
                logger.debug("Successfully programmed secondary storage " + ssStore.getName() + " in secondary storage VM " + secStorageVm.getInstanceName());
                return false;
            }
        }
    }
    return true;
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) KeystoreManager(com.cloud.framework.security.keystore.KeystoreManager) SecStorageSetupCommand(com.cloud.agent.api.SecStorageSetupCommand) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) NfsTO(com.cloud.agent.api.to.NfsTO) HostVO(com.cloud.host.HostVO) ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) Answer(com.cloud.agent.api.Answer) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO)

Example 5 with SecStorageSetupAnswer

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

the class NfsSecondaryStorageResource method execute.

private Answer execute(SecStorageSetupCommand cmd) {
    if (!_inSystemVM) {
        return new Answer(cmd, true, null);
    }
    Answer answer = null;
    DataStoreTO dStore = cmd.getDataStore();
    if (dStore instanceof NfsTO) {
        String secUrl = cmd.getSecUrl();
        try {
            URI uri = new URI(secUrl);
            String nfsHostIp = getUriHostIp(uri);
            addRouteToInternalIpOrCidr(_storageGateway, _storageIp, _storageNetmask, nfsHostIp);
            String dir = mountUri(uri, cmd.getNfsVersion());
            configCerts(cmd.getCerts());
            nfsIps.add(nfsHostIp);
            answer = new SecStorageSetupAnswer(dir);
        } catch (Exception e) {
            String msg = "GetRootDir for " + secUrl + " failed due to " + e.toString();
            s_logger.error(msg);
            answer = new Answer(cmd, false, msg);
        }
    } else {
        // TODO: what do we need to setup for S3/Swift, maybe need to mount
        // to some cache storage
        answer = new Answer(cmd, true, null);
    }
    savePostUploadPSK(cmd.getPostUploadKey());
    startPostUploadServer();
    return answer;
}
Also used : 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) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) NfsTO(com.cloud.agent.api.to.NfsTO) URI(java.net.URI) 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)

Aggregations

Answer (com.cloud.agent.api.Answer)5 SecStorageSetupAnswer (com.cloud.agent.api.SecStorageSetupAnswer)5 NfsTO (com.cloud.agent.api.to.NfsTO)4 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)3 DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)3 ListTemplateAnswer (com.cloud.agent.api.storage.ListTemplateAnswer)3 ListVolumeAnswer (com.cloud.agent.api.storage.ListVolumeAnswer)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 ConfigurationException (javax.naming.ConfigurationException)3 CheckHealthAnswer (com.cloud.agent.api.CheckHealthAnswer)2 ReadyAnswer (com.cloud.agent.api.ReadyAnswer)2 SecStorageSetupCommand (com.cloud.agent.api.SecStorageSetupCommand)2 CheckSshAnswer (com.cloud.agent.api.check.CheckSshAnswer)2 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)2 InternalErrorException (com.cloud.exception.InternalErrorException)2 HostVO (com.cloud.host.HostVO)2 SecondaryStorageVmVO (com.cloud.vm.SecondaryStorageVmVO)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2