use of com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties in project cloudstack by apache.
the class Ovm3StoragePool method prepareSecondaryStorageStore.
/**
* Copy the systemvm.iso in if it doesn't exist or the size differs.
*
* @param storageUrl
* @param poolUuid
* @param host
*/
private void prepareSecondaryStorageStore(String storageUrl, String poolUuid, String host) {
String mountPoint = storageUrl;
GlobalLock lock = GlobalLock.getInternLock("prepare.systemvm");
try {
/* double check */
if (config.getAgentHasMaster() && config.getAgentInOvm3Pool()) {
LOGGER.debug("Skip systemvm iso copy, leave it to the master");
return;
}
if (lock.lock(3600)) {
try {
/*
* save src iso real name for reuse, so we don't depend on
* other happy little accidents.
*/
File srcIso = getSystemVMPatchIsoFile();
String destPath = mountPoint + "/ISOs/";
try {
StoragePlugin sp = new StoragePlugin(c);
FileProperties fp = sp.storagePluginGetFileInfo(poolUuid, host, destPath + "/" + srcIso.getName());
if (fp.getSize() != srcIso.getTotalSpace()) {
LOGGER.info(" System VM patch ISO file already exists: " + srcIso.getAbsolutePath().toString() + ", destination: " + destPath);
}
} catch (Exception e) {
LOGGER.info("Copy System VM patch ISO file to secondary storage. source ISO: " + srcIso.getAbsolutePath() + ", destination: " + destPath);
try {
/* Perhaps use a key instead ? */
SshHelper.scpTo(c.getIp(), 22, config.getAgentSshUserName(), null, config.getAgentSshPassword(), destPath, srcIso.getAbsolutePath().toString(), "0644");
} catch (Exception es) {
LOGGER.error("Unexpected exception ", es);
String msg = "Unable to copy systemvm ISO on secondary storage. src location: " + srcIso.toString() + ", dest location: " + destPath;
LOGGER.error(msg);
throw new CloudRuntimeException(msg, es);
}
}
} finally {
lock.unlock();
}
}
} finally {
lock.releaseRef();
}
}
use of com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties 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.StoragePlugin.FileProperties in project cloudstack by apache.
the class StoragePluginTest method testStorageFileCreation.
@Test
public void testStorageFileCreation() throws Ovm3ResourceException {
con.setResult(results.simpleResponseWrapWrapper(FILECREATEXML));
FileProperties file = sPt.storagePluginCreate(FSMNTUUID, NFSHOST, FILE, SIZE, false);
file.getOnDiskSize();
}
use of com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties in project cloudstack by apache.
the class Ovm3StorageProcessor method execute.
public CreateAnswer execute(CreateCommand cmd) {
LOGGER.debug("execute: " + cmd.getClass());
StorageFilerTO primaryStorage = cmd.getPool();
DiskProfile disk = cmd.getDiskCharacteristics();
/* disk should have a uuid */
// should also be replaced with getVirtualDiskPath ?
String fileName = UUID.randomUUID().toString() + ".raw";
String dst = primaryStorage.getPath() + "/" + primaryStorage.getUuid() + "/" + fileName;
try {
StoragePlugin store = new StoragePlugin(c);
if (cmd.getTemplateUrl() != null) {
LOGGER.debug("CreateCommand " + cmd.getTemplateUrl() + " " + dst);
Linux host = new Linux(c);
host.copyFile(cmd.getTemplateUrl(), dst);
} else {
/* this is a dup with the createVolume ? */
LOGGER.debug("CreateCommand " + dst);
store.storagePluginCreate(primaryStorage.getUuid(), primaryStorage.getHost(), dst, disk.getSize(), false);
}
FileProperties fp = store.storagePluginGetFileInfo(primaryStorage.getUuid(), primaryStorage.getHost(), dst);
VolumeTO volume = new VolumeTO(cmd.getVolumeId(), disk.getType(), primaryStorage.getType(), primaryStorage.getUuid(), primaryStorage.getPath(), fileName, fp.getName(), fp.getSize(), null);
return new CreateAnswer(cmd, volume);
} catch (Exception e) {
LOGGER.debug("CreateCommand failed", e);
return new CreateAnswer(cmd, e.getMessage());
}
}
use of com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties in project cloudstack by apache.
the class StoragePluginTest method testStorageFileCreationFileExistS.
@Test(expected = Ovm3ResourceException.class)
public void testStorageFileCreationFileExistS() throws Ovm3ResourceException {
con.setResult(results.errorResponseWrap("exceptions OSError:[Errno.17] File exists " + FILE));
FileProperties file = sPt.storagePluginCreate(FSMNTUUID, NFSHOST, FILE, SIZE, false);
file.getSize();
}
Aggregations