public async Task <RouteFilter> CreateDefaultRouteFilter(string resourceGroupName, string filterName, string location, NetworkManagementClient nrpClient, bool containsRule = false) { var filter = new RouteFilter() { Location = location, Tags = { { "key", "value" } } }; if (containsRule) { RouteFilterRule rule = new RouteFilterRule() { Name = "test", Access = ExpressRouteTests.Filter_Access, Communities = { ExpressRouteTests.Filter_Commmunity }, Location = location }; filter.Rules.Add(rule); } // Put route filter Operation <RouteFilter> filterOperation = await nrpClient.RouteFilters.StartCreateOrUpdateAsync(resourceGroupName, filterName, filter); Response <RouteFilter> filterResponse = await WaitForCompletionAsync(filterOperation); Assert.AreEqual("Succeeded", filterResponse.Value.ProvisioningState.ToString()); Response <RouteFilter> getFilterResponse = await nrpClient.RouteFilters.GetAsync(resourceGroupName, filterName); return(getFilterResponse); }
public async Task <Response <RouteFilterRule> > GetAsync(string resourceGroupName, string routeFilterName, string ruleName, CancellationToken cancellationToken = default) { if (resourceGroupName == null) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (routeFilterName == null) { throw new ArgumentNullException(nameof(routeFilterName)); } if (ruleName == null) { throw new ArgumentNullException(nameof(ruleName)); } using var message = CreateGetRequest(resourceGroupName, routeFilterName, ruleName); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: { RouteFilterRule value = default; using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); value = RouteFilterRule.DeserializeRouteFilterRule(document.RootElement); return(Response.FromValue(value, message.Response)); }
public async Task <RouteFilter> CreateDefaultRouteFilterRule(string resourceGroupName, string filterName, string ruleName, string location, NetworkManagementClient nrpClient) { RouteFilterRule rule = new RouteFilterRule() { Access = ExpressRouteTests.Filter_Access, Communities = { ExpressRouteTests.Filter_Commmunity }, Location = location }; // Put route filter rule Operation <RouteFilterRule> ruleOperation = await nrpClient.RouteFilterRules.StartCreateOrUpdateAsync(resourceGroupName, filterName, ruleName, rule); Response <RouteFilterRule> ruleResponse = await WaitForCompletionAsync(ruleOperation); Assert.AreEqual("Succeeded", ruleResponse.Value.ProvisioningState.ToString()); Response <RouteFilter> getFilterResponse = await nrpClient.RouteFilters.GetAsync(resourceGroupName, filterName); return(getFilterResponse); }
public static RouteFilter CreateDefaultRouteFilterRule(string resourceGroupName, string filterName, string ruleName, string location, NetworkManagementClient nrpClient) { var rule = new RouteFilterRule() { Access = ExpressRouteTests.Filter_Access, Communities = new List <string> { ExpressRouteTests.Filter_Commmunity }, Location = location }; // Put route filter rule var ruleResponse = nrpClient.RouteFilterRules.CreateOrUpdate(resourceGroupName, filterName, ruleName, rule); Assert.Equal("Succeeded", ruleResponse.ProvisioningState); var getFilterResponse = nrpClient.RouteFilters.Get(resourceGroupName, filterName); return(getFilterResponse); }
public static RouteFilter CreateDefaultRouteFilter(string resourceGroupName, string filterName, string location, NetworkManagementClient nrpClient, bool containsRule = false) { var filter = new RouteFilter() { Location = location, Tags = new Dictionary <string, string>() { { "key", "value" } } }; if (containsRule) { var rule = new RouteFilterRule() { Name = "test", Access = ExpressRouteTests.Filter_Access, Communities = new List <string> { ExpressRouteTests.Filter_Commmunity }, Location = location }; var rules = new List <RouteFilterRule>(); rules.Add(rule); filter.Rules = rules; } // Put route filter var filterResponse = nrpClient.RouteFilters.CreateOrUpdate(resourceGroupName, filterName, filter); Assert.Equal("Succeeded", filterResponse.ProvisioningState); var getFilterResponse = nrpClient.RouteFilters.Get(resourceGroupName, filterName); return(getFilterResponse); }
/// <summary> /// Creates or updates a route in the specified route filter. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='routeFilterName'> /// The name of the route filter. /// </param> /// <param name='ruleName'> /// The name of the route filter rule. /// </param> /// <param name='routeFilterRuleParameters'> /// Parameters supplied to the create or update route filter rule operation. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <RouteFilterRule> BeginCreateOrUpdateAsync(this IRouteFilterRulesOperations operations, string resourceGroupName, string routeFilterName, string ruleName, RouteFilterRule routeFilterRuleParameters, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.BeginCreateOrUpdateWithHttpMessagesAsync(resourceGroupName, routeFilterName, ruleName, routeFilterRuleParameters, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Creates or updates a route in the specified route filter. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='routeFilterName'> /// The name of the route filter. /// </param> /// <param name='ruleName'> /// The name of the route filter rule. /// </param> /// <param name='routeFilterRuleParameters'> /// Parameters supplied to the create or update route filter rule operation. /// </param> public static RouteFilterRule BeginCreateOrUpdate(this IRouteFilterRulesOperations operations, string resourceGroupName, string routeFilterName, string ruleName, RouteFilterRule routeFilterRuleParameters) { return(operations.BeginCreateOrUpdateAsync(resourceGroupName, routeFilterName, ruleName, routeFilterRuleParameters).GetAwaiter().GetResult()); }
public async Task RouteFilterApiTest() { Subscription subscription = await ArmClient.GetDefaultSubscriptionAsync(); var filterCollection = await GetCollection(); // Create route filter string filterName = Recording.GenerateAssetName("filter"); string ruleName = Recording.GenerateAssetName("rule"); RouteFilter filter = await CreateDefaultRouteFilter(filterCollection, filterName); Assert.AreEqual("Succeeded", filter.Data.ProvisioningState.ToString()); Assert.AreEqual(filterName, filter.Data.Name); Assert.IsEmpty(filter.Data.Rules); var filters = await filterCollection.GetAllAsync().ToEnumerableAsync(); Has.One.Equals(filters); Assert.AreEqual(filterName, filters[0].Data.Name); Assert.IsEmpty(filters[0].Data.Rules); var allFilters = await subscription.GetRouteFiltersAsync().ToEnumerableAsync(); // there could be other filters in the current subscription Assert.True(allFilters.Any(f => filterName == f.Data.Name && f.Data.Rules.Count == 0)); // Crete route filter rule RouteFilterRule filterRule = await CreateDefaultRouteFilterRule(filter, ruleName); Assert.AreEqual("Succeeded", filterRule.Data.ProvisioningState.ToString()); Assert.AreEqual(ruleName, filterRule.Data.Name); Response <RouteFilter> getFilterResponse = await filterCollection.GetAsync(filterName); Assert.AreEqual(filterName, getFilterResponse.Value.Data.Name); filter = await filterCollection.GetAsync(filterName); Assert.AreEqual(filterName, filter.Data.Name); Has.One.Equals(filter.Data.Rules); Assert.AreEqual(ruleName, filter.Data.Rules[0].Name); filterRule = await filter.GetRouteFilterRules().GetAsync(ruleName); Assert.AreEqual(ruleName, filterRule.Data.Name); // Update route filter filterRule.Data.Access = Access.Deny; filterRule = await filter.GetRouteFilterRules().CreateOrUpdate(ruleName, filterRule.Data).WaitForCompletionAsync(); Assert.AreEqual(ruleName, filterRule.Data.Name); Assert.AreEqual(Access.Deny, filterRule.Data.Access); // Add filter rule, this will fail due to the limitation of maximum 1 rule per filter Assert.ThrowsAsync <RequestFailedException>(async() => await CreateDefaultRouteFilterRule(filter, Recording.GenerateAssetName("rule2"))); filter = await filterCollection.GetAsync(filterName); Has.One.Equals(filter.Data.Rules); Assert.AreEqual(ruleName, filter.Data.Rules[0].Name); // Delete fileter rule await filterRule.DeleteAsync(); var rules = await filter.GetRouteFilterRules().GetAllAsync().ToEnumerableAsync(); Assert.IsEmpty(rules); // Delete filter await filter.DeleteAsync(); allFilters = await subscription.GetRouteFiltersAsync().ToEnumerableAsync(); Assert.False(allFilters.Any(f => filter.Id == f.Id)); }
public virtual RouteFilterRulesCreateOrUpdateOperation StartCreateOrUpdate(string resourceGroupName, string routeFilterName, string ruleName, RouteFilterRule routeFilterRuleParameters, CancellationToken cancellationToken = default) { if (resourceGroupName == null) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (routeFilterName == null) { throw new ArgumentNullException(nameof(routeFilterName)); } if (ruleName == null) { throw new ArgumentNullException(nameof(ruleName)); } if (routeFilterRuleParameters == null) { throw new ArgumentNullException(nameof(routeFilterRuleParameters)); } using var scope = _clientDiagnostics.CreateScope("RouteFilterRulesOperations.StartCreateOrUpdate"); scope.Start(); try { var originalResponse = RestClient.CreateOrUpdate(resourceGroupName, routeFilterName, ruleName, routeFilterRuleParameters, cancellationToken); return(new RouteFilterRulesCreateOrUpdateOperation(_clientDiagnostics, _pipeline, RestClient.CreateCreateOrUpdateRequest(resourceGroupName, routeFilterName, ruleName, routeFilterRuleParameters).Request, originalResponse)); } catch (Exception e) { scope.Failed(e); throw; } }