/// <summary> /// Adds an internal Hyper-V switch configured for the specified subnet and gateway as well /// as an optional NAT enabling external connectivity. /// </summary> /// <param name="switchName">The new switch name.</param> /// <param name="subnet">Specifies the internal subnet.</param> /// <param name="addNat">Optionally configure a NAT to support external routing.</param> public void NewInternalSwitch(string switchName, NetworkCidr subnet, bool addNat = false) { if (isAdmin) { hypervClient.NewInternalSwitch(switchName: switchName, subnet: subnet, addNat: addNat); } else { var request = new GrpcNewInternalSwitchRequest(switchName: switchName, subnet: subnet, addNat: addNat); var reply = desktopService.NewInternalSwitchAsync(request).Result; reply.Error.EnsureSuccess(); } }
/// <inheritdoc/> public async Task <GrpcBaseReply> NewInternalSwitchAsync(GrpcNewInternalSwitchRequest request, CallContext context = default) { await SyncContext.Clear; try { hyperv.NewInternalSwitch( switchName: request.SwitchName, subnet: NetworkCidr.Parse(request.Subnet), addNat: request.AddNat); return(new GrpcBaseReply()); } catch (Exception e) { return(new GrpcBaseReply(e)); } }