示例#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 switch, it it exists as well as any associated NAT (with the same name).
        /// </summary>
        /// <param name="switchName">The target switch name.</param>
        /// <param name="ignoreMissing">Optionally ignore missing items.</param>
        public void RemoveSwitch(string switchName, bool ignoreMissing = false)
        {
            if (isAdmin)
            {
                hypervClient.RemoveSwitch(switchName: switchName, ignoreMissing: ignoreMissing);
            }
            else
            {
                var request = new GrpcRemoveSwitchRequest(switchName: switchName, ignoreMissing: ignoreMissing);
                var reply   = desktopService.RemoveSwitchAsync(request).Result;

                reply.Error.EnsureSuccess();
            }
        }
示例#3
0
        /// <inheritdoc/>
        public async Task <GrpcBaseReply> RemoveSwitchAsync(GrpcRemoveSwitchRequest request, CallContext context = default)
        {
            await SyncContext.Clear;

            try
            {
                hyperv.RemoveSwitch(switchName: request.SwitchName, ignoreMissing: request.IgnoreMissing ?? false);

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