Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_interface_policy_lldp.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import absolute_import, division, print_function
7
8 __metaclass__ = type
9
10 ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "certified"}
11
12 DOCUMENTATION = r"""
13 ---
14 module: aci_interface_policy_lldp
15 short_description: Manage LLDP interface policies (lldp:IfPol)
16 description:
17 - Manage LLDP interface policies on Cisco ACI fabrics.
18 options:
19 lldp_policy:
20 description:
21 - The LLDP interface policy name.
22 type: str
23 aliases: [ name ]
24 description:
25 description:
26 - The description of the LLDP interface policy name.
27 type: str
28 aliases: [ descr ]
29 receive_state:
30 description:
31 - Enable or disable Receive state.
32 - The APIC defaults to C(true) when unset during creation.
33 type: bool
34 transmit_state:
35 description:
36 - Enable or Disable Transmit state.
37 - The APIC defaults to C(true) when unset during creation.
38 type: bool
39 state:
40 description:
41 - Use C(present) or C(absent) for adding or removing.
42 - Use C(query) for listing an object or multiple objects.
43 type: str
44 choices: [ absent, present, query ]
45 default: present
46 name_alias:
47 description:
48 - The alias for the current object. This relates to the nameAlias field in ACI.
49 type: str
50 extends_documentation_fragment:
51 - cisco.aci.aci
52 - cisco.aci.annotation
53 - cisco.aci.owner
54
55 seealso:
56 - name: APIC Management Information Model reference
57 description: More information about the internal APIC class B(lldp:IfPol).
58 link: https://developer.cisco.com/docs/apic-mim-ref/
59 author:
60 - Dag Wieers (@dagwieers)
61 """
62
63 EXAMPLES = r"""
64 - name: Create a LLDP interface policy
65 cisco.aci.aci_interface_policy_lldp:
66 host: apic
67 username: admin
68 password: SomeSecretPassword
69 lldp_policy: LLDP_OFF
70 receive_state: false
71 transmit_state: false
72 state: present
73 delegate_to: localhost
74
75 - name: Delete a LLDP interface policy
76 cisco.aci.aci_interface_policy_lldp:
77 host: apic
78 username: admin
79 password: SomeSecretPassword
80 lldp_policy: LLDP_OFF
81 state: absent
82 delegate_to: localhost
83
84 - name: Query all LLDP interface policies
85 cisco.aci.aci_interface_policy_lldp:
86 host: apic
87 username: admin
88 password: SomeSecretPassword
89 state: query
90 delegate_to: localhost
91 register: query_result
92
93 - name: Query a specific LLDP interface policy
94 cisco.aci.aci_interface_policy_lldp:
95 host: apic
96 username: admin
97 password: SomeSecretPassword
98 lldp_policy: LLDP_OFF
99 state: query
100 delegate_to: localhost
101 register: query_result
102 """
103
104 RETURN = r"""
105 current:
106 description: The existing configuration from the APIC after the module has finished
107 returned: success
108 type: list
109 sample:
110 [
111 {
112 "fvTenant": {
113 "attributes": {
114 "descr": "Production environment",
115 "dn": "uni/tn-production",
116 "name": "production",
117 "nameAlias": "",
118 "ownerKey": "",
119 "ownerTag": ""
120 }
121 }
122 }
123 ]
124 error:
125 description: The error information as returned from the APIC
126 returned: failure
127 type: dict
128 sample:
129 {
130 "code": "122",
131 "text": "unknown managed object class foo"
132 }
133 raw:
134 description: The raw output returned by the APIC REST API (xml or json)
135 returned: parse error
136 type: str
137 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
138 sent:
139 description: The actual/minimal configuration pushed to the APIC
140 returned: info
141 type: list
142 sample:
143 {
144 "fvTenant": {
145 "attributes": {
146 "descr": "Production environment"
147 }
148 }
149 }
150 previous:
151 description: The original configuration from the APIC before the module has started
152 returned: info
153 type: list
154 sample:
155 [
156 {
157 "fvTenant": {
158 "attributes": {
159 "descr": "Production",
160 "dn": "uni/tn-production",
161 "name": "production",
162 "nameAlias": "",
163 "ownerKey": "",
164 "ownerTag": ""
165 }
166 }
167 }
168 ]
169 proposed:
170 description: The assembled configuration from the user-provided parameters
171 returned: info
172 type: dict
173 sample:
174 {
175 "fvTenant": {
176 "attributes": {
177 "descr": "Production environment",
178 "name": "production"
179 }
180 }
181 }
182 filter_string:
183 description: The filter string used for the request
184 returned: failure or debug
185 type: str
186 sample: ?rsp-prop-include=config-only
187 method:
188 description: The HTTP method used for the request to the APIC
189 returned: failure or debug
190 type: str
191 sample: POST
192 response:
193 description: The HTTP response from the APIC
194 returned: failure or debug
195 type: str
196 sample: OK (30 bytes)
197 status:
198 description: The HTTP status from the APIC
199 returned: failure or debug
200 type: int
201 sample: 200
202 url:
203 description: The HTTP url used for the request to the APIC
204 returned: failure or debug
205 type: str
206 sample: https://10.11.12.13/api/mo/uni/tn-production.json
207 """
208
209 from ansible.module_utils.basic import AnsibleModule
210 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
211
212
213 def main():
214 argument_spec = aci_argument_spec()
215 argument_spec.update(aci_annotation_spec())
216 argument_spec.update(aci_owner_spec())
217 argument_spec.update(
218 lldp_policy=dict(type="str", aliases=["name"]), # Not required for querying all objects
219 description=dict(type="str", aliases=["descr"]),
220 receive_state=dict(type="bool"),
221 transmit_state=dict(type="bool"),
222 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
223 name_alias=dict(type="str"),
224 )
225
226 module = AnsibleModule(
227 argument_spec=argument_spec,
228 supports_check_mode=True,
229 required_if=[
230 ["state", "absent", ["lldp_policy"]],
231 ["state", "present", ["lldp_policy"]],
232 ],
233 )
234
235 aci = ACIModule(module)
236
237 lldp_policy = module.params.get("lldp_policy")
238 description = module.params.get("description")
239 receive_state = aci.boolean(module.params.get("receive_state"), "enabled", "disabled")
240 transmit_state = aci.boolean(module.params.get("transmit_state"), "enabled", "disabled")
241 state = module.params.get("state")
242 name_alias = module.params.get("name_alias")
243
244 aci.construct_url(
245 root_class=dict(
246 aci_class="lldpIfPol",
247 aci_rn="infra/lldpIfP-{0}".format(lldp_policy),
248 module_object=lldp_policy,
249 target_filter={"name": lldp_policy},
250 ),
251 )
252
253 aci.get_existing()
254
255 if state == "present":
256 aci.payload(
257 aci_class="lldpIfPol",
258 class_config=dict(
259 name=lldp_policy,
260 descr=description,
261 adminRxSt=receive_state,
262 adminTxSt=transmit_state,
263 nameAlias=name_alias,
264 ),
265 )
266
267 aci.get_diff(aci_class="lldpIfPol")
268
269 aci.post_config()
270
271 elif state == "absent":
272 aci.delete_config()
273
274 aci.exit_json()
275
276
277 if __name__ == "__main__":
278 main()