예제 #1
0
        /// <summary>
        ///     The process record method.
        /// </summary>
        protected override void ProcessRecord()
        {
            ResponseType response = null;

            base.ProcessRecord();
            try
            {
                if (NetworkDomain != null)
                {
                    NetworkDomainId = NetworkDomain.id;
                }

                if (ChildIpAddressList != null && ChildIpAddressList.Length > 0)
                {
                    ChildIpAddressListId = ChildIpAddressList.Select(x => x.id).ToArray();
                }

                var ipAddressList = new createIpAddressList
                {
                    networkDomainId      = NetworkDomainId,
                    name                 = Name,
                    description          = Description,
                    ipVersion            = IpVersion.ToString(),
                    childIpAddressListId = ChildIpAddressListId,
                    ipAddress            = IpAddress != null
                        ? IpAddress.Select(x => new IpAddressRangeType
                    {
                        begin               = x.Begin,
                        end                 = x.End,
                        prefixSize          = x.PrefixSize ?? 0,
                        prefixSizeSpecified = x.PrefixSize.HasValue
                    }).ToArray()
                        : null,
                };

                response = Connection.ApiClient.Networking.FirewallRule.CreateIpAddressList(ipAddressList).Result;
            }
            catch (AggregateException ae)
            {
                ae.Handle(
                    e =>
                {
                    if (e is ComputeApiException)
                    {
                        WriteError(new ErrorRecord(e, "-2", ErrorCategory.InvalidOperation, Connection));
                    }
                    else
                    {
                        // if (e is HttpRequestException)
                        ThrowTerminatingError(new ErrorRecord(e, "-1", ErrorCategory.ConnectionError, Connection));
                    }

                    return(true);
                });
            }

            WriteObject(response);
        }
 /// <summary>
 /// Creates an ip address list.
 /// </summary>
 /// <param name="createIpAddressList">The ip address list details.</param>
 /// <returns>The response details.</returns>
 public async Task <ResponseType> CreateIpAddressList(createIpAddressList createIpAddressList)
 {
     return(await _api.PostAsync <createIpAddressList, ResponseType>(
                ApiUris.CreateIpAddressList(_api.OrganizationId),
                createIpAddressList));
 }