public async Task ListNetworkDomains_Paged_Success() { CloudControlClient client = CreateCloudControlClientWithUserAccount(request => { MessageAssert.AcceptsMediaType(request, "application/json" ); MessageAssert.HasRequestUri(request, CreateApiUri($"caas/2.4/{TestOrganizationId}/network/networkDomain?datacenterId=AU9&pageNumber=1&pageSize=250") ); return(request.CreateResponse(HttpStatusCode.OK, responseBody: TestResponses.ListNetworkDomains_Success, mediaType: "application/json" )); }); using (client) { NetworkDomainQuery query = NetworkDomainQuery.ByDatacenter("AU9"); Paging paging = new Paging { PageNumber = 1, PageSize = 250 }; NetworkDomains networkDomains = await client.ListNetworkDomains(query, paging); Assert.NotNull(networkDomains); Assert.Equal(2, networkDomains.TotalCount); Assert.Equal(2, networkDomains.Items.Count); } }
/// <summary> /// Retrieve a list of network domains in the specified datacenter. /// </summary> /// <param name="query"> /// A <see cref="NetworkDomainQuery"/> that determines which network domains are retrieved. /// </param> /// <param name="paging"> /// An optional <see cref="Paging"/> configuration for the results. /// </param> /// <param name="cancellationToken"> /// An optional cancellation token that can be used to cancel the request. /// </param> /// <returns> /// A <see cref="NetworkDomains"/> representing the page of results. /// </returns> public async Task <NetworkDomains> ListNetworkDomains(NetworkDomainQuery query, Paging paging = null, CancellationToken cancellationToken = default(CancellationToken)) { if (query == null) { throw new ArgumentNullException(nameof(query)); } Guid organizationId = await GetOrganizationId(); HttpRequest request = Requests.Network.ListNetworkDomains .WithTemplateParameters(new { organizationId, networkDomainName = query.Name, datacenterId = query.DatacenterId }) .WithPaging(paging); using (HttpResponseMessage response = await _httpClient.GetAsync(request, cancellationToken)) { if (!response.IsSuccessStatusCode) { throw await CloudControlException.FromApiV2Response(response); } return(await response.ReadContentAsAsync <NetworkDomains>()); } }
/// <summary> /// List network domains in the specified datacenter. /// </summary> /// <param name="client"> /// The CloudControl API client. /// </param> /// <param name="datacenterId"> /// The Id of the datacenter containing the network domain to retrieve. /// </param> /// <param name="paging"> /// An optional <see cref="Paging"/> configuration for the results. /// </param> /// <param name="cancellationToken"> /// An optional cancellation token that can be used to cancel the request. /// </param> /// <returns> /// The network domains (as <see cref="NetworkDomains"/>). /// </returns> public static Task <NetworkDomains> ListNetworkDomains(this CloudControlClient client, string datacenterId, Paging paging, CancellationToken cancellationToken = default(CancellationToken)) { if (client == null) { throw new ArgumentNullException(nameof(client)); } NetworkDomainQuery query = NetworkDomainQuery.ByDatacenter(datacenterId); return(client.ListNetworkDomains(query, paging, cancellationToken)); }
/// <summary> /// Retrieve the first network domain in the specified datacenter with the specified name. /// </summary> /// <param name="client"> /// The CloudControl API client. /// </param> /// <param name="name"> /// The name of the network domain to retrieve. /// </param> /// <param name="datacenterId"> /// The Id of the datacenter containing the network domain to retrieve. /// </param> /// <param name="cancellationToken"> /// An optional cancellation token that can be used to cancel the request. /// </param> /// <returns> /// A <see cref="NetworkDomain"/> representing the network domain, or <c>null</c> if no network domain was found with the specified Id. /// </returns> public static async Task <NetworkDomain> GetNetworkDomainByName(this CloudControlClient client, string name, string datacenterId, CancellationToken cancellationToken = default(CancellationToken)) { if (client == null) { throw new ArgumentNullException(nameof(client)); } NetworkDomainQuery query = NetworkDomainQuery.ByNameAndDatacenter(name, datacenterId); NetworkDomains matchingNetworkDomains = await client.ListNetworkDomains(query, cancellationToken : cancellationToken); return(matchingNetworkDomains.Items.FirstOrDefault()); }
public async Task Client_ListNetworkDomains_AU9() { CloudControlClient client = CloudControlClient.Create( baseUri: new Uri("https://api-au.dimensiondata.com/"), userName: Credentials.User, password: Credentials.Password ); using (client) { Paging page = new Paging { PageSize = 20 }; NetworkDomainQuery query = NetworkDomainQuery.ByDatacenter("AU9"); NetworkDomains networkDomains = await client.ListNetworkDomains(query, page); int expectedTotalCount = networkDomains.TotalCount; int totalCount = 0; while (!networkDomains.IsEmpty) { totalCount += networkDomains.PageCount; foreach (NetworkDomain networkDomain in networkDomains) { Console.WriteLine("NetworkDomain: " + networkDomain.Name); } page++; networkDomains = await client.ListNetworkDomains(query, page); } Assert.Equal(expectedTotalCount, totalCount); } }