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 <GrpcGetSwitchReply> GetSwitchAsync(GrpcGetSwitchRequest request, CallContext context = default)
        {
            await SyncContext.Clear;

            try
            {
                return(new GrpcGetSwitchReply(@switch: hyperv.GetSwitch(request.SwitchName).ToProto()));
            }
            catch (Exception e)
            {
                return(new GrpcGetSwitchReply(e));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns information for a Hyper-V switch by name.
        /// </summary>
        /// <param name="switchName">The switch name.</param>
        /// <returns>The <see cref="VirtualSwitch"/> when present or <c>null</c>.</returns>
        public VirtualSwitch GetSwitch(string switchName)
        {
            if (isAdmin)
            {
                return(hypervClient.GetSwitch(switchName: switchName));
            }
            else
            {
                var request = new GrpcGetSwitchRequest(switchName: switchName);
                var reply   = desktopService.GetSwitchAsync(request).Result;

                reply.Error.EnsureSuccess();

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