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