Search in sources :

Example 1 with GuestInfo

use of com.vmware.vim25.GuestInfo in project cloudstack by apache.

the class VmwareResource method execute.

protected Answer execute(GetVmIpAddressCommand cmd) {
    if (s_logger.isTraceEnabled()) {
        s_logger.trace("Executing resource command GetVmIpAddressCommand: " + _gson.toJson(cmd));
    }
    String details = "Unable to find IP Address of VM. ";
    String vmName = cmd.getVmName();
    boolean result = false;
    String ip = null;
    Answer answer = null;
    VmwareContext context = getServiceContext();
    VmwareHypervisorHost hyperHost = getHyperHost(context);
    if (vmName == null || vmName.isEmpty()) {
        details += "Name of instance provided is NULL or empty.";
        return new Answer(cmd, result, details);
    }
    try {
        VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName);
        if (vmMo != null) {
            GuestInfo guestInfo = vmMo.getGuestInfo();
            VirtualMachineToolsStatus toolsStatus = guestInfo.getToolsStatus();
            if (toolsStatus == VirtualMachineToolsStatus.TOOLS_NOT_INSTALLED) {
                details += "Vmware tools not installed.";
            } else {
                ip = guestInfo.getIpAddress();
                if (ip != null) {
                    result = true;
                }
                details = ip;
            }
        } else {
            details += "VM " + vmName + " no longer exists on vSphere host: " + hyperHost.getHyperHostName();
            s_logger.info(details);
        }
    } catch (Throwable e) {
        if (e instanceof RemoteException) {
            s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
            invalidateServiceContext();
        }
        details += "Encountered exception : " + VmwareHelper.getExceptionMessage(e);
        s_logger.error(details);
    }
    answer = new Answer(cmd, result, details);
    if (s_logger.isTraceEnabled()) {
        s_logger.trace("Returning GetVmIpAddressAnswer: " + _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) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) VirtualMachineToolsStatus(com.vmware.vim25.VirtualMachineToolsStatus) GuestInfo(com.vmware.vim25.GuestInfo) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) RemoteException(java.rmi.RemoteException)

Aggregations

Answer (com.cloud.agent.api.Answer)1 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)1 CheckHealthAnswer (com.cloud.agent.api.CheckHealthAnswer)1 CheckNetworkAnswer (com.cloud.agent.api.CheckNetworkAnswer)1 CheckOnHostAnswer (com.cloud.agent.api.CheckOnHostAnswer)1 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)1 CreateVMSnapshotAnswer (com.cloud.agent.api.CreateVMSnapshotAnswer)1 CreateVolumeFromSnapshotAnswer (com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)1 DeleteVMSnapshotAnswer (com.cloud.agent.api.DeleteVMSnapshotAnswer)1 GetHostStatsAnswer (com.cloud.agent.api.GetHostStatsAnswer)1 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)1 GetVmDiskStatsAnswer (com.cloud.agent.api.GetVmDiskStatsAnswer)1 GetVmStatsAnswer (com.cloud.agent.api.GetVmStatsAnswer)1 GetVncPortAnswer (com.cloud.agent.api.GetVncPortAnswer)1 MaintainAnswer (com.cloud.agent.api.MaintainAnswer)1 ManageSnapshotAnswer (com.cloud.agent.api.ManageSnapshotAnswer)1 MigrateAnswer (com.cloud.agent.api.MigrateAnswer)1 MigrateWithStorageAnswer (com.cloud.agent.api.MigrateWithStorageAnswer)1 ModifyStoragePoolAnswer (com.cloud.agent.api.ModifyStoragePoolAnswer)1 ModifyTargetsAnswer (com.cloud.agent.api.ModifyTargetsAnswer)1