Search in sources :

Example 1 with WaitForValues

use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.WaitForValues in project photon-model by vmware.

the class VimUtils method waitTaskEnd.

public static TaskInfo waitTaskEnd(Connection connection, ManagedObjectReference task) throws InvalidCollectorVersionFaultMsg, InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    WaitForValues waitForValues = new WaitForValues(connection);
    Object[] info = waitForValues.wait(task, new String[] { VimPath.task_info }, new String[] { VimPath.task_info_state }, new Object[][] { new Object[] { TaskInfoState.SUCCESS, TaskInfoState.ERROR } });
    return (TaskInfo) info[0];
}
Also used : TaskInfo(com.vmware.vim25.TaskInfo) WaitForValues(com.vmware.photon.controller.model.adapters.vsphere.util.connection.WaitForValues)

Example 2 with WaitForValues

use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.WaitForValues in project photon-model by vmware.

the class PowerStateClient method softPowerOff.

private void softPowerOff(ManagedObjectReference vm, long politenessDeadlineMicros) throws Exception {
    try {
        getVimPort().shutdownGuest(vm);
    } catch (ToolsUnavailableFaultMsg e) {
        // no vmtoools present, try harder
        hardPowerOff(vm);
        return;
    }
    // wait for guest to shutdown
    WaitForValues wait = new WaitForValues(this.connection);
    int timeout = (int) TimeUnit.MICROSECONDS.toSeconds(politenessDeadlineMicros - Utils.getNowMicrosUtc());
    if (timeout <= 0) {
        // maybe try anyway?
        return;
    }
    Object[] currentPowerState = wait.wait(vm, new String[] { VimPath.vm_runtime_powerState }, new String[] { VimPath.vm_runtime_powerState }, new Object[][] { new Object[] { VirtualMachinePowerState.POWERED_OFF } }, timeout);
    if (currentPowerState == null || currentPowerState[0] != VirtualMachinePowerState.POWERED_OFF) {
        // vm not shutdown on time
        hardPowerOff(vm);
    }
}
Also used : WaitForValues(com.vmware.photon.controller.model.adapters.vsphere.util.connection.WaitForValues) ToolsUnavailableFaultMsg(com.vmware.vim25.ToolsUnavailableFaultMsg)

Aggregations

WaitForValues (com.vmware.photon.controller.model.adapters.vsphere.util.connection.WaitForValues)2 TaskInfo (com.vmware.vim25.TaskInfo)1 ToolsUnavailableFaultMsg (com.vmware.vim25.ToolsUnavailableFaultMsg)1