Search in sources :

Example 1 with HostVmStateReportEntry

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;
}
Also used : HostVmStateReportEntry(com.cloud.agent.api.HostVmStateReportEntry) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) PowerState(com.cloud.vm.VirtualMachine.PowerState)

Example 2 with HostVmStateReportEntry

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;
}
Also used : HostVmStateReportEntry(com.cloud.agent.api.HostVmStateReportEntry) HashMap(java.util.HashMap) PowerState(com.cloud.vm.VirtualMachine.PowerState) State(com.cloud.vm.VirtualMachine.State) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with HostVmStateReportEntry

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;
}
Also used : HostVmStateReportEntry(com.cloud.agent.api.HostVmStateReportEntry) HashMap(java.util.HashMap) PowerState(com.cloud.vm.VirtualMachine.PowerState)

Example 4 with HostVmStateReportEntry

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;
}
Also used : BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) HostVmStateReportEntry(com.cloud.agent.api.HostVmStateReportEntry) HashMap(java.util.HashMap) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) VM(com.xensource.xenapi.VM) VmPowerState(com.xensource.xenapi.Types.VmPowerState) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 5 with HostVmStateReportEntry

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;
}
Also used : DynamicProperty(com.vmware.vim25.DynamicProperty) HostVmStateReportEntry(com.cloud.agent.api.HostVmStateReportEntry) HostMO(com.cloud.hypervisor.vmware.mo.HostMO) HashMap(java.util.HashMap) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) ObjectContent(com.vmware.vim25.ObjectContent) VirtualMachinePowerState(com.vmware.vim25.VirtualMachinePowerState)

Aggregations

HostVmStateReportEntry (com.cloud.agent.api.HostVmStateReportEntry)8 HashMap (java.util.HashMap)8 PowerState (com.cloud.vm.VirtualMachine.PowerState)4 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 LibvirtException (org.libvirt.LibvirtException)2 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)1 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)1 State (com.cloud.vm.VirtualMachine.State)1 DynamicProperty (com.vmware.vim25.DynamicProperty)1 ObjectContent (com.vmware.vim25.ObjectContent)1 VirtualMachinePowerState (com.vmware.vim25.VirtualMachinePowerState)1 Host (com.xensource.xenapi.Host)1 BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)1 VmPowerState (com.xensource.xenapi.Types.VmPowerState)1 XenAPIException (com.xensource.xenapi.Types.XenAPIException)1 VM (com.xensource.xenapi.VM)1 XmlRpcException (org.apache.xmlrpc.XmlRpcException)1 Connect (org.libvirt.Connect)1 Domain (org.libvirt.Domain)1