| 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_dynamic_interface |
| 15 |
short_description: Dynamic interface |
| 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 |
dynamic_interface: |
| 29 |
description: The top level parameters set. |
| 30 |
required: false |
| 31 |
type: dict |
| 32 |
suboptions: |
| 33 |
color: |
| 34 |
type: int |
| 35 |
description: Color. |
| 36 |
default_mapping: |
| 37 |
aliases: ['default-mapping'] |
| 38 |
type: str |
| 39 |
description: Default mapping. |
| 40 |
choices: ['disable', 'enable'] |
| 41 |
defmap_intf: |
| 42 |
aliases: ['defmap-intf'] |
| 43 |
type: str |
| 44 |
description: Defmap intf. |
| 45 |
defmap_intrazone_deny: |
| 46 |
aliases: ['defmap-intrazone-deny'] |
| 47 |
type: str |
| 48 |
description: Defmap intrazone deny. |
| 49 |
choices: ['disable', 'enable'] |
| 50 |
defmap_zonemember: |
| 51 |
aliases: ['defmap-zonemember'] |
| 52 |
type: raw |
| 53 |
description: (list) Defmap zonemember. |
| 54 |
description: |
| 55 |
type: str |
| 56 |
description: Description. |
| 57 |
dynamic_mapping: |
| 58 |
type: list |
| 59 |
elements: dict |
| 60 |
description: Dynamic mapping. |
| 61 |
suboptions: |
| 62 |
_scope: |
| 63 |
type: list |
| 64 |
elements: dict |
| 65 |
description: Scope. |
| 66 |
suboptions: |
| 67 |
name: |
| 68 |
type: str |
| 69 |
description: Name. |
| 70 |
vdom: |
| 71 |
type: str |
| 72 |
description: Vdom. |
| 73 |
egress_shaping_profile: |
| 74 |
aliases: ['egress-shaping-profile'] |
| 75 |
type: raw |
| 76 |
description: (list or str) Egress shaping profile. |
| 77 |
intrazone_deny: |
| 78 |
aliases: ['intrazone-deny'] |
| 79 |
type: str |
| 80 |
description: Intrazone deny. |
| 81 |
choices: ['disable', 'enable'] |
| 82 |
local_intf: |
| 83 |
aliases: ['local-intf'] |
| 84 |
type: raw |
| 85 |
description: (list) Local intf. |
| 86 |
ingress_shaping_profile: |
| 87 |
aliases: ['ingress-shaping-profile'] |
| 88 |
type: raw |
| 89 |
description: (list or str) Ingress shaping profile. |
| 90 |
egress_shaping_profile: |
| 91 |
aliases: ['egress-shaping-profile'] |
| 92 |
type: raw |
| 93 |
description: (list or str) Egress shaping profile. |
| 94 |
name: |
| 95 |
type: str |
| 96 |
description: Name. |
| 97 |
required: true |
| 98 |
single_intf: |
| 99 |
aliases: ['single-intf'] |
| 100 |
type: str |
| 101 |
description: Single intf. |
| 102 |
choices: ['disable', 'enable'] |
| 103 |
ingress_shaping_profile: |
| 104 |
aliases: ['ingress-shaping-profile'] |
| 105 |
type: raw |
| 106 |
description: (list or str) Ingress shaping profile. |
| 107 |
platform_mapping: |
| 108 |
type: list |
| 109 |
elements: dict |
| 110 |
description: Platform mapping. |
| 111 |
suboptions: |
| 112 |
egress_shaping_profile: |
| 113 |
aliases: ['egress-shaping-profile'] |
| 114 |
type: raw |
| 115 |
description: (list or str) Egress shaping profile. |
| 116 |
ingress_shaping_profile: |
| 117 |
aliases: ['ingress-shaping-profile'] |
| 118 |
type: raw |
| 119 |
description: (list or str) Ingress shaping profile. |
| 120 |
intf_zone: |
| 121 |
aliases: ['intf-zone'] |
| 122 |
type: str |
| 123 |
description: Intf zone. |
| 124 |
intrazone_deny: |
| 125 |
aliases: ['intrazone-deny'] |
| 126 |
type: str |
| 127 |
description: Intrazone deny. |
| 128 |
choices: ['disable', 'enable'] |
| 129 |
name: |
| 130 |
type: str |
| 131 |
description: Name. |
| 132 |
wildcard: |
| 133 |
type: str |
| 134 |
description: Wildcard. |
| 135 |
choices: ['disable', 'enable'] |
| 136 |
wildcard_intf: |
| 137 |
aliases: ['wildcard-intf'] |
| 138 |
type: str |
| 139 |
description: Wildcard intf. |
| 140 |
zone_only: |
| 141 |
aliases: ['zone-only'] |
| 142 |
type: str |
| 143 |
description: Zone only. |
| 144 |
choices: ['disable', 'enable'] |
| 145 |
''' |
| 146 |
|
| 147 |
EXAMPLES = ''' |
| 148 |
- name: Example playbook (generated based on argument schema) |
| 149 |
hosts: fortimanagers |
| 150 |
connection: httpapi |
| 151 |
gather_facts: false |
| 152 |
tasks: |
| 153 |
- name: Dynamic interface |
| 154 |
fortinet.fortimanager.fmgr_dynamic_interface: |
| 155 |
# workspace_locking_adom: <global or your adom name> |
| 156 |
adom: <your own value> |
| 157 |
state: present # <value in [present, absent]> |
| 158 |
dynamic_interface: |
| 159 |
name: "your value" # Required variable, string |
| 160 |
# color: <integer> |
| 161 |
# default_mapping: <value in [disable, enable]> |
| 162 |
# defmap_intf: <string> |
| 163 |
# defmap_intrazone_deny: <value in [disable, enable]> |
| 164 |
# defmap_zonemember: <list or string> |
| 165 |
# description: <string> |
| 166 |
# dynamic_mapping: |
| 167 |
# - _scope: |
| 168 |
# - name: <string> |
| 169 |
# vdom: <string> |
| 170 |
# egress_shaping_profile: <list or string> |
| 171 |
# intrazone_deny: <value in [disable, enable]> |
| 172 |
# local_intf: <list or string> |
| 173 |
# ingress_shaping_profile: <list or string> |
| 174 |
# egress_shaping_profile: <list or string> |
| 175 |
# single_intf: <value in [disable, enable]> |
| 176 |
# ingress_shaping_profile: <list or string> |
| 177 |
# platform_mapping: |
| 178 |
# - egress_shaping_profile: <list or string> |
| 179 |
# ingress_shaping_profile: <list or string> |
| 180 |
# intf_zone: <string> |
| 181 |
# intrazone_deny: <value in [disable, enable]> |
| 182 |
# name: <string> |
| 183 |
# wildcard: <value in [disable, enable]> |
| 184 |
# wildcard_intf: <string> |
| 185 |
# zone_only: <value in [disable, enable]> |
| 186 |
''' |
| 187 |
|
| 188 |
RETURN = ''' |
| 189 |
meta: |
| 190 |
description: The result of the request. |
| 191 |
type: dict |
| 192 |
returned: always |
| 193 |
contains: |
| 194 |
request_url: |
| 195 |
description: The full url requested. |
| 196 |
returned: always |
| 197 |
type: str |
| 198 |
sample: /sys/login/user |
| 199 |
response_code: |
| 200 |
description: The status of api request. |
| 201 |
returned: always |
| 202 |
type: int |
| 203 |
sample: 0 |
| 204 |
response_data: |
| 205 |
description: The api response. |
| 206 |
type: list |
| 207 |
returned: always |
| 208 |
response_message: |
| 209 |
description: The descriptive message of the api response. |
| 210 |
type: str |
| 211 |
returned: always |
| 212 |
sample: OK. |
| 213 |
system_information: |
| 214 |
description: The information of the target system. |
| 215 |
type: dict |
| 216 |
returned: always |
| 217 |
rc: |
| 218 |
description: The status the request. |
| 219 |
type: int |
| 220 |
returned: always |
| 221 |
sample: 0 |
| 222 |
version_check_warning: |
| 223 |
description: Warning if the parameters used in the playbook are not supported by the current FortiManager version. |
| 224 |
type: list |
| 225 |
returned: complex |
| 226 |
''' |
| 227 |
from ansible.module_utils.basic import AnsibleModule |
| 228 |
from ansible.module_utils.connection import Connection |
| 229 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass |
| 230 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec |
| 231 |
|
| 232 |
|
| 233 |
def main(): |
| 234 |
urls_list = [ |
| 235 |
'/pm/config/adom/{adom}/obj/dynamic/interface', |
| 236 |
'/pm/config/global/obj/dynamic/interface' |
| 237 |
] |
| 238 |
module_arg_spec = { |
| 239 |
'adom': {'required': True, 'type': 'str'}, |
| 240 |
'revision_note': {'type': 'str'}, |
| 241 |
'dynamic_interface': { |
| 242 |
'type': 'dict', 'v_range': [['6.0.0', '']], |
| 243 |
'options': { |
| 244 |
'color': {'type': 'int'}, |
| 245 |
'default-mapping': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 246 |
'defmap-intf': {'type': 'str'}, |
| 247 |
'defmap-intrazone-deny': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 248 |
'defmap-zonemember': {'type': 'raw'}, |
| 249 |
'description': {'type': 'str'}, |
| 250 |
'dynamic_mapping': { |
| 251 |
'type': 'list', |
| 252 |
'options': { |
| 253 |
'_scope': {'type': 'list', 'options': {'name': {'type': 'str'}, 'vdom': {'type': 'str'}}, 'elements': 'dict'}, |
| 254 |
'egress-shaping-profile': {'type': 'raw'}, |
| 255 |
'intrazone-deny': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 256 |
'local-intf': {'type': 'raw'}, |
| 257 |
'ingress-shaping-profile': {'v_range': [['6.2.2', '']], 'type': 'raw'} |
| 258 |
}, |
| 259 |
'elements': 'dict' |
| 260 |
}, |
| 261 |
'egress-shaping-profile': {'type': 'raw'}, |
| 262 |
'name': {'required': True, 'type': 'str'}, |
| 263 |
'single-intf': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 264 |
'ingress-shaping-profile': {'v_range': [['6.2.2', '']], 'type': 'raw'}, |
| 265 |
'platform_mapping': { |
| 266 |
'v_range': [['6.4.1', '']], |
| 267 |
'type': 'list', |
| 268 |
'options': { |
| 269 |
'egress-shaping-profile': {'v_range': [['6.4.1', '']], 'type': 'raw'}, |
| 270 |
'ingress-shaping-profile': {'v_range': [['6.4.1', '']], 'type': 'raw'}, |
| 271 |
'intf-zone': {'v_range': [['6.4.1', '']], 'type': 'str'}, |
| 272 |
'intrazone-deny': {'v_range': [['6.4.1', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 273 |
'name': {'v_range': [['6.4.1', '']], 'type': 'str'} |
| 274 |
}, |
| 275 |
'elements': 'dict' |
| 276 |
}, |
| 277 |
'wildcard': {'v_range': [['7.0.1', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 278 |
'wildcard-intf': {'v_range': [['7.0.1', '']], 'type': 'str'}, |
| 279 |
'zone-only': {'v_range': [['6.4.7', '6.4.15'], ['7.0.3', '']], 'choices': ['disable', 'enable'], 'type': 'str'} |
| 280 |
} |
| 281 |
} |
| 282 |
} |
| 283 |
|
| 284 |
module_option_spec = get_module_arg_spec('full crud') |
| 285 |
module_arg_spec.update(module_option_spec) |
| 286 |
check_galaxy_version(module_arg_spec) |
| 287 |
module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'dynamic_interface'), |
| 288 |
supports_check_mode=True) |
| 289 |
if not module._socket_path: |
| 290 |
module.fail_json(msg='MUST RUN IN HTTPAPI MODE') |
| 291 |
connection = Connection(module._socket_path) |
| 292 |
fmgr = NAPIManager('full crud', module_arg_spec, urls_list, |
| 293 |
'name', 'data', module, connection) |
| 294 |
fmgr.process_crud() |
| 295 |
module.exit_json(meta=module.params) |
| 296 |
|
| 297 |
|
| 298 |
if __name__ == '__main__': |
| 299 |
main() |