Ejemplo n.º 1
0
        /// <summary>
        /// Clears and test related state.
        /// </summary>
        private void ClearState()
        {
            // Put Hyper-V into a known state by ensuring that any test related assets
            // left over from a previous run are removed.

            using (var hyperv = new HyperVClient())
            {
                if (hyperv.GetVm(machineName: TestMachineName1) != null)
                {
                    hyperv.StopVm(TestMachineName1, turnOff: true);
                    hyperv.RemoveVm(TestMachineName1);
                }

                if (hyperv.GetVm(machineName: TestMachineName2) != null)
                {
                    hyperv.StopVm(TestMachineName2, turnOff: true);
                    hyperv.RemoveVm(TestMachineName2);
                }

                if (hyperv.GetSwitch(switchName: TestSwitchName) != null)
                {
                    hyperv.RemoveSwitch(TestSwitchName);
                }

                NeonHelper.DeleteFile(test1VhdxPath);
                NeonHelper.DeleteFile(test2VhdxPath);
            }
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public async Task <GrpcGetVmReply> GetVmAsync(GrpcGetVmRequest request, CallContext context = default)
        {
            await SyncContext.Clear;

            try
            {
                return(new GrpcGetVmReply(machine: hyperv.GetVm(request.MachineName).ToProto()));
            }
            catch (Exception e)
            {
                return(new GrpcGetVmReply(e));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the current status for a named virtual machine.
        /// </summary>
        /// <param name="machineName">The machine name.</param>
        /// <returns>The <see cref="VirtualMachine"/> or <c>null</c> when the virtual machine doesn't exist..</returns>
        public VirtualMachine GetVm(string machineName)
        {
            if (isAdmin)
            {
                return(hypervClient.GetVm(machineName: machineName));
            }
            else
            {
                var request = new GrpcGetVmRequest(machineName: machineName);
                var reply   = desktopService.GetVmAsync(request).Result;

                reply.Error.EnsureSuccess();

                return(reply.Machine.ToLocal());
            }
        }