use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.
the class Ovm3VmSupport method execute.
/* do migrations of VMs in a simple way just inside a cluster for now */
public MigrateAnswer execute(final MigrateCommand cmd) {
final String vmName = cmd.getVmName();
String destUuid = cmd.getHostGuid();
String destIp = cmd.getDestinationIp();
State state = State.Error;
/*
* TODO: figure out non pooled migration, works from CLI but not from
* the agent... perhaps pause the VM and then migrate it ? for now just
* stop the VM.
*/
String msg = "Migrating " + vmName + " to " + destIp;
LOGGER.info(msg);
if (!config.getAgentInOvm3Cluster() && !config.getAgentInOvm3Pool()) {
try {
Xen xen = new Xen(c);
Xen.Vm vm = xen.getRunningVmConfig(vmName);
HostVO destHost = resourceMgr.findHostByGuid(destUuid);
if (destHost == null) {
msg = "Unable to find migration target host in DB " + destUuid + " with ip " + destIp;
LOGGER.info(msg);
return new MigrateAnswer(cmd, false, msg, null);
}
xen.stopVm(ovmObject.deDash(vm.getVmRootDiskPoolId()), vm.getVmUuid());
msg = destHost.toString();
state = State.Stopping;
return new MigrateAnswer(cmd, false, msg, null);
} catch (Ovm3ResourceException e) {
msg = "Unpooled VM Migrate of " + vmName + " to " + destUuid + " failed due to: " + e.getMessage();
LOGGER.debug(msg, e);
return new MigrateAnswer(cmd, false, msg, null);
} finally {
/* shouldn't we just reinitialize completely as a last resort ? */
hypervisor.setVmState(vmName, state);
}
} else {
try {
Xen xen = new Xen(c);
Xen.Vm vm = xen.getRunningVmConfig(vmName);
if (vm == null) {
state = State.Stopped;
msg = vmName + " is no running on " + config.getAgentHostname();
return new MigrateAnswer(cmd, false, msg, null);
}
/* not a storage migration!!! */
xen.migrateVm(ovmObject.deDash(vm.getVmRootDiskPoolId()), vm.getVmUuid(), destIp);
state = State.Stopping;
msg = "Migration of " + vmName + " successfull";
return new MigrateAnswer(cmd, true, msg, null);
} catch (Ovm3ResourceException e) {
msg = "Pooled VM Migrate" + ": Migration of " + vmName + " to " + destIp + " failed due to " + e.getMessage();
LOGGER.debug(msg, e);
return new MigrateAnswer(cmd, false, msg, null);
} finally {
hypervisor.setVmState(vmName, state);
}
}
}
use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.
the class Ovm3VmSupport method getVmStat.
private VmStatsEntry getVmStat(String vmName) {
CloudstackPlugin cSp = new CloudstackPlugin(c);
Map<String, String> oldVmStats = null;
Map<String, String> newVmStats = null;
VmStatsEntry stats = new VmStatsEntry();
try {
if (vmStats.containsKey(vmName)) {
oldVmStats = new HashMap<String, String>();
oldVmStats.putAll(vmStats.get(vmName));
}
newVmStats = cSp.ovsDomUStats(vmName);
} catch (Ovm3ResourceException e) {
LOGGER.info("Unable to retrieve stats from " + vmName, e);
return stats;
}
if (oldVmStats == null) {
LOGGER.debug("No old stats retrieved stats from " + vmName);
stats.setNumCPUs(1);
stats.setNetworkReadKBs(0);
stats.setNetworkWriteKBs(0);
stats.setDiskReadKBs(0);
stats.setDiskWriteKBs(0);
stats.setDiskReadIOs(0);
stats.setDiskWriteIOs(0);
stats.setCPUUtilization(0);
stats.setEntityType("vm");
} else {
LOGGER.debug("Retrieved new stats from " + vmName);
int cpus = Integer.parseInt(newVmStats.get("vcpus"));
stats.setNumCPUs(cpus);
stats.setNetworkReadKBs(doubleMin(newVmStats.get("rx_bytes"), oldVmStats.get("rx_bytes")));
stats.setNetworkWriteKBs(doubleMin(newVmStats.get("tx_bytes"), oldVmStats.get("tx_bytes")));
stats.setDiskReadKBs(doubleMin(newVmStats.get("rd_bytes"), oldVmStats.get("rd_bytes")));
stats.setDiskWriteKBs(doubleMin(newVmStats.get("rw_bytes"), oldVmStats.get("rw_bytes")));
stats.setDiskReadIOs(doubleMin(newVmStats.get("rd_ops"), oldVmStats.get("rd_ops")));
stats.setDiskWriteIOs(doubleMin(newVmStats.get("rw_ops"), oldVmStats.get("rw_ops")));
Double dCpu = doubleMin(newVmStats.get("cputime"), oldVmStats.get("cputime"));
Double dTime = doubleMin(newVmStats.get("uptime"), oldVmStats.get("uptime"));
Double cpupct = dCpu / dTime * 100 * cpus;
stats.setCPUUtilization(cpupct);
stats.setEntityType("vm");
}
((ConcurrentHashMap<String, Map<String, String>>) vmStats).put(vmName, newVmStats);
return stats;
}
use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException 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.Ovm3ResourceException in project cloudstack by apache.
the class Ovm3VmSupport method deleteVif.
private Boolean deleteVif(Xen.Vm vm, NicTO nic) throws Ovm3ResourceException {
/* here we should use the housekeeping of VLANs/Networks etc..
* so we can clean after the last VM is gone
*/
try {
String net = network.getNetwork(nic);
if (net != null) {
LOGGER.debug("Removing vif " + nic.getDeviceId() + " " + " " + nic.getMac() + " " + net + " from " + vm.getVmName());
vm.removeVif(net, nic.getMac());
} else {
LOGGER.debug("Unable to remove vif " + nic.getDeviceId() + " no network for " + vm.getVmName());
return false;
}
} catch (Exception e) {
String msg = "Unable to remove vif " + nic.getType() + " for " + vm.getVmName() + " " + e.getMessage();
LOGGER.debug(msg);
throw new Ovm3ResourceException(msg);
}
return true;
}
use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.
the class Ovm3VmSupport method execute.
/* Migration should make sure both HVs are the same ? */
public PrepareForMigrationAnswer execute(PrepareForMigrationCommand cmd) {
VirtualMachineTO vm = cmd.getVirtualMachine();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Preparing host for migrating " + vm.getName());
}
NicTO[] nics = vm.getNics();
try {
for (NicTO nic : nics) {
network.getNetwork(nic);
}
hypervisor.setVmState(vm.getName(), State.Migrating);
LOGGER.debug("VM " + vm.getName() + " is in Migrating state");
return new PrepareForMigrationAnswer(cmd);
} catch (Ovm3ResourceException e) {
LOGGER.error("Catch Exception " + e.getClass().getName() + " prepare for migration failed due to: " + e.getMessage());
return new PrepareForMigrationAnswer(cmd, e);
}
}
Aggregations