Debian Codegraph @

ansible_collections/cisco/nxos/plugins/modules/nxos_igmp.py

raw
1 #!/usr/bin/python
2 #
3 # This file is part of Ansible
4 #
5 # Ansible is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Ansible is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
17 #
18 from __future__ import absolute_import, division, print_function
19
20
21 __metaclass__ = type
22
23
24 DOCUMENTATION = """
25 module: nxos_igmp
26 extends_documentation_fragment:
27 - cisco.nxos.nxos
28 short_description: Manages IGMP global configuration.
29 description:
30 - Manages IGMP global configuration configuration settings.
31 version_added: 1.0.0
32 author:
33 - Jason Edelman (@jedelman8)
34 - Gabriele Gerbino (@GGabriele)
35 notes:
36 - Tested against NXOSv 7.3.(0)D1(1) on VIRL
37 - Unsupported for Cisco MDS
38 - When C(state=default), all supported params will be reset to a default state.
39 - If restart is set to true with other params set, the restart will happen last, i.e.
40 after the configuration takes place.
41 options:
42 flush_routes:
43 description:
44 - Removes routes when the IGMP process is restarted. By default, routes are not
45 flushed.
46 type: bool
47 enforce_rtr_alert:
48 description:
49 - Enables or disables the enforce router alert option check for IGMPv2 and IGMPv3
50 packets.
51 type: bool
52 restart:
53 description:
54 - Restarts the igmp process (using an exec config command).
55 type: bool
56 default: False
57 state:
58 description:
59 - Manages desired state of the resource.
60 default: present
61 choices:
62 - present
63 - default
64 type: str
65 """
66 EXAMPLES = """
67 - name: Default igmp global params (all params except restart)
68 cisco.nxos.nxos_igmp:
69 state: default
70
71 - name: Ensure the following igmp global config exists on the device
72 cisco.nxos.nxos_igmp:
73 flush_routes: true
74 enforce_rtr_alert: true
75
76 - name: Restart the igmp process
77 cisco.nxos.nxos_igmp:
78 restart: true
79 """
80
81 RETURN = """
82 updates:
83 description: commands sent to the device
84 returned: always
85 type: list
86 sample: ["ip igmp flush-routes"]
87 """
88 from ansible.module_utils.basic import AnsibleModule
89
90 from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import (
91 load_config,
92 run_commands,
93 )
94
95
96 def get_current(module):
97 output = run_commands(module, {"command": "show running-config", "output": "text"})
98 return {
99 "flush_routes": "ip igmp flush-routes" in output[0],
100 "enforce_rtr_alert": "ip igmp enforce-router-alert" in output[0],
101 }
102
103
104 def get_desired(module):
105 return {
106 "flush_routes": module.params["flush_routes"],
107 "enforce_rtr_alert": module.params["enforce_rtr_alert"],
108 }
109
110
111 def main():
112 argument_spec = dict(
113 flush_routes=dict(type="bool"),
114 enforce_rtr_alert=dict(type="bool"),
115 restart=dict(type="bool", default=False),
116 state=dict(choices=["present", "default"], default="present"),
117 )
118
119 module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
120
121 warnings = list()
122
123 current = get_current(module)
124 desired = get_desired(module)
125
126 state = module.params["state"]
127
128 commands = list()
129
130 if state == "default":
131 if current["flush_routes"]:
132 commands.append("no ip igmp flush-routes")
133 if current["enforce_rtr_alert"]:
134 commands.append("no ip igmp enforce-router-alert")
135
136 elif state == "present":
137 ldict = {
138 "flush_routes": "flush-routes",
139 "enforce_rtr_alert": "enforce-router-alert",
140 }
141 for arg in ["flush_routes", "enforce_rtr_alert"]:
142 if desired[arg] and not current[arg]:
143 commands.append("ip igmp {0}".format(ldict.get(arg)))
144 elif current[arg] and not desired[arg]:
145 commands.append("no ip igmp {0}".format(ldict.get(arg)))
146
147 result = {"changed": False, "updates": commands, "warnings": warnings}
148
149 if commands:
150 if not module.check_mode:
151 load_config(module, commands)
152 result["changed"] = True
153
154 if module.params["restart"]:
155 cmd = {"command": "restart igmp", "output": "text"}
156 run_commands(module, cmd)
157
158 module.exit_json(**result)
159
160
161 if __name__ == "__main__":
162 main()