コード例 #1
0
        /// <summary>
        ///     Retrieve a list of VLANs.
        /// </summary>
        /// <param name="query">
        ///     A <see cref="VlanQuery"/> that determines which VLANs will be 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="Vlans"/> representing the page of results.
        /// </returns>
        public async Task <Vlans> ListVlans(VlanQuery query, Paging paging = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            Guid organizationId = await GetOrganizationId();

            HttpRequest request = Requests.Network.ListVlans
                                  .WithTemplateParameters(new
            {
                organizationId,
                vlanName        = query.Name,
                networkDomainId = query.NetworkDomainId
            })
                                  .WithPaging(paging);

            using (HttpResponseMessage response = await _httpClient.GetAsync(request, cancellationToken))
            {
                if (!response.IsSuccessStatusCode)
                {
                    throw await CloudControlException.FromApiV2Response(response);
                }

                return(await response.ReadContentAsAsync <Vlans>());
            }
        }
コード例 #2
0
        /// <summary>
        ///     Retrieve a list of VLANs in the specified network domain.
        /// </summary>
        /// <param name="client">
        ///     The CloudControl API client.
        /// </param>
        /// <param name="networkDomainId">
        ///     The Id of the target network domain.
        /// </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="Vlans"/> representing the page of results.
        /// </returns>
        public static Task <Vlans> ListVlans(this CloudControlClient client, Guid networkDomainId, Paging paging = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            VlanQuery query = VlanQuery.ByNetworkDomain(networkDomainId);

            return(client.ListVlans(query, paging, cancellationToken));
        }
コード例 #3
0
        /// <summary>
        ///     Retrieve a specific VLAN by name and network domain.
        /// </summary>
        /// <param name="client">
        ///     The CloudControl API client.
        /// </param>
        /// <param name="name">
        ///     The name of the VLAN to retrieve.
        /// </param>
        /// <param name="networkDomainId">
        ///     The Id of the network domain containing the VLAN 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 VLAN, or <c>null</c> if no network domain was found with the specified Id.
        /// </returns>
        public static async Task <Vlan> GetVlanByName(this CloudControlClient client, string name, Guid networkDomainId, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            VlanQuery query = VlanQuery.ByNameAndNetworkDomain(name, networkDomainId);

            Vlans matchingVlans = await client.ListVlans(query,
                                                         cancellationToken : cancellationToken
                                                         );

            return(matchingVlans.Items.FirstOrDefault());
        }