ansible  2.9.27
About: Ansible is an IT Configuration Management, Deployment \
About: Ansible (2.x) is an IT Configuration Management, Deployment & Orchestration tool.
ansible download page.
  Fossies Dox: ansible-2.9.27.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

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