<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# (c) 2015, <NAME> <<EMAIL>>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.

DOCUMENTATION = '''
module: cloudstack_fw
short_description: Manages firewall rules on Apache CloudStack based clouds.
description: Creates and removes firewall rules.
version_added: '2.0'
author: <NAME>
options:
  ip_address:
    description:
      - Public IP address the rule is assigned to.
    required: true
  state:
    description:
      - State of the firewall rule.
    required: false
    default: 'present'
    choices: [ 'present', 'absent' ]
  protocol:
    description:
      - Protocol of the firewall rule.
    required: false
    default: 'tcp'
    choices: [ 'tcp', 'udp', 'icmp' ]
  cidr:
    description:
      - CIDR (full notation) to be used for firewall rule.
    required: false
    default: '0.0.0.0\0'
  start_port
    description:
      - Start port for this rule. Considered if C(protocol=tcp) or C(protocol=udp).
    required: false
    default: null
  end_port
    description:
      - End port for this rule. Considered if C(protocol=tcp) or C(protocol=udp).
    required: false
    default: null
  icmp_type
    description:
      - Type of the icmp message being sent. Considered if C(protocol=icmp).
    required: false
    default: null
  icmp_code
    description:
      - Error code for this icmp message. Considered if C(protocol=icmp).
    required: false
    default: null
  project:
    description:
      - Name of the project.
    required: false
    default: null
'''

EXAMPLES = '''
---
# Allow inbound port 80/tcp from 1.2.3.4 to 4.3.2.1
- local_action:
    module: cloudstack_fw
    ip_address: 4.3.2.1
    start_port: 80
    end_port: 80
    cidr: 1.2.3.4/32


# Allow inbound tcp/udp port 53 to 4.3.2.1
- local_action:
    module: cloudstack_fw
    ip_address: 4.3.2.1
    start_port: 53
    end_port: 53
    protocol: '{{ item }}'
  with_items:
  - tcp
  - udp


# Ensure firewall rule is removed
- local_action:
    module: cloudstack_fw
    ip_address: 4.3.2.1
    start_port: 8000
    end_port: 8888
    cidr: 172.16.17.32/8
    state: absent
'''

RETURN = '''
'''

try:
    from cs import CloudStack, CloudStackException, read_config
    has_lib_cs = True
except ImportError:
    has_lib_cs = False

# import cloudstack common
from ansible.module_utils.cloudstack import *


class AnsibleCloudStackFirewall(AnsibleCloudStack):<commit_msg>fixed doc issues with cloudstack_fw<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# (c) 2015, <NAME> <<EMAIL>>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.

DOCUMENTATION = '''
module: cloudstack_fw
short_description: Manages firewall rules on Apache CloudStack based clouds.
description: Creates and removes firewall rules.
version_added: '2.0'
author: <NAME>
options:
  ip_address:
    description:
      - Public IP address the rule is assigned to.
    required: true
  state:
    description:
      - State of the firewall rule.
    required: false
    default: 'present'
    choices: [ 'present', 'absent' ]
  protocol:
    description:
      - Protocol of the firewall rule.
    required: false
    default: 'tcp'
    choices: [ 'tcp', 'udp', 'icmp' ]
  cidr:
    description:
      - CIDR (full notation) to be used for firewall rule.
    required: false
    default: '0.0.0.0/0'
  start_port:
    description:
      - Start port for this rule. Considered if C(protocol=tcp) or C(protocol=udp).
    required: false
    default: null
  end_port:
    description:
      - End port for this rule. Considered if C(protocol=tcp) or C(protocol=udp).
    required: false
    default: null
  icmp_type:
    description:
      - Type of the icmp message being sent. Considered if C(protocol=icmp).
    required: false
    default: null
  icmp_code:
    description:
      - Error code for this icmp message. Considered if C(protocol=icmp).
    required: false
    default: null
  project:
    description:
      - Name of the project.
    required: false
    default: null
'''

EXAMPLES = '''
---
# Allow inbound port 80/tcp from 1.2.3.4 to 4.3.2.1
- local_action:
    module: cloudstack_fw
    ip_address: 4.3.2.1
    start_port: 80
    end_port: 80
    cidr: 1.2.3.4/32


# Allow inbound tcp/udp port 53 to 4.3.2.1
- local_action:
    module: cloudstack_fw
    ip_address: 4.3.2.1
    start_port: 53
    end_port: 53
    protocol: '{{ item }}'
  with_items:
  - tcp
  - udp


# Ensure firewall rule is removed
- local_action:
    module: cloudstack_fw
    ip_address: 4.3.2.1
    start_port: 8000
    end_port: 8888
    cidr: 172.16.17.32/8
    state: absent
'''

try:
    from cs import CloudStack, CloudStackException, read_config
    has_lib_cs = True
except ImportError:
    has_lib_cs = False

# import cloudstack common
from ansible.module_utils.cloudstack import *


class AnsibleCloudStackFirewall(AnsibleCloudStack):
{'fraction_non_alphanumeric': 0.0916419874958868, 'fraction_numerical': 0.024021059559065482, 'mean_word_length': 2.9888451443569553, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 18, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5323640', 'n_tokens_mistral': 2023, 'n_tokens_neox': 1916, 'n_words': 686}