public void TestMachinePollStatus() { var provider = _container.Resolve <IHyperVProvider>(); provider.Connect(); IHyperVMachine machine = provider.GetMachineByName(MachineName); HyperVStatus status = provider.GetStatus(machine); Stopwatch s = new Stopwatch(); s.Start(); bool isReset = false; while (s.Elapsed.TotalSeconds < 15) { machine = provider.GetMachineByName(MachineName); status = provider.GetStatus(machine); Debug.WriteLine("Machine Status is => " + status); if (s.Elapsed.TotalSeconds >= 1 && !isReset) { provider.Reset(machine); isReset = true; } Thread.Sleep(1000); } s.Stop(); }
private uint ChangeState(HyperVStatus state) { var raw = _rawMachine; var scope = _rawMachine.Scope; var managementService = new ManagementClass(scope, new ManagementPath("Msvm_VirtualSystemManagementService"), null) .GetInstances() .OfType <ManagementObject>().FirstOrDefault(); if (managementService != null) { var inParameters = managementService.GetMethodParameters("RequestStateChange"); inParameters["RequestedState"] = (object)state; var outParameters = raw.InvokeMethod("RequestStateChange", inParameters, null); Debug.WriteLine("Changed state with return " + outParameters); if (outParameters != null) { return((uint)outParameters["ReturnValue"]); } } else { throw new HyperVException("Could not find machine management service for rstate change"); } return(0); }
public void OneTimeTearDown() { // Ensure we shut down the test image after tests complete. var provider = _container.GetRequiredService <IHyperVProvider>(); Thread.Sleep(5000); provider.Connect(); IHyperVMachine machine = provider.GetMachineByName(TestMachineName); HyperVStatus status = machine.GetStatus(); if (status != HyperVStatus.Off) { machine.Stop(); } }
private uint ChangeState(IHyperVMachine machine, HyperVStatus state) { var rawMachine = ((HyperVMachine)machine).FetchRawMachine(); var managementService = new ManagementClass(_scope, new ManagementPath("Msvm_VirtualSystemManagementService"), null) .GetInstances() .OfType<ManagementObject>().FirstOrDefault(); if (managementService != null) { var inParameters = managementService.GetMethodParameters("RequestStateChange"); inParameters["RequestedState"] = (object)state; var outParameters = rawMachine.InvokeMethod("RequestStateChange", inParameters, null); Debug.WriteLine("Changed state with return " + outParameters); if (outParameters != null) return (uint) outParameters["ReturnValue"]; } else { throw new HyperVException("Could not find machine management service for rstate change"); } return 0; }