Debian Codegraph @

ansible_collections/cisco/intersight/plugins/modules/intersight_multicast_policy.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import absolute_import, division, print_function
7 __metaclass__ = type
8
9 ANSIBLE_METADATA = {'metadata_version': '1.1',
10 'status': ['preview'],
11 'supported_by': 'community'}
12
13 DOCUMENTATION = r'''
14 ---
15 module: intersight_multicast_policy
16 short_description: Multicast Policy configuration for Cisco Intersight
17 description:
18 - Manages Multicast Policy configuration on Cisco Intersight.
19 - A policy to configure multicast settings including IGMP snooping and querier on Cisco Intersight managed switches.
20 - For more information see L(Cisco Intersight,https://intersight.com/apidocs/fabric/MulticastPolicy/get/).
21 extends_documentation_fragment: intersight
22 options:
23 state:
24 description:
25 - If C(present), will verify the resource is present and will create if needed.
26 - If C(absent), will verify the resource is absent and will delete if needed.
27 type: str
28 choices: [present, absent]
29 default: present
30 organization:
31 description:
32 - The name of the Organization this resource is assigned to.
33 - Profiles, Policies, and Pools that are created within a Custom Organization are applicable only to devices in the same Organization.
34 type: str
35 default: default
36 name:
37 description:
38 - The name assigned to the Multicast Policy.
39 - The name must be between 1 and 62 alphanumeric characters, allowing special characters :-_.
40 type: str
41 required: true
42 description:
43 description:
44 - The user-defined description for the Multicast Policy.
45 - Description can contain letters(a-z, A-Z), numbers(0-9), hyphen(-), period(.), colon(:), or an underscore(_).
46 type: str
47 aliases: [descr]
48 tags:
49 description:
50 - List of tags in Key:<user-defined key> Value:<user-defined value> format.
51 type: list
52 elements: dict
53 querier_state:
54 description:
55 - Administrative state of the IGMP Querier for this VLAN.
56 type: str
57 choices: ['Enabled', 'Disabled']
58 default: 'Disabled'
59 snooping_state:
60 description:
61 - Administrative state of the IGMP Snooping for this VLAN.
62 type: str
63 choices: ['Enabled', 'Disabled']
64 default: 'Enabled'
65 querier_ip_address:
66 description:
67 - Used to define the IGMP Querier IP address.
68 - Must be a valid IPv4 address.
69 type: str
70 querier_ip_address_peer:
71 description:
72 - Used to define the IGMP Querier IP address of the peer switch.
73 - This is optional and only applicable when querier_state is set to 'Enabled'.
74 - Must be a valid IPv4 address.
75 type: str
76 src_ip_proxy:
77 description:
78 - Administrative state of the IGMP source IP proxy for this VLAN.
79 type: str
80 choices: ['Enabled', 'Disabled']
81 default: 'Enabled'
82 author:
83 - Ron Gershburg (@rgershbu)
84 '''
85
86 EXAMPLES = r'''
87 - name: Create a Multicast Policy with querier enabled
88 cisco.intersight.intersight_multicast_policy:
89 api_private_key: "{{ api_private_key }}"
90 api_key_id: "{{ api_key_id }}"
91 organization: "default"
92 name: "Multicast-Policy-Querier"
93 description: "Multicast policy with IGMP querier enabled"
94 tags:
95 - Key: "Site"
96 Value: "DataCenter-A"
97 querier_state: "Enabled"
98 snooping_state: "Enabled"
99 querier_ip_address: "192.168.1.1"
100 querier_ip_address_peer: "192.168.1.2"
101 src_ip_proxy: "Enabled"
102 state: present
103
104 - name: Create a basic Multicast Policy with defaults
105 cisco.intersight.intersight_multicast_policy:
106 api_private_key: "{{ api_private_key }}"
107 api_key_id: "{{ api_key_id }}"
108 name: "Basic-Multicast-Policy"
109 description: "Basic multicast policy with snooping enabled"
110 querier_state: "Disabled"
111 snooping_state: "Enabled"
112 src_ip_proxy: "Enabled"
113 state: present
114
115 - name: Create a Multicast Policy with only snooping
116 cisco.intersight.intersight_multicast_policy:
117 api_private_key: "{{ api_private_key }}"
118 api_key_id: "{{ api_key_id }}"
119 name: "Snooping-Only-Policy"
120 description: "Multicast policy with only snooping enabled"
121 querier_state: "Disabled"
122 snooping_state: "Enabled"
123 src_ip_proxy: "Disabled"
124 state: present
125
126 - name: Delete a Multicast Policy
127 cisco.intersight.intersight_multicast_policy:
128 api_private_key: "{{ api_private_key }}"
129 api_key_id: "{{ api_key_id }}"
130 name: "Multicast-Policy-Querier"
131 state: absent
132 '''
133
134 RETURN = r'''
135 api_response:
136 description: The API response output returned by the specified resource.
137 returned: always
138 type: dict
139 sample:
140 "api_response": {
141 "Name": "test_multicast_policy",
142 "ObjectType": "fabric.MulticastPolicy",
143 "QuerierState": "Enabled",
144 "SnoopingState": "Enabled",
145 "QuerierIpAddress": "192.168.1.1",
146 "QuerierIpAddressPeer": "192.168.1.2",
147 "SrcIpProxy": "Enabled",
148 "Tags": [
149 {
150 "Key": "Site",
151 "Value": "DataCenter-A"
152 }
153 ]
154 }
155 '''
156
157
158 from ansible.module_utils.basic import AnsibleModule
159 from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec
160
161
162 def main():
163 argument_spec = intersight_argument_spec.copy()
164 argument_spec.update(
165 state=dict(type='str', choices=['present', 'absent'], default='present'),
166 organization=dict(type='str', default='default'),
167 name=dict(type='str', required=True),
168 description=dict(type='str', aliases=['descr']),
169 tags=dict(type='list', elements='dict'),
170 querier_state=dict(type='str', choices=['Enabled', 'Disabled'], default='Disabled'),
171 snooping_state=dict(type='str', choices=['Enabled', 'Disabled'], default='Enabled'),
172 querier_ip_address=dict(type='str'),
173 querier_ip_address_peer=dict(type='str'),
174 src_ip_proxy=dict(type='str', choices=['Enabled', 'Disabled'], default='Enabled')
175 )
176 module = AnsibleModule(
177 argument_spec,
178 supports_check_mode=True,
179 required_if=[
180 ['querier_state', 'Enabled', ['querier_ip_address']],
181 ]
182 )
183
184 # Validate that snooping cannot be disabled with querier enabled
185 if (module.params['snooping_state'] == 'Disabled' and module.params['querier_state'] == 'Enabled'):
186 module.fail_json(
187 msg="Invalid configuration: Multicast policy cannot have Snooping Disabled and Querier Enabled simultaneously."
188 )
189
190 intersight = IntersightModule(module)
191 intersight.result['api_response'] = {}
192 intersight.result['trace_id'] = ''
193
194 # Resource path used to configure policy
195 resource_path = '/fabric/MulticastPolicies'
196
197 # Define API body used in compares or create
198 intersight.api_body = {
199 'Organization': {
200 'Name': intersight.module.params['organization'],
201 },
202 'Name': intersight.module.params['name'],
203 'QuerierState': intersight.module.params['querier_state'],
204 'SnoopingState': intersight.module.params['snooping_state'],
205 'SrcIpProxy': intersight.module.params['src_ip_proxy'],
206 }
207
208 if intersight.module.params['state'] == 'present':
209 intersight.set_tags_and_description()
210
211 # Add querier IP address if querier is enabled
212 if intersight.module.params['querier_state'] == 'Enabled':
213 intersight.api_body['QuerierIpAddress'] = intersight.module.params['querier_ip_address']
214
215 # Add peer IP address if provided
216 if intersight.module.params['querier_ip_address_peer']:
217 intersight.api_body['QuerierIpAddressPeer'] = intersight.module.params['querier_ip_address_peer']
218
219 intersight.configure_policy_or_profile(resource_path=resource_path)
220
221 module.exit_json(**intersight.result)
222
223
224 if __name__ == '__main__':
225 main()