use of com.cloud.legacymodel.vm.HostVmStateReportEntry 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.legacymodel.vm.HostVmStateReportEntry in project cosmic by MissionCriticalCloud.
the class CitrixResourceBase method getHostVmStateReport.
protected HashMap<String, HostVmStateReportEntry> getHostVmStateReport(final Connection conn) {
// TODO : new VM sync model does not require a cluster-scope report, we
// need to optimize
// the report accordingly
final HashMap<String, HostVmStateReportEntry> vmStates = new HashMap<>();
Map<VM, VM.Record> vm_map = null;
for (int i = 0; i < 2; i++) {
try {
// USE THIS TO GET ALL VMS FROM
vm_map = VM.getAllRecords(conn);
// A CLUSTER
break;
} catch (final XmlRpcException | XenAPIException e) {
s_logger.warn("Unable to get vms", e);
}
try {
Thread.sleep(1000);
} catch (final InterruptedException e) {
s_logger.warn("Caught (previously ignored) interrupted exception", e);
}
}
if (vm_map == null) {
return vmStates;
}
for (final VM.Record record : vm_map.values()) {
if (record.isControlDomain || record.isASnapshot || record.isATemplate) {
// Skip DOM0
continue;
}
final VmPowerState ps = record.powerState;
final Host host = record.residentOn;
String host_uuid = null;
if (!isRefNull(host)) {
try {
host_uuid = host.getUuid(conn);
} catch (final BadServerResponse e) {
s_logger.error("Failed to get host uuid for host " + host.toWireString(), e);
} catch (final XenAPIException e) {
s_logger.error("Failed to get host uuid for host " + host.toWireString(), e);
} catch (final XmlRpcException e) {
s_logger.error("Failed to get host uuid for host " + host.toWireString(), e);
}
if (host_uuid.equalsIgnoreCase(this._host.getUuid())) {
vmStates.put(record.nameLabel, new HostVmStateReportEntry(convertToPowerState(ps), host_uuid));
}
}
}
return vmStates;
}
use of com.cloud.legacymodel.vm.HostVmStateReportEntry in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResource method getHostVmStateReport.
private HashMap<String, HostVmStateReportEntry> getHostVmStateReport() {
final HashMap<String, HostVmStateReportEntry> vmStates = new HashMap<>();
Connect conn = null;
if (getHypervisorType() == HypervisorType.KVM) {
try {
conn = LibvirtConnection.getConnectionByType(HypervisorType.KVM.toString());
vmStates.putAll(getHostVmStateReport(conn));
} catch (final LibvirtException e) {
logger.debug("Failed to get connection: " + e.getMessage());
}
}
return vmStates;
}
Aggregations