Search in sources :

Example 6 with PowerState

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;
}
Also used : PowerState(com.cloud.vm.VirtualMachine.PowerState)

Example 7 with PowerState

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

Example 8 with PowerState

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();
    }
}
Also used : MockVMVO(com.cloud.simulator.MockVMVO) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PowerState(com.cloud.vm.VirtualMachine.PowerState) MockVm(com.cloud.simulator.MockVm) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 9 with PowerState

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

Example 10 with PowerState

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;
}
Also used : ModifyTargetsAnswer(com.cloud.agent.api.ModifyTargetsAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) SetupAnswer(com.cloud.agent.api.SetupAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) CheckOnHostAnswer(com.cloud.agent.api.CheckOnHostAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) RevertToVMSnapshotAnswer(com.cloud.agent.api.RevertToVMSnapshotAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) CreateVMSnapshotAnswer(com.cloud.agent.api.CreateVMSnapshotAnswer) DeleteVMSnapshotAnswer(com.cloud.agent.api.DeleteVMSnapshotAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) ScaleVmAnswer(com.cloud.agent.api.ScaleVmAnswer) MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) ValidateSnapshotAnswer(com.cloud.agent.api.ValidateSnapshotAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) GetVmDiskStatsAnswer(com.cloud.agent.api.GetVmDiskStatsAnswer) ArrayList(java.util.ArrayList) VmStatsEntry(com.cloud.agent.api.VmStatsEntry) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) RemoteException(java.rmi.RemoteException) PowerState(com.cloud.vm.VirtualMachine.PowerState) VirtualMachinePowerState(com.vmware.vim25.VirtualMachinePowerState)

Aggregations

PowerState (com.cloud.vm.VirtualMachine.PowerState)21 HashMap (java.util.HashMap)9 LibvirtException (org.libvirt.LibvirtException)8 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)7 Domain (org.libvirt.Domain)6 HostVmStateReportEntry (com.cloud.agent.api.HostVmStateReportEntry)4 RevertToVMSnapshotAnswer (com.cloud.agent.api.RevertToVMSnapshotAnswer)4 Connection (com.xensource.xenapi.Connection)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 Connect (org.libvirt.Connect)4 VolumeObjectTO (com.cloud.storage.to.VolumeObjectTO)3 VMSnapshot (com.cloud.vm.snapshot.VMSnapshot)3 VirtualMachinePowerState (com.vmware.vim25.VirtualMachinePowerState)3 VBD (com.xensource.xenapi.VBD)2 VDI (com.xensource.xenapi.VDI)2 VM (com.xensource.xenapi.VM)2 Map (java.util.Map)2 Answer (com.cloud.agent.api.Answer)1 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)1 CheckHealthAnswer (com.cloud.agent.api.CheckHealthAnswer)1