Search in sources :

Example 1 with UnmanagedInstanceTO

use of org.apache.cloudstack.vm.UnmanagedInstanceTO in project cloudstack by apache.

the class VmwareResource method execute.

private Answer execute(GetUnmanagedInstancesCommand cmd) {
    VmwareContext context = getServiceContext();
    HashMap<String, UnmanagedInstanceTO> unmanagedInstances = new HashMap<>();
    try {
        VmwareHypervisorHost hyperHost = getHyperHost(context);
        String vmName = cmd.getInstanceName();
        List<VirtualMachineMO> vmMos = hyperHost.listVmsOnHyperHostWithHypervisorName(vmName);
        for (VirtualMachineMO vmMo : vmMos) {
            if (vmMo == null) {
                continue;
            }
            if (vmMo.isTemplate()) {
                continue;
            }
            // Filter managed instances
            if (cmd.hasManagedInstance(vmMo.getName())) {
                continue;
            }
            // Filter instance if answer is requested for a particular instance name
            if (StringUtils.isNotEmpty(cmd.getInstanceName()) && !cmd.getInstanceName().equals(vmMo.getVmName())) {
                continue;
            }
            UnmanagedInstanceTO instance = getUnmanagedInstance(hyperHost, vmMo);
            if (instance != null) {
                unmanagedInstances.put(instance.getName(), instance);
            }
        }
    } catch (Exception e) {
        s_logger.info("GetUnmanagedInstancesCommand failed due to " + VmwareHelper.getExceptionMessage(e));
    }
    return new GetUnmanagedInstancesAnswer(cmd, "", unmanagedInstances);
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) UnmanagedInstanceTO(org.apache.cloudstack.vm.UnmanagedInstanceTO) HashMap(java.util.HashMap) GetUnmanagedInstancesAnswer(com.cloud.agent.api.GetUnmanagedInstancesAnswer) VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException)

Example 2 with UnmanagedInstanceTO

use of org.apache.cloudstack.vm.UnmanagedInstanceTO in project cloudstack by apache.

the class VmwareResource method getUnmanagedInstance.

private UnmanagedInstanceTO getUnmanagedInstance(VmwareHypervisorHost hyperHost, VirtualMachineMO vmMo) {
    UnmanagedInstanceTO instance = null;
    try {
        instance = new UnmanagedInstanceTO();
        instance.setName(vmMo.getVmName());
        instance.setInternalCSName(vmMo.getInternalCSName());
        instance.setCpuCores(vmMo.getConfigSummary().getNumCpu());
        instance.setCpuCoresPerSocket(vmMo.getCoresPerSocket());
        instance.setCpuSpeed(vmMo.getConfigSummary().getCpuReservation());
        instance.setMemory(vmMo.getConfigSummary().getMemorySizeMB());
        instance.setOperatingSystemId(vmMo.getVmGuestInfo().getGuestId());
        if (StringUtils.isEmpty(instance.getOperatingSystemId())) {
            instance.setOperatingSystemId(vmMo.getConfigSummary().getGuestId());
        }
        VirtualMachineGuestOsIdentifier osIdentifier = VirtualMachineGuestOsIdentifier.OTHER_GUEST;
        try {
            osIdentifier = VirtualMachineGuestOsIdentifier.fromValue(instance.getOperatingSystemId());
        } catch (IllegalArgumentException iae) {
            if (StringUtils.isNotEmpty(instance.getOperatingSystemId()) && instance.getOperatingSystemId().contains("64")) {
                osIdentifier = VirtualMachineGuestOsIdentifier.OTHER_GUEST_64;
            }
        }
        instance.setOperatingSystem(vmMo.getGuestInfo().getGuestFullName());
        if (StringUtils.isEmpty(instance.getOperatingSystem())) {
            instance.setOperatingSystem(vmMo.getConfigSummary().getGuestFullName());
        }
        UnmanagedInstanceTO.PowerState powerState = UnmanagedInstanceTO.PowerState.PowerUnknown;
        if (vmMo.getPowerState().toString().equalsIgnoreCase("POWERED_ON")) {
            powerState = UnmanagedInstanceTO.PowerState.PowerOn;
        }
        if (vmMo.getPowerState().toString().equalsIgnoreCase("POWERED_OFF")) {
            powerState = UnmanagedInstanceTO.PowerState.PowerOff;
        }
        instance.setPowerState(powerState);
        instance.setDisks(getUnmanageInstanceDisks(vmMo));
        instance.setNics(getUnmanageInstanceNics(hyperHost, vmMo));
    } catch (Exception e) {
        s_logger.info("Unable to retrieve unmanaged instance info. " + e.getMessage());
    }
    return instance;
}
Also used : UnmanagedInstanceTO(org.apache.cloudstack.vm.UnmanagedInstanceTO) VirtualMachineGuestOsIdentifier(com.vmware.vim25.VirtualMachineGuestOsIdentifier) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException)

Aggregations

CloudException (com.cloud.exception.CloudException)2 InternalErrorException (com.cloud.exception.InternalErrorException)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ConnectException (java.net.ConnectException)2 RemoteException (java.rmi.RemoteException)2 ConfigurationException (javax.naming.ConfigurationException)2 UnmanagedInstanceTO (org.apache.cloudstack.vm.UnmanagedInstanceTO)2 GetUnmanagedInstancesAnswer (com.cloud.agent.api.GetUnmanagedInstancesAnswer)1 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)1 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)1 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)1 VirtualMachineGuestOsIdentifier (com.vmware.vim25.VirtualMachineGuestOsIdentifier)1 HashMap (java.util.HashMap)1