Esempio n. 1
0
        public async Task ListVlans_Paged_Success()
        {
            CloudControlClient client = CreateCloudControlClientWithUserAccount(request =>
            {
                MessageAssert.AcceptsMediaType(request,
                                               "application/json"
                                               );
                MessageAssert.HasRequestUri(request,
                                            CreateApiUri($"caas/2.4/{TestOrganizationId}/network/vlan?networkDomainId=909dd855-4b2c-49a9-8151-46969a1a9380&pageNumber=1&pageSize=250")
                                            );

                return(request.CreateResponse(HttpStatusCode.OK,
                                              responseBody: TestResponses.ListVlans_Success,
                                              mediaType: "application/json"
                                              ));
            });

            using (client)
            {
                Vlans vlans = await client.ListVlans(
                    networkDomainId : new Guid("909dd855-4b2c-49a9-8151-46969a1a9380"),
                    paging : new Paging
                {
                    PageNumber = 1,
                    PageSize   = 250
                }
                    );

                Assert.NotNull(vlans);
                Assert.Equal(1, vlans.TotalCount);
                Assert.Equal(1, vlans.Items.Count);
            }
        }
Esempio n. 2
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());
        }
        /// <summary>
        ///     Asynchronously perform Cmdlet processing.
        /// </summary>
        /// <param name="cancellationToken">
        ///     A <see cref="CancellationToken"/> that can be used to cancel Cmdlet processing.
        /// </param>
        /// <returns>
        ///     A <see cref="Task"/> representing the asynchronous operation.
        /// </returns>
        protected override async Task ProcessRecordAsync(CancellationToken cancellationToken)
        {
            CloudControlClient client = GetClient();

            switch (ParameterSetName)
            {
            case "By network domain":
            {
                Paging paging = GetPagingConfiguration();

                Vlans vlans = await client.ListVlans(NetworkDomainId, paging, cancellationToken);

                WriteObject(vlans.Items,
                            enumerateCollection: true
                            );

                break;
            }

            case "By Id":
            {
                Vlan vlan = await client.GetVlan(Id, cancellationToken);

                if (vlan == null)
                {
                    WriteError(
                        Errors.ResourceNotFoundById <Vlan>(Id)
                        );
                }
                else
                {
                    WriteObject(vlan);
                }

                break;
            }

            case "By name":
            {
                Vlan vlan = await client.GetVlanByName(Name, NetworkDomainId);

                if (vlan == null)
                {
                    WriteError(
                        Errors.ResourceNotFoundByName <Vlan>(Name,
                                                             message: $"No network domain named '{Name}' was found in network domain '{NetworkDomainId}'."
                                                             )
                        );
                }
                else
                {
                    WriteObject(vlan);
                }

                break;
            }

            default:
            {
                ThrowTerminatingError(
                    Errors.UnrecognizedParameterSet(this)
                    );

                return;
            }
            }
        }