use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.
the class Ovm3StorageProcessor method cloneVolumeFromBaseTemplate.
/**
* dest is VolumeObject, src is a template
*/
@Override
public CopyCmdAnswer cloneVolumeFromBaseTemplate(CopyCommand cmd) {
LOGGER.debug("execute cloneVolumeFromBaseTemplate: " + cmd.getClass());
try {
// src
DataTO srcData = cmd.getSrcTO();
TemplateObjectTO src = (TemplateObjectTO) srcData;
String srcFile = getVirtualDiskPath(src.getUuid(), src.getDataStore().getUuid());
srcFile = srcFile.replace(config.getVirtualDiskDir(), config.getTemplateDir());
DataTO destData = cmd.getDestTO();
VolumeObjectTO dest = (VolumeObjectTO) destData;
String destFile = getVirtualDiskPath(dest.getUuid(), dest.getDataStore().getUuid());
Linux host = new Linux(c);
LOGGER.debug("CopyFrom: " + srcData.getObjectType() + "," + srcFile + " to " + destData.getObjectType() + "," + destFile);
host.copyFile(srcFile, destFile);
VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setUuid(dest.getUuid());
// was destfile
newVol.setPath(dest.getUuid());
newVol.setFormat(ImageFormat.RAW);
return new CopyCmdAnswer(newVol);
} catch (Ovm3ResourceException e) {
String msg = "Error cloneVolumeFromBaseTemplate: " + e.getMessage();
LOGGER.info(msg);
return new CopyCmdAnswer(msg);
}
}
use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.
the class Ovm3StorageProcessor method createVolume.
/**
* Creates a volume, just a normal empty volume.
*/
@Override
public Answer createVolume(CreateObjectCommand cmd) {
LOGGER.debug("execute createVolume: " + cmd.getClass());
DataTO data = cmd.getData();
VolumeObjectTO volume = (VolumeObjectTO) data;
try {
/*
* public Boolean storagePluginCreate(String uuid, String ssuuid,
* String host, String file, Integer size)
*/
String poolUuid = data.getDataStore().getUuid();
String storeUrl = data.getDataStore().getUrl();
URI uri = new URI(storeUrl);
String host = uri.getHost();
String file = getVirtualDiskPath(volume.getUuid(), poolUuid);
Long size = volume.getSize();
StoragePlugin sp = new StoragePlugin(c);
FileProperties fp = sp.storagePluginCreate(poolUuid, host, file, size, false);
if (!fp.getName().equals(file)) {
return new CreateObjectAnswer("Filename mismatch: " + fp.getName() + " != " + file);
}
VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setName(volume.getName());
newVol.setSize(fp.getSize());
newVol.setPath(volume.getUuid());
return new CreateObjectAnswer(newVol);
} catch (Ovm3ResourceException | URISyntaxException e) {
LOGGER.info("Volume creation failed: " + e.toString(), e);
return new CreateObjectAnswer(e.toString());
}
}
use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.
the class Ovm3StorageProcessor method deleteSnapshot.
/**
* Is not used in normal operation, the SSVM takes care of this.
*/
@Override
public Answer deleteSnapshot(DeleteCommand cmd) {
LOGGER.debug("execute deleteSnapshot: " + cmd.getClass());
DataTO data = cmd.getData();
SnapshotObjectTO snap = (SnapshotObjectTO) data;
String storeUrl = data.getDataStore().getUrl();
String snapUuid = snap.getPath();
try {
// snapshots/accountid/volumeid
String secPoolUuid = pool.setupSecondaryStorage(storeUrl);
String filePath = config.getAgentSecStoragePath() + "/" + secPoolUuid + "/" + snapUuid + ".raw";
StoragePlugin sp = new StoragePlugin(c);
sp.storagePluginDestroy(secPoolUuid, filePath);
LOGGER.debug("Snapshot deletion success: " + filePath);
return new Answer(cmd, true, "Deleted Snapshot " + filePath);
} catch (Ovm3ResourceException e) {
LOGGER.info("Snapshot deletion failed: " + e.toString(), e);
return new CreateObjectAnswer(e.toString());
}
}
use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.
the class Ovm3StorageProcessor method copyTemplateToPrimaryStorage.
/**
* src is Nfs and Template from secondary storage to primary
*/
@Override
public CopyCmdAnswer copyTemplateToPrimaryStorage(CopyCommand cmd) {
LOGGER.debug("execute copyTemplateToPrimaryStorage: " + cmd.getClass());
DataTO srcData = cmd.getSrcTO();
DataStoreTO srcStore = srcData.getDataStore();
DataTO destData = cmd.getDestTO();
NfsTO srcImageStore = (NfsTO) srcStore;
TemplateObjectTO destTemplate = (TemplateObjectTO) destData;
try {
String secPoolUuid = pool.setupSecondaryStorage(srcImageStore.getUrl());
String primaryPoolUuid = destData.getDataStore().getUuid();
String destPath = config.getAgentOvmRepoPath() + "/" + ovmObject.deDash(primaryPoolUuid) + "/" + config.getTemplateDir();
String sourcePath = config.getAgentSecStoragePath() + "/" + secPoolUuid;
Linux host = new Linux(c);
String destUuid = destTemplate.getUuid();
/*
* Would love to add dynamic formats (tolower), to also support
* VHD and QCOW2, although Ovm3.2 does not have tapdisk2 anymore
* so we can forget about that.
*/
/* TODO: add checksumming */
String srcFile = sourcePath + "/" + srcData.getPath();
if (srcData.getPath().endsWith("/")) {
srcFile = sourcePath + "/" + srcData.getPath() + "/" + destUuid + ".raw";
}
String destFile = destPath + "/" + destUuid + ".raw";
LOGGER.debug("CopyFrom: " + srcData.getObjectType() + "," + srcFile + " to " + destData.getObjectType() + "," + destFile);
host.copyFile(srcFile, destFile);
TemplateObjectTO newVol = new TemplateObjectTO();
newVol.setUuid(destUuid);
// was destfile
newVol.setPath(destUuid);
newVol.setFormat(ImageFormat.RAW);
return new CopyCmdAnswer(newVol);
} catch (Ovm3ResourceException e) {
String msg = "Error while copying template to primary storage: " + e.getMessage();
LOGGER.info(msg);
return new CopyCmdAnswer(msg);
}
}
use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.
the class Ovm3HypervisorSupport method execute.
/**
* CheckHealthAnwer: Check the health of an agent on the hypervisor.
* TODO: should elaborate here with checks...
*
* @param cmd
* @return
*/
public CheckHealthAnswer execute(CheckHealthCommand cmd) {
Common test = new Common(c);
String ping = "put";
String pong;
try {
pong = test.echo(ping);
} catch (Ovm3ResourceException e) {
LOGGER.debug("CheckHealth went wrong: " + config.getAgentHostname() + ", " + e.getMessage(), e);
return new CheckHealthAnswer(cmd, false);
}
if (ping.contentEquals(pong)) {
return new CheckHealthAnswer(cmd, true);
}
LOGGER.debug("CheckHealth did not receive " + ping + " but got " + pong + " from " + config.getAgentHostname());
return new CheckHealthAnswer(cmd, false);
}
Aggregations