use of com.cloud.agent.api.to.NfsTO in project cloudstack by apache.
the class VmwareStorageManagerImpl method createOvaForTemplate.
@Override
public String createOvaForTemplate(TemplateObjectTO template) {
DataStoreTO storeTO = template.getDataStore();
if (!(storeTO instanceof NfsTO)) {
s_logger.debug("Can only handle NFS storage, while creating OVA from template");
return null;
}
NfsTO nfsStore = (NfsTO) storeTO;
String secStorageUrl = nfsStore.getUrl();
assert (secStorageUrl != null);
String installPath = template.getPath();
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, _nfsVersion);
String installFullPath = secondaryMountPoint + "/" + installPath;
try {
if (installFullPath.endsWith(".ova")) {
if (new File(installFullPath).exists()) {
s_logger.debug("OVA file found at: " + installFullPath);
} else {
if (new File(installFullPath + ".meta").exists()) {
createOVAFromMetafile(installFullPath + ".meta");
} else {
String msg = "Unable to find OVA or OVA MetaFile to prepare template.";
s_logger.error(msg);
throw new Exception(msg);
}
}
return installPath;
}
} catch (Throwable e) {
s_logger.debug("Failed to create OVA: " + e.toString());
}
return null;
}
use of com.cloud.agent.api.to.NfsTO in project cosmic by MissionCriticalCloud.
the class NfsSecondaryStorageResource method deleteVolume.
protected Answer deleteVolume(final DeleteCommand cmd) {
final DataTO obj = cmd.getData();
final DataStoreTO dstore = obj.getDataStore();
if (dstore instanceof NfsTO) {
final NfsTO nfs = (NfsTO) dstore;
String relativeVolumePath = obj.getPath();
String parent = getRootDir(nfs.getUrl());
if (relativeVolumePath.startsWith(File.separator)) {
relativeVolumePath = relativeVolumePath.substring(1);
}
if (!parent.endsWith(File.separator)) {
parent += File.separator;
}
final String absoluteVolumePath = parent + relativeVolumePath;
final File volPath = new File(absoluteVolumePath);
File tmpltParent = null;
if (volPath.exists() && volPath.isDirectory()) {
// for vmware, absoluteVolumePath represents a directory where volume files are located.
tmpltParent = volPath;
} else {
// for other hypervisors, the volume .vhd or .qcow2 file path is passed
tmpltParent = new File(absoluteVolumePath).getParentFile();
}
String details = null;
if (!tmpltParent.exists()) {
details = "volume parent directory " + tmpltParent.getName() + " doesn't exist";
s_logger.debug(details);
return new Answer(cmd, true, details);
}
final File[] tmpltFiles = tmpltParent.listFiles();
if (tmpltFiles == null || tmpltFiles.length == 0) {
details = "No files under volume parent directory " + tmpltParent.getName();
s_logger.debug(details);
} else {
boolean found = false;
for (final File f : tmpltFiles) {
if (!found && f.getName().equals("volume.properties")) {
found = true;
}
// Don't let this stop us from cleaning up the template
if (f.isDirectory() && f.getName().equals("KVMHA")) {
s_logger.debug("Deleting KVMHA directory contents from template location");
final File[] haFiles = f.listFiles();
for (final File haFile : haFiles) {
haFile.delete();
}
}
if (!f.delete()) {
return new Answer(cmd, false, "Unable to delete file " + f.getName() + " under Volume path " + tmpltParent.getPath());
}
}
if (!found) {
details = "Can not find volume.properties under " + tmpltParent.getName();
s_logger.debug(details);
}
}
if (!tmpltParent.delete()) {
details = "Unable to delete directory " + tmpltParent.getName() + " under Volume path " + tmpltParent.getPath();
s_logger.debug(details);
return new Answer(cmd, false, details);
}
return new Answer(cmd, true, null);
} else {
return new Answer(cmd, false, "Unsupported image data store: " + dstore);
}
}
use of com.cloud.agent.api.to.NfsTO in project cosmic by MissionCriticalCloud.
the class NfsSecondaryStorageResource method deleteTemplate.
protected Answer deleteTemplate(final DeleteCommand cmd) {
final DataTO obj = cmd.getData();
final DataStoreTO dstore = obj.getDataStore();
if (dstore instanceof NfsTO) {
final NfsTO nfs = (NfsTO) dstore;
String relativeTemplatePath = obj.getPath();
String parent = getRootDir(nfs.getUrl());
if (relativeTemplatePath.startsWith(File.separator)) {
relativeTemplatePath = relativeTemplatePath.substring(1);
}
if (!parent.endsWith(File.separator)) {
parent += File.separator;
}
final String absoluteTemplatePath = parent + relativeTemplatePath;
final File tmpltPath = new File(absoluteTemplatePath);
File tmpltParent = null;
if (tmpltPath.exists() && tmpltPath.isDirectory()) {
tmpltParent = tmpltPath;
} else {
tmpltParent = tmpltPath.getParentFile();
}
String details = null;
if (!tmpltParent.exists()) {
details = "template parent directory " + tmpltParent.getName() + " doesn't exist";
s_logger.debug(details);
return new Answer(cmd, true, details);
}
final File[] tmpltFiles = tmpltParent.listFiles();
if (tmpltFiles == null || tmpltFiles.length == 0) {
details = "No files under template parent directory " + tmpltParent.getName();
s_logger.debug(details);
} else {
boolean found = false;
for (final File f : tmpltFiles) {
if (!found && f.getName().equals("template.properties")) {
found = true;
}
// Don't let this stop us from cleaning up the template
if (f.isDirectory() && f.getName().equals("KVMHA")) {
s_logger.debug("Deleting KVMHA directory contents from template location");
final File[] haFiles = f.listFiles();
for (final File haFile : haFiles) {
haFile.delete();
}
}
if (!f.delete()) {
return new Answer(cmd, false, "Unable to delete file " + f.getName() + " under Template path " + relativeTemplatePath);
}
}
if (!found) {
details = "Can not find template.properties under " + tmpltParent.getName();
s_logger.debug(details);
}
}
if (!tmpltParent.delete()) {
details = "Unable to delete directory " + tmpltParent.getName() + " under Template path " + relativeTemplatePath;
s_logger.debug(details);
return new Answer(cmd, false, details);
}
return new Answer(cmd, true, null);
} else {
return new Answer(cmd, false, "Unsupported image data store: " + dstore);
}
}
use of com.cloud.agent.api.to.NfsTO in project cosmic by MissionCriticalCloud.
the class NfsSecondaryStorageResource method execute.
private Answer execute(final ListTemplateCommand cmd) {
if (!_inSystemVM) {
return new ListTemplateAnswer(null, null);
}
final DataStoreTO store = cmd.getDataStore();
if (store instanceof NfsTO) {
final NfsTO nfs = (NfsTO) store;
final String secUrl = nfs.getUrl();
final String root = getRootDir(secUrl);
final Map<String, TemplateProp> templateInfos = _dlMgr.gatherTemplateInfo(root);
return new ListTemplateAnswer(secUrl, templateInfos);
} else {
return new Answer(cmd, false, "Unsupported image data store: " + store);
}
}
use of com.cloud.agent.api.to.NfsTO 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;
}
Aggregations