Debian Codegraph @

ansible_collections/fortinet/fortimanager/plugins/modules/fmgr_switchcontroller_vlanpolicy.py

raw symbols SCIP
1 #!/usr/bin/python
2 from __future__ import absolute_import, division, print_function
3 # Copyright 2019-2024 Fortinet, Inc.
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
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_switchcontroller_vlanpolicy
15 short_description: Configure VLAN policy to be applied on the managed FortiSwitch ports through dynamic-port-policy.
16 version_added: "2.2.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 switchcontroller_vlanpolicy:
29 description: The top level parameters set.
30 required: false
31 type: dict
32 suboptions:
33 allowed_vlans:
34 aliases: ['allowed-vlans']
35 type: raw
36 description: (list) Allowed VLANs to be applied when using this VLAN policy.
37 allowed_vlans_all:
38 aliases: ['allowed-vlans-all']
39 type: str
40 description: Enable/disable all defined VLANs when using this VLAN policy.
41 choices: ['disable', 'enable']
42 description:
43 type: str
44 description: Description for the VLAN policy.
45 discard_mode:
46 aliases: ['discard-mode']
47 type: str
48 description: Discard mode to be applied when using this VLAN policy.
49 choices: ['none', 'all-untagged', 'all-tagged']
50 name:
51 type: str
52 description: VLAN policy name.
53 required: true
54 untagged_vlans:
55 aliases: ['untagged-vlans']
56 type: raw
57 description: (list) Untagged VLANs to be applied when using this VLAN policy.
58 vlan:
59 type: str
60 description: Native VLAN to be applied when using this VLAN policy.
61 fortilink:
62 type: raw
63 description: (list) FortiLink interface for which this VLAN policy belongs to.
64 '''
65
66 EXAMPLES = '''
67 - name: Example playbook (generated based on argument schema)
68 hosts: fortimanagers
69 connection: httpapi
70 gather_facts: false
71 tasks:
72 - name: Configure VLAN policy to be applied on the managed FortiSwitch ports through dynamic-port-policy.
73 fortinet.fortimanager.fmgr_switchcontroller_vlanpolicy:
74 # workspace_locking_adom: <global or your adom name>
75 adom: <your own value>
76 state: present # <value in [present, absent]>
77 switchcontroller_vlanpolicy:
78 name: "your value" # Required variable, string
79 # allowed_vlans: <list or string>
80 # allowed_vlans_all: <value in [disable, enable]>
81 # description: <string>
82 # discard_mode: <value in [none, all-untagged, all-tagged]>
83 # untagged_vlans: <list or string>
84 # vlan: <string>
85 # fortilink: <list or string>
86 '''
87
88 RETURN = '''
89 meta:
90 description: The result of the request.
91 type: dict
92 returned: always
93 contains:
94 request_url:
95 description: The full url requested.
96 returned: always
97 type: str
98 sample: /sys/login/user
99 response_code:
100 description: The status of api request.
101 returned: always
102 type: int
103 sample: 0
104 response_data:
105 description: The api response.
106 type: list
107 returned: always
108 response_message:
109 description: The descriptive message of the api response.
110 type: str
111 returned: always
112 sample: OK.
113 system_information:
114 description: The information of the target system.
115 type: dict
116 returned: always
117 rc:
118 description: The status the request.
119 type: int
120 returned: always
121 sample: 0
122 version_check_warning:
123 description: Warning if the parameters used in the playbook are not supported by the current FortiManager version.
124 type: list
125 returned: complex
126 '''
127 from ansible.module_utils.basic import AnsibleModule
128 from ansible.module_utils.connection import Connection
129 from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass
130 from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec
131
132
133 def main():
134 urls_list = [
135 '/pm/config/adom/{adom}/obj/switch-controller/vlan-policy',
136 '/pm/config/global/obj/switch-controller/vlan-policy'
137 ]
138 module_arg_spec = {
139 'adom': {'required': True, 'type': 'str'},
140 'revision_note': {'type': 'str'},
141 'switchcontroller_vlanpolicy': {
142 'type': 'dict', 'v_range': [['7.2.1', '']],
143 'options': {
144 'allowed-vlans': {'v_range': [['7.2.1', '']], 'type': 'raw'},
145 'allowed-vlans-all': {'v_range': [['7.2.1', '']], 'choices': ['disable', 'enable'], 'type': 'str'},
146 'description': {'v_range': [['7.2.1', '']], 'type': 'str'},
147 'discard-mode': {'v_range': [['7.2.1', '']], 'choices': ['none', 'all-untagged', 'all-tagged'], 'type': 'str'},
148 'name': {'v_range': [['7.2.1', '']], 'required': True, 'type': 'str'},
149 'untagged-vlans': {'v_range': [['7.2.1', '']], 'type': 'raw'},
150 'vlan': {'v_range': [['7.2.1', '']], 'type': 'str'},
151 'fortilink': {'v_range': [['7.2.6', '7.2.12'], ['7.4.3', '']], 'type': 'raw'}
152 }
153 }
154 }
155
156 module_option_spec = get_module_arg_spec('full crud')
157 module_arg_spec.update(module_option_spec)
158 check_galaxy_version(module_arg_spec)
159 module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'switchcontroller_vlanpolicy'),
160 supports_check_mode=True)
161 if not module._socket_path:
162 module.fail_json(msg='MUST RUN IN HTTPAPI MODE')
163 connection = Connection(module._socket_path)
164 fmgr = NAPIManager('full crud', module_arg_spec, urls_list,
165 'name', 'data', module, connection)
166 fmgr.process_crud()
167 module.exit_json(meta=module.params)
168
169
170 if __name__ == '__main__':
171 main()