use of com.cloud.vm.VirtualMachine.PowerState in project cloudstack by apache.
the class OvmResourceBase method toPowerState.
private PowerState toPowerState(String vmName, String s) {
PowerState state = s_powerStateMaps.get(s);
if (state == null) {
s_logger.debug("Unkown state " + s + " for " + vmName);
state = PowerState.PowerUnknown;
}
return state;
}
use of com.cloud.vm.VirtualMachine.PowerState in project cloudstack by apache.
the class AgentRoutingResource method getHostVmStateReport.
protected HashMap<String, HostVmStateReportEntry> getHostVmStateReport() {
HashMap<String, HostVmStateReportEntry> report = new HashMap<String, HostVmStateReportEntry>();
Map<String, PowerState> states = _simMgr.getVmStates(this.hostGuid);
for (String vmName : states.keySet()) {
report.put(vmName, new HostVmStateReportEntry(states.get(vmName), agentHost.getName()));
}
return report;
}
use of com.cloud.vm.VirtualMachine.PowerState in project cloudstack by apache.
the class MockVmManagerImpl method getVmStates.
@Override
public Map<String, PowerState> getVmStates(final String hostGuid) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
final Map<String, PowerState> states = new HashMap<String, PowerState>();
final List<MockVMVO> vms = _mockVmDao.findByHostGuid(hostGuid);
if (vms.isEmpty()) {
txn.commit();
return states;
}
for (final MockVm vm : vms) {
states.put(vm.getName(), vm.getPowerState());
}
txn.commit();
return states;
} catch (final Exception ex) {
txn.rollback();
throw new CloudRuntimeException("unable to fetch vms from host " + hostGuid, ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
use of com.cloud.vm.VirtualMachine.PowerState in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResource method getHostVmStateReport.
private HashMap<String, HostVmStateReportEntry> getHostVmStateReport(final Connect conn) {
final HashMap<String, HostVmStateReportEntry> vmStates = new HashMap<>();
String[] vms = null;
int[] ids = null;
try {
ids = conn.listDomains();
} catch (final LibvirtException e) {
logger.warn("Unable to listDomains", e);
return null;
}
try {
vms = conn.listDefinedDomains();
} catch (final LibvirtException e) {
logger.warn("Unable to listDomains", e);
return null;
}
Domain dm = null;
for (final int id : ids) {
try {
dm = conn.domainLookupByID(id);
final DomainState ps = dm.getInfo().state;
final PowerState state = convertToPowerState(ps);
logger.trace("VM " + dm.getName() + ": powerstate = " + ps + "; vm state=" + state.toString());
final String vmName = dm.getName();
vmStates.put(vmName, new HostVmStateReportEntry(state, conn.getHostName()));
} catch (final LibvirtException e) {
logger.warn("Unable to get vms", e);
} finally {
try {
if (dm != null) {
dm.free();
}
} catch (final LibvirtException e) {
logger.trace("Ignoring libvirt error.", e);
}
}
}
for (final String vm : vms) {
try {
dm = conn.domainLookupByName(vm);
final DomainState ps = dm.getInfo().state;
final PowerState state = convertToPowerState(ps);
final String vmName = dm.getName();
logger.trace("VM " + vmName + ": powerstate = " + ps + "; vm state=" + state.toString());
vmStates.put(vmName, new HostVmStateReportEntry(state, conn.getHostName()));
} catch (final LibvirtException e) {
logger.warn("Unable to get vms", e);
} finally {
try {
if (dm != null) {
dm.free();
}
} catch (final LibvirtException e) {
logger.trace("Ignoring libvirt error.", e);
}
}
}
return vmStates;
}
use of com.cloud.vm.VirtualMachine.PowerState in project cloudstack by apache.
the class VmwareResource method execute.
protected Answer execute(GetVmStatsCommand cmd) {
if (s_logger.isTraceEnabled()) {
s_logger.trace("Executing resource GetVmStatsCommand: " + _gson.toJson(cmd));
}
HashMap<String, VmStatsEntry> vmStatsMap = null;
try {
HashMap<String, PowerState> vmPowerStates = getVmStates();
// getVmNames should return all i-x-y values.
List<String> requestedVmNames = cmd.getVmNames();
List<String> vmNames = new ArrayList<String>();
if (requestedVmNames != null) {
for (String vmName : requestedVmNames) {
if (vmPowerStates.get(vmName) != null) {
vmNames.add(vmName);
}
}
}
if (vmNames != null) {
vmStatsMap = getVmStats(vmNames);
}
} catch (Throwable e) {
if (e instanceof RemoteException) {
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
invalidateServiceContext();
}
s_logger.error("Unable to execute GetVmStatsCommand due to : " + VmwareHelper.getExceptionMessage(e), e);
}
Answer answer = new GetVmStatsAnswer(cmd, vmStatsMap);
if (s_logger.isTraceEnabled()) {
s_logger.trace("Report GetVmStatsAnswer: " + _gson.toJson(answer));
}
return answer;
}
Aggregations