/// <summary>
 /// Creates a firewall rule.
 /// </summary>
 /// <param name="createFirewallRule">The firewall rule details.</param>
 /// <returns>The response details.</returns>
 public async Task <ResponseType> CreateFirewallRule(CreateFirewallRuleType createFirewallRule)
 {
     return(await _api.PostAsync <CreateFirewallRuleType, ResponseType>(
                ApiUris.CreateFirewallRule(_api.OrganizationId),
                createFirewallRule));
 }
示例#2
0
        /// <summary>
        ///     The process record method.
        /// </summary>
        protected override void ProcessRecord()
        {
            ResponseType response = null;

            base.ProcessRecord();
            try
            {
                RulePlacementType rulePlacement = new RulePlacementType
                {
                    position = Position
                };

                if (Position == RulePositionType.AFTER || Position == RulePositionType.BEFORE)
                {
                    if (RelativeToRule == null)
                    {
                        ThrowTerminatingError(
                            new ErrorRecord(
                                new ArgumentException("For relative rule placement, please provide the RelativeRule"), "-3", ErrorCategory.InvalidArgument, Connection));
                        return;
                    }

                    rulePlacement.relativeToRule = RelativeToRule.name;
                }

                var firewall = new CreateFirewallRuleType
                {
                    networkDomainId = NetworkDomain.id,
                    name            = FirewallRuleName,
                    ipVersion       = IpVersion.ToString(),
                    protocol        = Protocol.ToString(),
                    action          = FirewallAction,
                    source          = Source,
                    destination     = Destination,
                    placement       = rulePlacement,
                    enabled         = Enabled
                };

                response = Connection.ApiClient.Networking.FirewallRule.CreateFirewallRule(firewall).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);
        }