use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.
the class Ovm3HypervisorSupportTest method ReportedVmStatesTest.
@Test
public void ReportedVmStatesTest() throws ConfigurationException, Ovm3ResourceException {
Ovm3Configuration config = new Ovm3Configuration(configTest.getParams());
con.setResult(xen.getMultipleVmsListXML());
Ovm3HypervisorSupport hypervisor = new Ovm3HypervisorSupport(con, config);
hypervisor.vmStateMapClear();
State vmState = hypervisor.getVmState(vmName);
results.basicStringTest(vmState.toString(), State.Running.toString());
hypervisor.setVmStateStarting(vmName);
results.basicStringTest(hypervisor.getVmState(vmName).toString(), State.Starting.toString());
hypervisor.setVmState(vmName, State.Running);
results.basicStringTest(hypervisor.getVmState(vmName).toString(), State.Running.toString());
hypervisor.revmoveVmState(vmName);
assertNull(hypervisor.getVmState(vmName));
}
use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.
the class Ovm3StorageProcessor method attachDetach.
/**
* Generic disk attach/detach.
* @param cmd
* @param vmName
* @param disk
* @param isAttach
* @return
*/
private AttachAnswer attachDetach(Command cmd, String vmName, DiskTO disk, boolean isAttach) {
Xen xen = new Xen(c);
String doThis = (isAttach) ? "Attach" : "Dettach";
LOGGER.debug(doThis + " volume type " + disk.getType() + " " + vmName);
String msg = "";
String path = "";
try {
Xen.Vm vm = xen.getVmConfig(vmName);
/* check running */
if (vm == null) {
msg = doThis + " can't find VM " + vmName;
LOGGER.debug(msg);
return new AttachAnswer(msg);
}
if (disk.getType() == Volume.Type.ISO) {
path = getIsoPath(disk);
} else if (disk.getType() == Volume.Type.DATADISK) {
path = getVirtualDiskPath(disk, vm.getPrimaryPoolUuid());
}
if ("".equals(path)) {
msg = doThis + " can't do anything with an empty path.";
LOGGER.debug(msg);
return new AttachAnswer(msg);
}
if (isAttach) {
if (disk.getType() == Volume.Type.ISO) {
vm.addIso(path);
} else {
vm.addDataDisk(path);
}
} else {
if (!vm.removeDisk(path)) {
msg = doThis + " failed for " + vmName + disk.getType() + " was not attached " + path;
LOGGER.debug(msg);
return new AttachAnswer(msg);
}
}
xen.configureVm(ovmObject.deDash(vm.getPrimaryPoolUuid()), vm.getVmUuid());
return new AttachAnswer(disk);
} catch (Ovm3ResourceException e) {
msg = doThis + " failed for " + vmName + " " + e.getMessage();
LOGGER.warn(msg, e);
return new AttachAnswer(msg);
}
}
use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.
the class Ovm3StorageProcessor method createTemplateFromSnapshot.
/**
* Copies from secondary to secondary
*/
@Override
public Answer createTemplateFromSnapshot(CopyCommand cmd) {
LOGGER.debug("execute createTemplateFromSnapshot: " + cmd.getClass());
try {
// src.getPath contains the uuid of the snapshot.
DataTO srcData = cmd.getSrcTO();
SnapshotObjectTO srcSnap = (SnapshotObjectTO) srcData;
String secPoolUuid = pool.setupSecondaryStorage(srcData.getDataStore().getUrl());
String srcFile = config.getAgentSecStoragePath() + "/" + secPoolUuid + "/" + srcSnap.getPath();
// dest
DataTO destData = cmd.getDestTO();
TemplateObjectTO destTemplate = (TemplateObjectTO) destData;
String secPoolUuidTemplate = pool.setupSecondaryStorage(destData.getDataStore().getUrl());
String destDir = config.getAgentSecStoragePath() + "/" + secPoolUuidTemplate + "/" + destTemplate.getPath();
String destFile = destDir + "/" + destTemplate.getUuid() + ".raw";
CloudstackPlugin csp = new CloudstackPlugin(c);
csp.ovsMkdirs(destDir);
Linux host = new Linux(c);
host.copyFile(srcFile, destFile);
TemplateObjectTO newVol = new TemplateObjectTO();
newVol.setUuid(destTemplate.getUuid());
newVol.setPath(destTemplate.getUuid());
newVol.setFormat(ImageFormat.RAW);
return new CopyCmdAnswer(newVol);
} catch (Ovm3ResourceException e) {
String msg = "Error backupSnapshot: " + e.getMessage();
LOGGER.info(msg);
return new CopyCmdAnswer(msg);
}
}
use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.
the class Ovm3StoragePool method setupPool.
/**
* Setup a pool in general, this creates a repo if it doesn't exist yet, if
* it does however we mount it.
*
* @param cmd
* @return
* @throws Ovm3ResourceException
*/
private Boolean setupPool(StorageFilerTO cmd) throws Ovm3ResourceException {
String primUuid = cmd.getUuid();
String ssUuid = ovmObject.deDash(primUuid);
String fsType = "nfs";
String clusterUuid = config.getAgentOwnedByUuid().substring(0, 15);
String managerId = config.getAgentOwnedByUuid();
String poolAlias = cmd.getHost() + ":" + cmd.getPath();
String mountPoint = String.format("%1$s:%2$s", cmd.getHost(), cmd.getPath()) + "/VirtualMachines";
Integer poolSize = 0;
Pool poolHost = new Pool(c);
PoolOCFS2 poolFs = new PoolOCFS2(c);
if (config.getAgentIsMaster()) {
try {
LOGGER.debug("Create poolfs on " + config.getAgentHostname() + " for repo " + primUuid);
/* double check if we're not overwritting anything here!@ */
poolFs.createPoolFs(fsType, mountPoint, clusterUuid, primUuid, ssUuid, managerId);
} catch (Ovm3ResourceException e) {
throw e;
}
try {
poolHost.createServerPool(poolAlias, primUuid, config.getOvm3PoolVip(), poolSize + 1, config.getAgentHostname(), c.getIp());
} catch (Ovm3ResourceException e) {
throw e;
}
} else if (config.getAgentHasMaster()) {
try {
poolHost.joinServerPool(poolAlias, primUuid, config.getOvm3PoolVip(), poolSize + 1, config.getAgentHostname(), c.getIp());
} catch (Ovm3ResourceException e) {
throw e;
}
}
try {
/* should contain check if we're in an OVM pool or not */
CloudstackPlugin csp = new CloudstackPlugin(c);
Boolean vip = csp.dom0CheckPort(config.getOvm3PoolVip(), 22, 60, 1);
if (!vip) {
throw new Ovm3ResourceException("Unable to reach Ovm3 Pool VIP " + config.getOvm3PoolVip());
}
/*
* should also throw exception, we need to stop pool creation here,
* or is the manual addition fine?
*/
if (!addMembers()) {
return false;
}
} catch (Ovm3ResourceException e) {
throw new Ovm3ResourceException("Unable to add members to pool" + e.getMessage());
}
return true;
}
use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.
the class Ovm3StoragePool method setupNfsStorage.
/**
* Sets up NFS Storage
*
* @param uri
* @param uuid
* @return
* @throws Ovm3ResourceException
*/
private String setupNfsStorage(URI uri, String uuid) throws Ovm3ResourceException {
String fsUri = "nfs";
String msg = "";
String mountPoint = config.getAgentSecStoragePath() + "/" + uuid;
Linux host = new Linux(c);
Map<String, Linux.FileSystem> fsList = host.getFileSystemMap(fsUri);
Linux.FileSystem fs = fsList.get(uuid);
if (fs == null || !fs.getRemoteDir().equals(mountPoint)) {
try {
StoragePlugin sp = new StoragePlugin(c);
sp.storagePluginMountNFS(uri.getHost(), uri.getPath(), uuid, mountPoint);
msg = "Nfs storage " + uri + " mounted on " + mountPoint;
return uuid;
} catch (Ovm3ResourceException ec) {
msg = "Nfs storage " + uri + " mount on " + mountPoint + " FAILED " + ec.getMessage();
LOGGER.error(msg);
throw ec;
}
} else {
msg = "NFS storage " + uri + " already mounted on " + mountPoint;
return uuid;
}
}
Aggregations