/// <summary> /// The new peering service from resource group and name. /// </summary> /// <returns> /// The <see cref="PSPeeringService"/>. /// </returns> /// <exception cref="ItemNotFoundException"> /// </exception> /// <exception cref="ErrorResponseException"> /// </exception> private PSPeeringService NewPeeringServiceFromResourceGroupAndName() { try { var location = this.PeeringServiceLocationsClient.List(); var CheckProvider = this.PeeringManagementClient.CheckServiceProviderAvailability(this.PeeringLocation, this.PeeringServiceProvider); if (!CheckProvider.Equals(Constants.Available, StringComparison.InvariantCultureIgnoreCase)) { throw new ItemNotFoundException(string.Format(Resources.Error_ProviderNotFound, this.PeeringServiceProvider, this.PeeringLocation, CheckProvider)); } var peeringService = new PeeringService { Location = location.Select(ToPeeringServiceLocationPS).ToList().Find(x => x.State.Equals(this.PeeringLocation.Trim(), StringComparison.InvariantCultureIgnoreCase)).AzureRegion, PeeringServiceLocation = this.PeeringLocation.Trim(), PeeringServiceProvider = this.PeeringServiceProvider.Trim(), Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, true) }; if (this.ShouldProcess(string.Format(Resources.ShouldProcessMessage, $"a peering service with resource group:{this.ResourceGroupName} and name:{this.Name}."))) { this.PeeringServicesClient.CreateOrUpdate(this.ResourceGroupName, this.Name, peeringService); return(this.ToPeeringServicePS(this.PeeringServicesClient.Get(this.ResourceGroupName, this.Name))); } return(this.ToPeeringServicePS(peeringService)); } catch (ErrorResponseException ex) { var error = this.GetErrorCodeAndMessageFromArmOrErm(ex); throw new ErrorResponseException(string.Format(Resources.Error_CloudError, error?.Code, error?.Message)); } }
/// <summary> /// The delete peering service. /// </summary> /// <param name="name"> /// The name. /// </param> /// <param name="resourceGroupName"> /// The resource group name. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> private bool DeletePeeringService(string name, string resourceGroupName) { PeeringService service = null; try { this.Client.PeeringServices.Delete(resourceGroupName, name); //service = this.client.PeeringServices.Get(resourceGroupName, name); return(service == null); } catch (Exception ex) { Assert.Null(service); Assert.NotNull(ex.Message); return(false); } }
private bool DeletePeeringService(MockContext context, string name, string resourceGroupName) { this.client = context.GetServiceClient <PeeringManagementClient>(); PeeringService service = null; try { this.client.PeeringServices.Delete(resourceGroupName, name); //service = this.client.PeeringServices.Get(resourceGroupName, name); if (service == null) { return(true); } return(false); } catch (Exception ex) { Assert.Null(service); Assert.NotNull(ex.Message); return(false); } }
public void CreatePeeringService() { using (var context = MockContext.Start(this.GetType().FullName)) { this.client = context.GetServiceClient <PeeringManagementClient>(); //Create a Resource Group this.resourcesClient = context.GetServiceClient <ResourceManagementClient>(); var rgname = TestUtilities.GenerateName("res"); var resourceGroup = resourcesClient.ResourceGroups.CreateOrUpdate( rgname, new ResourceGroup { Location = "centralus" }); //List Locations var peeringServiceLocations = this.client.PeeringServiceLocations.List().ToList(); Assert.NotNull(peeringServiceLocations); var location = peeringServiceLocations.Find(s => s.Name == "New York"); Assert.NotNull(location); //List Providers var listProviders = this.client.PeeringServiceProviders.List().ToList(); Assert.NotNull(listProviders); var myProvider = listProviders.Find(p => p.ServiceProviderName == "TestPeer1"); //Create Peering Service var peeringService = new PeeringService { Location = location.AzureRegion, PeeringServiceLocation = location.Name, PeeringServiceProvider = myProvider.Name, }; var name = TestUtilities.GenerateName("myPeeringService"); var prefixName = "AS54733Prefix"; try { var result = this.client.PeeringServices.CreateOrUpdate(rgname, name, peeringService); Assert.NotNull(result); Assert.Equal(name, result.Name); } catch (Exception ex) { Assert.True(this.DeletePeeringService(context, name, rgname)); Assert.Contains("NotFound", ex.Message); } try { var prefix = new PeeringServicePrefix { Prefix = "10.10.10.2", }; var peeringServicePrefix = this.client.PeeringServicePrefixes.CreateOrUpdate(rgname, name, prefixName, prefix); Assert.NotNull(peeringServicePrefix); Assert.Equal(prefixName, peeringServicePrefix.Name); //var servicePrefix = this.client.PeeringServicePrefixes.Get(rgname, name, prefixName); //Assert.NotNull(servicePrefix); } catch (Exception ex) { Assert.Contains("NotFound", ex.Message); } finally { } } }
public void CreatePeeringService() { using (MockContext context = MockContext.Start(this.GetType().FullName)) { this.MockClients(context); // Create a Resource Group var rgname = TestUtilities.GenerateName("res"); var resourceGroup = this.ResourcesClient.ResourceGroups.CreateOrUpdate( rgname, new ResourceGroup { Location = "centralus" }); // List Locations var peeringServiceLocations = this.Client.PeeringServiceLocations.List().ToList(); Assert.NotNull(peeringServiceLocations); var location = peeringServiceLocations.Find(s => s.Name == "Washington"); Assert.NotNull(location); // List Providers var listProviders = this.Client.PeeringServiceProviders.List().ToList(); Assert.NotNull(listProviders); PeeringServiceProvider myProvider = null; foreach (var provider in listProviders) { var isAvailable = this.Client.CheckServiceProviderAvailability( location.State, provider.Name); if (isAvailable == "Available") { myProvider = provider; break; } } // Create Peering Service var peeringService = new PeeringService { Location = location.AzureRegion, PeeringServiceLocation = location.Name, PeeringServiceProvider = myProvider?.Name, }; var name = TestUtilities.GenerateName("myPeeringService"); var prefixName = "AS54733Prefix"; try { var result = this.Client.PeeringServices.CreateOrUpdate(rgname, name, peeringService); Assert.NotNull(result); Assert.Equal(name, result.Name); } catch (Exception ex) { Assert.True(this.DeletePeeringService(name, rgname)); Assert.Contains("NotFound", ex.Message); } try { var prefix = new PeeringServicePrefix { Prefix = "34.56.10.0/24", PeeringServicePrefixKey = TestUtilities.GenerateGuid().ToString() }; var peeringServicePrefix = this.Client.Prefixes.CreateOrUpdate( rgname, name, prefixName, prefix.Prefix, prefix.PeeringServicePrefixKey); Assert.NotNull(peeringServicePrefix); Assert.Equal(prefixName, peeringServicePrefix.Name); // var servicePrefix = this.client.PeeringServicePrefixes.Get(rgname, name, prefixName); // Assert.NotNull(servicePrefix); } catch (Exception ex) { Assert.Contains("BadRequest", ex.Message); } finally { Assert.True(this.DeletePeeringService(name, rgname)); } } }
/// <summary> /// Creates a new peering service or updates an existing peering with the /// specified name under the given subscription and resource group. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='peeringServiceName'> /// The name of the peering service. /// </param> /// <param name='peeringService'> /// The properties needed to create or update a peering service. /// </param> public static PeeringService CreateOrUpdate(this IPeeringServicesOperations operations, string resourceGroupName, string peeringServiceName, PeeringService peeringService) { return(operations.CreateOrUpdateAsync(resourceGroupName, peeringServiceName, peeringService).GetAwaiter().GetResult()); }
/// <summary> /// Creates a new peering service or updates an existing peering with the /// specified name under the given subscription and resource group. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='peeringServiceName'> /// The name of the peering service. /// </param> /// <param name='peeringService'> /// The properties needed to create or update a peering service. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <PeeringService> CreateOrUpdateAsync(this IPeeringServicesOperations operations, string resourceGroupName, string peeringServiceName, PeeringService peeringService, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, peeringServiceName, peeringService, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }