use of com.cloud.agent.api.HostVmStateReportEntry in project cloudstack by apache.
the class OvmResourceBase method getHostVmStateReport.
protected HashMap<String, HostVmStateReportEntry> getHostVmStateReport() throws XmlRpcException {
final HashMap<String, HostVmStateReportEntry> vmStates = new HashMap<String, HostVmStateReportEntry>();
Map<String, String> vms = OvmHost.getAllVms(_conn);
for (final Map.Entry<String, String> entry : vms.entrySet()) {
PowerState state = toPowerState(entry.getKey(), entry.getValue());
vmStates.put(entry.getKey(), new HostVmStateReportEntry(state, _conn.getIp()));
}
return vmStates;
}
use of com.cloud.agent.api.HostVmStateReportEntry in project cloudstack by apache.
the class Ovm3HypervisorSupport method hostVmStateReport.
/**
* hostVmStateReport: Get all the VM states.
*
* @return
* @throws Ovm3ResourceException
*/
public Map<String, HostVmStateReportEntry> hostVmStateReport() throws Ovm3ResourceException {
final Map<String, HostVmStateReportEntry> vmStates = new HashMap<String, HostVmStateReportEntry>();
for (final Map.Entry<String, State> vm : vmStateMap.entrySet()) {
LOGGER.debug("VM " + vm.getKey() + " state: " + vm.getValue() + ":" + convertStateToPower(vm.getValue()));
vmStates.put(vm.getKey(), new HostVmStateReportEntry(convertStateToPower(vm.getValue()), c.getIp()));
}
return vmStates;
}
use of com.cloud.agent.api.HostVmStateReportEntry 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.agent.api.HostVmStateReportEntry in project cloudstack by apache.
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<String, HostVmStateReportEntry>();
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 Throwable e) {
s_logger.warn("Unable to get vms", e);
}
try {
Thread.sleep(1000);
} catch (final InterruptedException ex) {
}
}
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(_host.getUuid())) {
vmStates.put(record.nameLabel, new HostVmStateReportEntry(convertToPowerState(ps), host_uuid));
}
}
}
return vmStates;
}
use of com.cloud.agent.api.HostVmStateReportEntry in project cloudstack by apache.
the class VmwareResource method getHostVmStateReport.
private HashMap<String, HostVmStateReportEntry> getHostVmStateReport() throws Exception {
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
int key = ((HostMO) hyperHost).getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
if (key == 0) {
s_logger.warn("Custom field " + CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!");
}
String instanceNameCustomField = "value[" + key + "]";
// CLOUD_VM_INTERNAL_NAME stores the internal CS generated vm name. This was earlier stored in name. Now, name can be either the hostname or
// the internal CS name, but the custom field CLOUD_VM_INTERNAL_NAME always stores the internal CS name.
ObjectContent[] ocs = hyperHost.getVmPropertiesOnHyperHost(new String[] { "name", "runtime.powerState", "config.template", instanceNameCustomField });
HashMap<String, HostVmStateReportEntry> newStates = new HashMap<String, HostVmStateReportEntry>();
if (ocs != null && ocs.length > 0) {
for (ObjectContent oc : ocs) {
List<DynamicProperty> objProps = oc.getPropSet();
if (objProps != null) {
boolean isTemplate = false;
String name = null;
String VMInternalCSName = null;
VirtualMachinePowerState powerState = VirtualMachinePowerState.POWERED_OFF;
for (DynamicProperty objProp : objProps) {
if (objProp.getName().equals("config.template")) {
if (objProp.getVal().toString().equalsIgnoreCase("true")) {
isTemplate = true;
}
} else if (objProp.getName().equals("runtime.powerState")) {
powerState = (VirtualMachinePowerState) objProp.getVal();
} else if (objProp.getName().equals("name")) {
name = (String) objProp.getVal();
} else if (objProp.getName().contains(instanceNameCustomField)) {
if (objProp.getVal() != null)
VMInternalCSName = ((CustomFieldStringValue) objProp.getVal()).getValue();
} else {
assert (false);
}
}
if (VMInternalCSName != null)
name = VMInternalCSName;
if (!isTemplate) {
newStates.put(name, new HostVmStateReportEntry(convertPowerState(powerState), hyperHost.getHyperHostName()));
}
}
}
}
return newStates;
}
Aggregations