| 1 |
|
| 2 |
from __future__ import absolute_import, division, print_function |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
__metaclass__ = type |
| 7 |
|
| 8 |
ANSIBLE_METADATA = {'status': ['preview'], |
| 9 |
'supported_by': 'community', |
| 10 |
'metadata_version': '1.1'} |
| 11 |
|
| 12 |
DOCUMENTATION = ''' |
| 13 |
--- |
| 14 |
module: fmgr_pkg_firewall_shapingpolicy |
| 15 |
short_description: Configure shaping policies. |
| 16 |
version_added: "2.0.0" |
| 17 |
extends_documentation_fragment: |
| 18 |
- fortinet.fortimanager.general |
| 19 |
- fortinet.fortimanager.general.full_crud |
| 20 |
options: |
| 21 |
revision_note: |
| 22 |
description: The change note that can be specified when an object is created or updated. |
| 23 |
type: str |
| 24 |
adom: |
| 25 |
description: The parameter (adom) in requested url. |
| 26 |
type: str |
| 27 |
required: true |
| 28 |
pkg: |
| 29 |
description: The parameter (pkg) in requested url. |
| 30 |
type: str |
| 31 |
required: true |
| 32 |
pkg_firewall_shapingpolicy: |
| 33 |
description: The top level parameters set. |
| 34 |
required: false |
| 35 |
type: dict |
| 36 |
suboptions: |
| 37 |
app_category: |
| 38 |
aliases: ['app-category'] |
| 39 |
type: raw |
| 40 |
description: (list or str) IDs of one or more application categories that this shaper applies application control traffic shaping to. |
| 41 |
application: |
| 42 |
type: raw |
| 43 |
description: (list) IDs of one or more applications that this shaper applies application control traffic shaping to. |
| 44 |
dstaddr: |
| 45 |
type: raw |
| 46 |
description: (list or str) IPv4 destination address and address group names. |
| 47 |
dstaddr6: |
| 48 |
type: raw |
| 49 |
description: (list or str) IPv6 destination address and address group names. |
| 50 |
dstintf: |
| 51 |
type: raw |
| 52 |
description: (list or str) One or more outgoing |
| 53 |
groups: |
| 54 |
type: raw |
| 55 |
description: (list or str) Apply this traffic shaping policy to user groups that have authenticated with the FortiGate. |
| 56 |
id: |
| 57 |
type: int |
| 58 |
description: Shaping policy ID. |
| 59 |
required: true |
| 60 |
ip_version: |
| 61 |
aliases: ['ip-version'] |
| 62 |
type: str |
| 63 |
description: Apply this traffic shaping policy to IPv4 or IPv6 traffic. |
| 64 |
choices: ['4', '6'] |
| 65 |
per_ip_shaper: |
| 66 |
aliases: ['per-ip-shaper'] |
| 67 |
type: str |
| 68 |
description: Per-IP traffic shaper to apply with this policy. |
| 69 |
schedule: |
| 70 |
type: str |
| 71 |
description: Schedule name. |
| 72 |
service: |
| 73 |
type: raw |
| 74 |
description: (list or str) Service and service group names. |
| 75 |
srcaddr: |
| 76 |
type: raw |
| 77 |
description: (list or str) IPv4 source address and address group names. |
| 78 |
srcaddr6: |
| 79 |
type: raw |
| 80 |
description: (list or str) IPv6 source address and address group names. |
| 81 |
status: |
| 82 |
type: str |
| 83 |
description: Enable/disable this traffic shaping policy. |
| 84 |
choices: ['disable', 'enable'] |
| 85 |
traffic_shaper: |
| 86 |
aliases: ['traffic-shaper'] |
| 87 |
type: str |
| 88 |
description: Traffic shaper to apply to traffic forwarded by the firewall policy. |
| 89 |
traffic_shaper_reverse: |
| 90 |
aliases: ['traffic-shaper-reverse'] |
| 91 |
type: str |
| 92 |
description: Traffic shaper to apply to response traffic received by the firewall policy. |
| 93 |
url_category: |
| 94 |
aliases: ['url-category'] |
| 95 |
type: raw |
| 96 |
description: (list or str) IDs of one or more FortiGuard Web Filtering categories that this shaper applies traffic shaping to. |
| 97 |
users: |
| 98 |
type: raw |
| 99 |
description: (list or str) Apply this traffic shaping policy to individual users that have authenticated with the FortiGate. |
| 100 |
app_group: |
| 101 |
aliases: ['app-group'] |
| 102 |
type: raw |
| 103 |
description: (list or str) One or more application group names. |
| 104 |
class_id: |
| 105 |
aliases: ['class-id'] |
| 106 |
type: raw |
| 107 |
description: (int or str) Traffic class ID. |
| 108 |
comment: |
| 109 |
type: str |
| 110 |
description: Comments. |
| 111 |
diffserv_forward: |
| 112 |
aliases: ['diffserv-forward'] |
| 113 |
type: str |
| 114 |
description: Enable to change packets DiffServ values to the specified diffservcode-forward value. |
| 115 |
choices: ['disable', 'enable'] |
| 116 |
diffserv_reverse: |
| 117 |
aliases: ['diffserv-reverse'] |
| 118 |
type: str |
| 119 |
description: Enable to change packets reverse |
| 120 |
choices: ['disable', 'enable'] |
| 121 |
diffservcode_forward: |
| 122 |
aliases: ['diffservcode-forward'] |
| 123 |
type: str |
| 124 |
description: Change packets DiffServ to this value. |
| 125 |
diffservcode_rev: |
| 126 |
aliases: ['diffservcode-rev'] |
| 127 |
type: str |
| 128 |
description: Change packets reverse |
| 129 |
internet_service: |
| 130 |
aliases: ['internet-service'] |
| 131 |
type: str |
| 132 |
description: Enable/disable use of Internet Services for this policy. |
| 133 |
choices: ['disable', 'enable'] |
| 134 |
internet_service_custom: |
| 135 |
aliases: ['internet-service-custom'] |
| 136 |
type: raw |
| 137 |
description: (list or str) Custom Internet Service name. |
| 138 |
internet_service_custom_group: |
| 139 |
aliases: ['internet-service-custom-group'] |
| 140 |
type: raw |
| 141 |
description: (list or str) Custom Internet Service group name. |
| 142 |
internet_service_group: |
| 143 |
aliases: ['internet-service-group'] |
| 144 |
type: raw |
| 145 |
description: (list or str) Internet Service group name. |
| 146 |
internet_service_id: |
| 147 |
aliases: ['internet-service-id'] |
| 148 |
type: raw |
| 149 |
description: (list or str) Internet Service ID. |
| 150 |
internet_service_src: |
| 151 |
aliases: ['internet-service-src'] |
| 152 |
type: str |
| 153 |
description: Enable/disable use of Internet Services in source for this policy. |
| 154 |
choices: ['disable', 'enable'] |
| 155 |
internet_service_src_custom: |
| 156 |
aliases: ['internet-service-src-custom'] |
| 157 |
type: raw |
| 158 |
description: (list or str) Custom Internet Service source name. |
| 159 |
internet_service_src_custom_group: |
| 160 |
aliases: ['internet-service-src-custom-group'] |
| 161 |
type: raw |
| 162 |
description: (list or str) Custom Internet Service source group name. |
| 163 |
internet_service_src_group: |
| 164 |
aliases: ['internet-service-src-group'] |
| 165 |
type: raw |
| 166 |
description: (list or str) Internet Service source group name. |
| 167 |
internet_service_src_id: |
| 168 |
aliases: ['internet-service-src-id'] |
| 169 |
type: raw |
| 170 |
description: (list or str) Internet Service source ID. |
| 171 |
name: |
| 172 |
type: str |
| 173 |
description: Shaping policy name. |
| 174 |
srcintf: |
| 175 |
type: raw |
| 176 |
description: (list or str) One or more incoming |
| 177 |
tos: |
| 178 |
type: str |
| 179 |
description: ToS |
| 180 |
tos_mask: |
| 181 |
aliases: ['tos-mask'] |
| 182 |
type: str |
| 183 |
description: Non-zero bit positions are used for comparison while zero bit positions are ignored. |
| 184 |
tos_negate: |
| 185 |
aliases: ['tos-negate'] |
| 186 |
type: str |
| 187 |
description: Enable negated TOS match. |
| 188 |
choices: ['disable', 'enable'] |
| 189 |
uuid: |
| 190 |
type: str |
| 191 |
description: Universally Unique Identifier |
| 192 |
internet_service_name: |
| 193 |
aliases: ['internet-service-name'] |
| 194 |
type: raw |
| 195 |
description: (list or str) Internet Service ID. |
| 196 |
internet_service_src_name: |
| 197 |
aliases: ['internet-service-src-name'] |
| 198 |
type: raw |
| 199 |
description: (list or str) Internet Service source name. |
| 200 |
cos: |
| 201 |
type: str |
| 202 |
description: VLAN CoS bit pattern. |
| 203 |
cos_mask: |
| 204 |
aliases: ['cos-mask'] |
| 205 |
type: str |
| 206 |
description: VLAN CoS evaluated bits. |
| 207 |
traffic_type: |
| 208 |
aliases: ['traffic-type'] |
| 209 |
type: str |
| 210 |
description: Traffic type. |
| 211 |
choices: ['forwarding', 'local-in', 'local-out'] |
| 212 |
class_id_reverse: |
| 213 |
aliases: ['class-id-reverse'] |
| 214 |
type: int |
| 215 |
description: Reverse class id. |
| 216 |
http_response_match: |
| 217 |
aliases: ['http-response-match'] |
| 218 |
type: str |
| 219 |
description: Http response match. |
| 220 |
choices: ['disable', 'enable'] |
| 221 |
service_type: |
| 222 |
aliases: ['service-type'] |
| 223 |
type: str |
| 224 |
description: Select service-type |
| 225 |
choices: ['service', 'internet-service'] |
| 226 |
internet_service_src_fortiguard: |
| 227 |
aliases: ['internet-service-src-fortiguard'] |
| 228 |
type: raw |
| 229 |
description: (list) FortiGuard Internet Service source name. |
| 230 |
internet_service_fortiguard: |
| 231 |
aliases: ['internet-service-fortiguard'] |
| 232 |
type: raw |
| 233 |
description: (list) FortiGuard Internet Service name. |
| 234 |
''' |
| 235 |
|
| 236 |
EXAMPLES = ''' |
| 237 |
- name: Example playbook |
| 238 |
hosts: fortimanagers |
| 239 |
gather_facts: false |
| 240 |
connection: httpapi |
| 241 |
vars: |
| 242 |
ansible_httpapi_use_ssl: true |
| 243 |
ansible_httpapi_validate_certs: false |
| 244 |
ansible_httpapi_port: 443 |
| 245 |
tasks: |
| 246 |
- name: Configure shaping policies. |
| 247 |
fortinet.fortimanager.fmgr_pkg_firewall_shapingpolicy: |
| 248 |
bypass_validation: false |
| 249 |
adom: ansible |
| 250 |
pkg: ansible # package name |
| 251 |
state: present |
| 252 |
pkg_firewall_shapingpolicy: |
| 253 |
dstaddr: all |
| 254 |
dstintf: any |
| 255 |
id: 1 |
| 256 |
ip_version: 4 # <value in [4, 6]> |
| 257 |
schedule: always |
| 258 |
service: ALL |
| 259 |
srcaddr: all |
| 260 |
status: disable |
| 261 |
|
| 262 |
- name: Gathering fortimanager facts |
| 263 |
hosts: fortimanagers |
| 264 |
gather_facts: false |
| 265 |
connection: httpapi |
| 266 |
vars: |
| 267 |
ansible_httpapi_use_ssl: true |
| 268 |
ansible_httpapi_validate_certs: false |
| 269 |
ansible_httpapi_port: 443 |
| 270 |
tasks: |
| 271 |
- name: Retrieve all the shaping policies |
| 272 |
fortinet.fortimanager.fmgr_fact: |
| 273 |
facts: |
| 274 |
selector: "pkg_firewall_shapingpolicy" |
| 275 |
params: |
| 276 |
adom: "ansible" |
| 277 |
pkg: "ansible" # package name |
| 278 |
shaping_policy: "your_value" |
| 279 |
''' |
| 280 |
|
| 281 |
RETURN = ''' |
| 282 |
meta: |
| 283 |
description: The result of the request. |
| 284 |
type: dict |
| 285 |
returned: always |
| 286 |
contains: |
| 287 |
request_url: |
| 288 |
description: The full url requested. |
| 289 |
returned: always |
| 290 |
type: str |
| 291 |
sample: /sys/login/user |
| 292 |
response_code: |
| 293 |
description: The status of api request. |
| 294 |
returned: always |
| 295 |
type: int |
| 296 |
sample: 0 |
| 297 |
response_data: |
| 298 |
description: The api response. |
| 299 |
type: list |
| 300 |
returned: always |
| 301 |
response_message: |
| 302 |
description: The descriptive message of the api response. |
| 303 |
type: str |
| 304 |
returned: always |
| 305 |
sample: OK. |
| 306 |
system_information: |
| 307 |
description: The information of the target system. |
| 308 |
type: dict |
| 309 |
returned: always |
| 310 |
rc: |
| 311 |
description: The status the request. |
| 312 |
type: int |
| 313 |
returned: always |
| 314 |
sample: 0 |
| 315 |
version_check_warning: |
| 316 |
description: Warning if the parameters used in the playbook are not supported by the current FortiManager version. |
| 317 |
type: list |
| 318 |
returned: complex |
| 319 |
''' |
| 320 |
from ansible.module_utils.basic import AnsibleModule |
| 321 |
from ansible.module_utils.connection import Connection |
| 322 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass |
| 323 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec |
| 324 |
|
| 325 |
|
| 326 |
def main(): |
| 327 |
urls_list = [ |
| 328 |
'/pm/config/adom/{adom}/pkg/{pkg}/firewall/shaping-policy' |
| 329 |
] |
| 330 |
module_arg_spec = { |
| 331 |
'adom': {'required': True, 'type': 'str'}, |
| 332 |
'pkg': {'required': True, 'type': 'str'}, |
| 333 |
'revision_note': {'type': 'str'}, |
| 334 |
'pkg_firewall_shapingpolicy': { |
| 335 |
'type': 'dict', 'v_range': [['6.0.0', '']], |
| 336 |
'options': { |
| 337 |
'app-category': {'type': 'raw'}, |
| 338 |
'application': {'type': 'raw'}, |
| 339 |
'dstaddr': {'type': 'raw'}, |
| 340 |
'dstaddr6': {'type': 'raw'}, |
| 341 |
'dstintf': {'type': 'raw'}, |
| 342 |
'groups': {'type': 'raw'}, |
| 343 |
'id': {'required': True, 'type': 'int'}, |
| 344 |
'ip-version': {'choices': ['4', '6'], 'type': 'str'}, |
| 345 |
'per-ip-shaper': {'type': 'str'}, |
| 346 |
'schedule': {'type': 'str'}, |
| 347 |
'service': {'type': 'raw'}, |
| 348 |
'srcaddr': {'type': 'raw'}, |
| 349 |
'srcaddr6': {'type': 'raw'}, |
| 350 |
'status': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 351 |
'traffic-shaper': {'type': 'str'}, |
| 352 |
'traffic-shaper-reverse': {'type': 'str'}, |
| 353 |
'url-category': {'type': 'raw'}, |
| 354 |
'users': {'type': 'raw'}, |
| 355 |
'app-group': {'v_range': [['6.2.0', '']], 'type': 'raw'}, |
| 356 |
'class-id': {'v_range': [['6.2.0', '']], 'type': 'raw'}, |
| 357 |
'comment': {'v_range': [['6.2.0', '']], 'type': 'str'}, |
| 358 |
'diffserv-forward': {'v_range': [['6.2.0', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 359 |
'diffserv-reverse': {'v_range': [['6.2.0', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 360 |
'diffservcode-forward': {'v_range': [['6.2.0', '']], 'type': 'str'}, |
| 361 |
'diffservcode-rev': {'v_range': [['6.2.0', '']], 'type': 'str'}, |
| 362 |
'internet-service': {'v_range': [['6.2.0', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 363 |
'internet-service-custom': {'v_range': [['6.2.0', '']], 'type': 'raw'}, |
| 364 |
'internet-service-custom-group': {'v_range': [['6.2.0', '']], 'type': 'raw'}, |
| 365 |
'internet-service-group': {'v_range': [['6.2.0', '']], 'type': 'raw'}, |
| 366 |
'internet-service-id': {'v_range': [['6.2.0', '7.6.2']], 'type': 'raw'}, |
| 367 |
'internet-service-src': {'v_range': [['6.2.0', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 368 |
'internet-service-src-custom': {'v_range': [['6.2.0', '']], 'type': 'raw'}, |
| 369 |
'internet-service-src-custom-group': {'v_range': [['6.2.0', '']], 'type': 'raw'}, |
| 370 |
'internet-service-src-group': {'v_range': [['6.2.0', '']], 'type': 'raw'}, |
| 371 |
'internet-service-src-id': {'v_range': [['6.2.0', '7.6.2']], 'type': 'raw'}, |
| 372 |
'name': {'v_range': [['6.2.0', '']], 'type': 'str'}, |
| 373 |
'srcintf': {'v_range': [['6.2.0', '']], 'type': 'raw'}, |
| 374 |
'tos': {'v_range': [['6.2.0', '']], 'type': 'str'}, |
| 375 |
'tos-mask': {'v_range': [['6.2.0', '']], 'type': 'str'}, |
| 376 |
'tos-negate': {'v_range': [['6.2.0', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 377 |
'uuid': {'v_range': [['6.2.1', '']], 'type': 'str'}, |
| 378 |
'internet-service-name': {'v_range': [['6.4.0', '']], 'type': 'raw'}, |
| 379 |
'internet-service-src-name': {'v_range': [['6.4.0', '']], 'type': 'raw'}, |
| 380 |
'cos': {'v_range': [['7.4.0', '']], 'type': 'str'}, |
| 381 |
'cos-mask': {'v_range': [['7.4.0', '']], 'type': 'str'}, |
| 382 |
'traffic-type': {'v_range': [['7.4.0', '']], 'choices': ['forwarding', 'local-in', 'local-out'], 'type': 'str'}, |
| 383 |
'class-id-reverse': {'v_range': [['7.4.8', '7.4.10'], ['7.6.4', '']], 'type': 'int'}, |
| 384 |
'http-response-match': {'v_range': [['7.4.8', '7.4.10'], ['7.6.4', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 385 |
'service-type': {'v_range': [['7.4.8', '7.4.10'], ['7.6.4', '']], 'choices': ['service', 'internet-service'], 'type': 'str'}, |
| 386 |
'internet-service-src-fortiguard': {'v_range': [['7.6.4', '']], 'type': 'raw'}, |
| 387 |
'internet-service-fortiguard': {'v_range': [['7.6.4', '']], 'type': 'raw'} |
| 388 |
} |
| 389 |
} |
| 390 |
} |
| 391 |
|
| 392 |
module_option_spec = get_module_arg_spec('full crud') |
| 393 |
module_arg_spec.update(module_option_spec) |
| 394 |
check_galaxy_version(module_arg_spec) |
| 395 |
module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'pkg_firewall_shapingpolicy'), |
| 396 |
supports_check_mode=True) |
| 397 |
if not module._socket_path: |
| 398 |
module.fail_json(msg='MUST RUN IN HTTPAPI MODE') |
| 399 |
connection = Connection(module._socket_path) |
| 400 |
fmgr = NAPIManager('full crud', module_arg_spec, urls_list, |
| 401 |
'id', 'data', module, connection) |
| 402 |
fmgr.process_crud() |
| 403 |
module.exit_json(meta=module.params) |
| 404 |
|
| 405 |
|
| 406 |
if __name__ == '__main__': |
| 407 |
main() |