use of com.cloud.vm.VirtualMachine.PowerState in project cloudstack by apache.
the class VmwareResource method getVmStates.
private HashMap<String, PowerState> getVmStates() 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, PowerState> newStates = new HashMap<String, PowerState>();
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, convertPowerState(powerState));
}
}
}
}
return newStates;
}
use of com.cloud.vm.VirtualMachine.PowerState in project cloudstack by apache.
the class LibvirtComputingResource method getVmState.
public PowerState getVmState(final Connect conn, final String vmName) {
int retry = 3;
Domain vms = null;
while (retry-- > 0) {
try {
vms = conn.domainLookupByName(vmName);
final PowerState s = convertToPowerState(vms.getInfo().state);
return s;
} catch (final LibvirtException e) {
s_logger.warn("Can't get vm state " + vmName + e.getMessage() + "retry:" + retry);
} finally {
try {
if (vms != null) {
vms.free();
}
} catch (final LibvirtException l) {
s_logger.trace("Ignoring libvirt error.", l);
}
}
}
return PowerState.PowerOff;
}
use of com.cloud.vm.VirtualMachine.PowerState in project cloudstack by apache.
the class LibvirtCheckVirtualMachineCommandWrapper method execute.
@Override
public Answer execute(final CheckVirtualMachineCommand command, final LibvirtComputingResource libvirtComputingResource) {
try {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName());
final PowerState state = libvirtComputingResource.getVmState(conn, command.getVmName());
Integer vncPort = null;
if (state == PowerState.PowerOn) {
vncPort = libvirtComputingResource.getVncPort(conn, command.getVmName());
}
return new CheckVirtualMachineAnswer(command, state, vncPort);
} catch (final LibvirtException e) {
return new CheckVirtualMachineAnswer(command, e.getMessage());
}
}
use of com.cloud.vm.VirtualMachine.PowerState 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.vm.VirtualMachine.PowerState in project cloudstack by apache.
the class OvmResourceBase method getAllVms.
protected HashMap<String, PowerState> getAllVms() throws XmlRpcException {
final HashMap<String, PowerState> vmStates = new HashMap<String, PowerState>();
Map<String, String> vms = OvmHost.getAllVms(_conn);
for (final Map.Entry<String, String> entry : vms.entrySet()) {
PowerState powerState = toPowerState(entry.getKey(), entry.getValue());
vmStates.put(entry.getKey(), powerState);
}
return vmStates;
}
Aggregations