use of com.cloud.hypervisor.ovm3.objects.Xen in project cloudstack by apache.
the class Ovm3HypervisorResource method execute.
@Override
public RebootAnswer execute(RebootCommand cmd) {
String vmName = cmd.getVmName();
hypervisorsupport.setVmStateStarting(vmName);
try {
Xen xen = new Xen(c);
Xen.Vm vm = xen.getRunningVmConfig(vmName);
if (vm == null) {
return new RebootAnswer(cmd, vmName + " not present", false);
}
xen.rebootVm(ovmObject.deDash(vm.getVmRootDiskPoolId()), vm.getVmUuid());
vm = xen.getRunningVmConfig(vmName);
Integer vncPort = vm.getVncPort();
return new RebootAnswer(cmd, null, vncPort);
} catch (Exception e) {
LOGGER.debug("Reboot " + vmName + " failed", e);
return new RebootAnswer(cmd, e.getMessage(), false);
} finally {
hypervisorsupport.setVmState(vmName, State.Running);
}
}
use of com.cloud.hypervisor.ovm3.objects.Xen in project cloudstack by apache.
the class Ovm3StorageProcessor method createSnapshot.
/**
* Creates a snapshot from a volume, but only if the VM is stopped.
* This due qemu not being able to snap raw volumes.
*
* if stopped yes, if running ... no, unless we have ocfs2 when
* using raw partitions (file:) if using tap:aio we cloud...
* The "ancient" way:
* We do however follow the "two stage" approach, of "snap"
* on primary first, with the create object... and then
* backup the snapshot with the copycmd....
* (should transfer to createSnapshot, backupSnapshot)
*/
@Override
public Answer createSnapshot(CreateObjectCommand cmd) {
LOGGER.debug("execute createSnapshot: " + cmd.getClass());
DataTO data = cmd.getData();
Xen xen = new Xen(c);
SnapshotObjectTO snap = (SnapshotObjectTO) data;
VolumeObjectTO vol = snap.getVolume();
try {
Xen.Vm vm = xen.getVmConfig(snap.getVmName());
if (vm != null) {
return new CreateObjectAnswer("Snapshot object creation not supported for running VMs." + snap.getVmName());
}
Linux host = new Linux(c);
String uuid = host.newUuid();
/* for root volumes this works... */
String src = vol.getPath() + "/" + vol.getUuid() + ".raw";
String dest = vol.getPath() + "/" + uuid + ".raw";
/* seems that sometimes the path is already contains a file
* in case, we just replace it.... (Seems to happen if not ROOT)
*/
if (vol.getPath().contains(vol.getUuid())) {
src = getVirtualDiskPath(vol.getUuid(), data.getDataStore().getUuid());
dest = src.replace(vol.getUuid(), uuid);
}
LOGGER.debug("Snapshot " + src + " to " + dest);
host.copyFile(src, dest);
SnapshotObjectTO nsnap = new SnapshotObjectTO();
// nsnap.setPath(dest);
// move to something that looks the same as xenserver.
nsnap.setPath(uuid);
return new CreateObjectAnswer(nsnap);
} catch (Ovm3ResourceException e) {
return new CreateObjectAnswer("Snapshot object creation failed. " + e.getMessage());
}
}
use of com.cloud.hypervisor.ovm3.objects.Xen 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.Xen in project cloudstack by apache.
the class Ovm3VmSupport method plugNunplugNic.
/**
* Implements the unplug and plug feature for Nics, the boolan decides
* to either plug (true) or unplug (false)
*
* @param nic
* @param vmName
* @param plug
* @return
*/
private Answer plugNunplugNic(NicTO nic, String vmName, Boolean plug) {
try {
Xen xen = new Xen(c);
Xen.Vm vm = xen.getVmConfig(vmName);
/* check running */
if (vm == null) {
return new Answer(null, false, "Unable to execute command due to missing VM");
}
// setup the NIC in the VM config.
if (plug) {
createVif(vm, nic);
vm.setupVifs();
} else {
deleteVif(vm, nic);
}
// execute the change
xen.configureVm(ovmObject.deDash(vm.getPrimaryPoolUuid()), vm.getVmUuid());
} catch (Ovm3ResourceException e) {
String msg = "Unable to execute command due to " + e.toString();
LOGGER.debug(msg);
return new Answer(null, false, msg);
}
return new Answer(null, true, "success");
}
use of com.cloud.hypervisor.ovm3.objects.Xen in project cloudstack by apache.
the class Ovm3VmSupport method execute.
/*
*/
public GetVncPortAnswer execute(GetVncPortCommand cmd) {
try {
Xen host = new Xen(c);
Xen.Vm vm = host.getRunningVmConfig(cmd.getName());
Integer vncPort = vm.getVncPort();
LOGGER.debug("get vnc port for " + cmd.getName() + ": " + vncPort);
return new GetVncPortAnswer(cmd, c.getIp(), vncPort);
} catch (Ovm3ResourceException e) {
LOGGER.debug("get vnc port for " + cmd.getName() + " failed", e);
return new GetVncPortAnswer(cmd, e.getMessage());
}
}
Aggregations