def CheckFTState(vm, state, isPrimary=True, checkRRState=False): with LogSelfOp() as logOp: expRRState = None if isPrimary: expRRState = vim.VirtualMachine.RecordReplayState.recording else: expRRState = vim.VirtualMachine.RecordReplayState.replaying ftState = vm.GetRuntime().GetFaultToleranceState() rrState = vm.GetRuntime().GetRecordReplayState() if ftState != state: raise Exception("%s: Runtime FT state %s not set to %s" % \ (DescribeVm(vm), ftState, state)) Log("Verified runtime fault tolerance state as %s" % state) if not checkRRState: return # Check record/replay state if ftState == FTState.running: if rrState != expRRState: raise Exception("Runtime recordReplay state %s not set to %s" % \ (rrState, expRRState)) elif rrState != vim.VirtualMachine.RecordReplayState.inactive: raise Exception( "Runtime recordReplay state %s not set to inactive" % rrState) Log("Verified runtime record/replay state as %s" % rrState)
def WaitForPowerState(vm, si, powerState, nsec = 20): saveSi = connect.GetSi() connect.SetSi(si) for i in range(nsec): if vm.GetRuntime().GetPowerState() != powerState: time.sleep(1) if vm.GetRuntime().GetPowerState() != powerState: raise Exception("VM did not transition to expected power state!") connect.SetSi(saveSi)
def WaitForFTState(vm, desiredFtState, nsec=20): with LogSelfOp() as logOp: for i in range(nsec): ftState = vm.GetRuntime().GetFaultToleranceState() if ftState != desiredFtState: time.sleep(1) ftState = vm.GetRuntime().GetFaultToleranceState() if ftState != desiredFtState: raise Exception("%s: VM did not transition to expected FT state current %s != desired %s!" % \ (DescribeVm(vm), ftState, desiredFtState))
def WaitForPowerState(vm, si, powerState, nsec=40): with LogSelfOp() as logOp: saveSi = connect.GetSi() connect.SetSi(si) for i in range(nsec): if vm.GetRuntime().GetPowerState() != powerState: time.sleep(1) if vm.GetRuntime().GetPowerState() != powerState: raise Exception("%s: VM did not transition to expected power state!" % \ DescribeVm(vm)) connect.SetSi(saveSi)
def WaitForVMPowerState(self, vm, targetState, timeout=-1, progressCB=None): """ Wait for the given vm to enter the given power state. Timeout after the given timeout. Invoke the given progress callback occasional. @param vm [in] Hostd VirtualMachine MoRef @param targetState [in] the desired power state to wait for ('on' or 'off') @param timeout [in] seconds to abandon wait after (-1 means never, 0 means poll) @param progressCB [in] If not None, callback to invoke occasionally while waiting """ # First convert the targetState string into a VMODL PowerState enum value if targetState in ["off", "OFF", "Off"]: targetState = Vim.VirtualMachine.PowerState.poweredOff elif targetState in ["on", "ON", "On"]: targetState = Vim.VirtualMachine.PowerState.poweredOn else: raise RuntimeError, "Unknown state '%s' (should be 'on' or 'off')" % targetState # XXX use a property collector to wait ... rt = vm.GetRuntime() return self._WaitForResult("power state", rt.GetPowerState, targetState, progressCB, timeout)
def WaitForFTState(vm, state, nsec=120): for i in range(nsec): ftState = vm.GetRuntime().GetFaultToleranceState() if ftState == state: return time.sleep(1) raise Exception("Runtime FT state %s not set to %s" % (ftState, state))
def WaitForDasProtection(vm, status, nsec=120): for i in range(nsec): dasVmProtection = vm.GetRuntime().GetDasVmProtection() if dasVmProtection != None: dasProtection = dasVmProtection.GetDasProtected() if dasProtection == status: return time.sleep(1) raise Exception("VM is not protected")
def CheckFTState(vm, state, si = None, isPrimary = True): prevSi = None if si != None: prevSi = connect.GetSi() connect.SetSi(si) ftState = vm.GetRuntime().GetFaultToleranceState() if ftState != state: raise Exception( "Runtime FT state " + str(ftState) + " not set to " + str(state)) Log("Verified runtime fault tolerance state as " + str(state))
def CheckFTState(vm, state, si=None, isPrimary=True): expRRState = None if isPrimary: expRRState = vim.VirtualMachine.RecordReplayState.recording else: expRRState = vim.VirtualMachine.RecordReplayState.replaying ftState = vm.GetRuntime().GetFaultToleranceState() rrState = vm.GetRuntime().GetRecordReplayState() if ftState != state: raise Exception("Runtime FT state %s not set to %s" % (ftState, state)) Log("Verified runtime fault tolerance state as " + str(state)) if not checkRRState: return # Check record/replay state if ftState == FTState.running: if rrState != expRRState: raise Exception("Runtime recordReplay state %s not set to %s" % (rrState, expRRState)) elif rrState != vim.VirtualMachine.RecordReplayState.inactive: raise Exception("Runtime recordReplay state %s not set to inactive" % rrState) Log("Verified runtime record/replay state as %s" % rrState)
def CheckState(vm, state): curState = vm.GetRuntime().GetRecordReplayState() if curState != state: raise Exception("Runtime record/replay state not set to " + str(state)) Log("Verified runtime record/replay state")
def WaitForPowerState(vm, si, powerState, nsec=20): for i in range(nsec): if vm.GetRuntime().GetPowerState() == powerState: return time.sleep(1) raise Exception("VM did not transition to expected power state!")