use of com.cloud.hypervisor.ovm3.objects.StoragePlugin in project cloudstack by apache.
the class Ovm3StoragePool method execute.
/**
* Gets the details of a storage pool, size etc
*
* @param cmd
* @return
*/
public Answer execute(ModifyStoragePoolCommand cmd) {
StorageFilerTO pool = cmd.getPool();
LOGGER.debug("modifying pool " + pool);
try {
if (config.getAgentInOvm3Cluster()) {
// no native ovm cluster for now, I got to break it in horrible
// ways
}
if (pool.getType() == StoragePoolType.NetworkFilesystem) {
createRepo(pool);
StoragePlugin store = new StoragePlugin(c);
String propUuid = store.deDash(pool.getUuid());
String mntUuid = pool.getUuid();
String nfsHost = pool.getHost();
String nfsPath = pool.getPath();
StorageDetails ss = store.storagePluginGetFileSystemInfo(propUuid, mntUuid, nfsHost, nfsPath);
Map<String, TemplateProp> tInfo = new HashMap<String, TemplateProp>();
return new ModifyStoragePoolAnswer(cmd, Long.parseLong(ss.getSize()), Long.parseLong(ss.getFreeSize()), tInfo);
} else if (pool.getType() == StoragePoolType.OCFS2) {
createOCFS2Sr(pool);
}
return new Answer(cmd, false, "The pool type: " + pool.getType().name() + " is not supported.");
} catch (Exception e) {
LOGGER.debug("ModifyStoragePoolCommand failed", e);
return new Answer(cmd, false, e.getMessage());
}
}
use of com.cloud.hypervisor.ovm3.objects.StoragePlugin 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 in project cloudstack by apache.
the class Ovm3StoragePool method execute.
/**
* Gets statistics for storage.
*
* @param cmd
* @return
*/
public GetStorageStatsAnswer execute(final GetStorageStatsCommand cmd) {
LOGGER.debug("Getting stats for: " + cmd.getStorageId());
try {
Linux host = new Linux(c);
Linux.FileSystem fs = host.getFileSystemByUuid(cmd.getStorageId(), "nfs");
StoragePlugin store = new StoragePlugin(c);
String propUuid = store.deDash(cmd.getStorageId());
String mntUuid = cmd.getStorageId();
if (store == null || propUuid == null || mntUuid == null || fs == null) {
String msg = "Null returned when retrieving stats for " + cmd.getStorageId();
LOGGER.error(msg);
return new GetStorageStatsAnswer(cmd, msg);
}
/* or is it mntUuid ish ? */
StorageDetails sd = store.storagePluginGetFileSystemInfo(propUuid, mntUuid, fs.getHost(), fs.getDevice());
/*
* FIXME: cure me or kill me, this needs to trigger a reinit of
* primary storage, actually the problem is more deeprooted, as when
* the hypervisor reboots it looses partial context and needs to be
* reinitiated.... actually a full configure round... how to trigger
* that ?
*/
if ("".equals(sd.getSize())) {
String msg = "No size when retrieving stats for " + cmd.getStorageId();
LOGGER.debug(msg);
return new GetStorageStatsAnswer(cmd, msg);
}
long total = Long.parseLong(sd.getSize());
long used = total - Long.parseLong(sd.getFreeSize());
return new GetStorageStatsAnswer(cmd, total, used);
} catch (Ovm3ResourceException e) {
LOGGER.debug("GetStorageStatsCommand for " + cmd.getStorageId() + " failed", e);
return new GetStorageStatsAnswer(cmd, e.getMessage());
}
}
use of com.cloud.hypervisor.ovm3.objects.StoragePlugin 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 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());
}
}
Aggregations