コード例 #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);
            }
        }
コード例 #2
0
        /// <summary>
        /// Removes a named virtual machine and all of its drives (by default).
        /// </summary>
        /// <param name="machineName">The machine name.</param>
        /// <param name="keepDrives">Optionally retains the VM disk files.</param>
        public void RemoveVm(string machineName, bool keepDrives = false)
        {
            if (isAdmin)
            {
                hypervClient.RemoveVm(machineName: machineName, keepDrives: keepDrives);
            }
            else
            {
                var request = new GrpcRemoveVmRequest(machineName: machineName, keepDrives: keepDrives);

                desktopService.RemoveVmAsync(request).Result.Error.EnsureSuccess();
            }
        }
コード例 #3
0
        /// <inheritdoc/>
        public async Task <GrpcBaseReply> RemoveVmAsync(GrpcRemoveVmRequest request, CallContext context = default)
        {
            await SyncContext.Clear;

            try
            {
                hyperv.RemoveVm(machineName: request.MachineName);

                return(new GrpcBaseReply());
            }
            catch (Exception e)
            {
                return(new GrpcBaseReply(e));
            }
        }