Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_fabric_leaf_profile.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_fabric_leaf_profile
15 short_description: Manage fabric leaf profiles (fabric:LeafP)
16 description:
17 - Manage fabric leaf switch profiles in an ACI fabric.
18 options:
19 name:
20 description:
21 - Name of the fabric leaf switch profile
22 type: str
23 aliases: [ leaf_profile, leaf_switch_profile ]
24 description:
25 description:
26 - description of the profile
27 type: str
28 aliases: [ descr ]
29 state:
30 description:
31 - Use C(present) or C(absent) for adding or removing.
32 - Use C(query) for listing an object or multiple objects.
33 type: str
34 choices: [ absent, present, query ]
35 default: present
36 extends_documentation_fragment:
37 - cisco.aci.aci
38 - cisco.aci.annotation
39 - cisco.aci.owner
40
41 seealso:
42 - name: APIC Management Information Model reference
43 description: More information about the internal APIC class B(fabricLeafP).
44 link: https://developer.cisco.com/docs/apic-mim-ref/
45 author:
46 - Tim Cragg (@timcragg)
47 """
48
49 EXAMPLES = r"""
50 - name: Create a leaf switch profile
51 cisco.aci.aci_fabric_leaf_profile:
52 host: apic
53 username: admin
54 password: SomeSecretPassword
55 name: my_leaf_profile
56 state: present
57 delegate_to: localhost
58
59 - name: Remove a leaf switch profile
60 cisco.aci.aci_fabric_leaf_profile:
61 host: apic
62 username: admin
63 password: SomeSecretPassword
64 name: my_leaf_profile
65 state: absent
66 delegate_to: localhost
67
68 - name: Query a leaf profile
69 cisco.aci.aci_fabric_leaf_profile:
70 host: apic
71 username: admin
72 password: SomeSecretPassword
73 name: my_leaf_profile
74 state: query
75 delegate_to: localhost
76 register: query_result
77
78 - name: Query all leaf profiles
79 cisco.aci.aci_fabric_leaf_profile:
80 host: apic
81 username: admin
82 password: SomeSecretPassword
83 state: query
84 delegate_to: localhost
85 register: query_result
86 """
87
88 RETURN = r"""
89 current:
90 description: The existing configuration from the APIC after the module has finished
91 returned: success
92 type: list
93 sample:
94 [
95 {
96 "fvTenant": {
97 "attributes": {
98 "descr": "Production environment",
99 "dn": "uni/tn-production",
100 "name": "production",
101 "nameAlias": "",
102 "ownerKey": "",
103 "ownerTag": ""
104 }
105 }
106 }
107 ]
108 error:
109 description: The error information as returned from the APIC
110 returned: failure
111 type: dict
112 sample:
113 {
114 "code": "122",
115 "text": "unknown managed object class foo"
116 }
117 raw:
118 description: The raw output returned by the APIC REST API (xml or json)
119 returned: parse error
120 type: str
121 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
122 sent:
123 description: The actual/minimal configuration pushed to the APIC
124 returned: info
125 type: list
126 sample:
127 {
128 "fvTenant": {
129 "attributes": {
130 "descr": "Production environment"
131 }
132 }
133 }
134 previous:
135 description: The original configuration from the APIC before the module has started
136 returned: info
137 type: list
138 sample:
139 [
140 {
141 "fvTenant": {
142 "attributes": {
143 "descr": "Production",
144 "dn": "uni/tn-production",
145 "name": "production",
146 "nameAlias": "",
147 "ownerKey": "",
148 "ownerTag": ""
149 }
150 }
151 }
152 ]
153 proposed:
154 description: The assembled configuration from the user-provided parameters
155 returned: info
156 type: dict
157 sample:
158 {
159 "fvTenant": {
160 "attributes": {
161 "descr": "Production environment",
162 "name": "production"
163 }
164 }
165 }
166 filter_string:
167 description: The filter string used for the request
168 returned: failure or debug
169 type: str
170 sample: ?rsp-prop-include=config-only
171 method:
172 description: The HTTP method used for the request to the APIC
173 returned: failure or debug
174 type: str
175 sample: POST
176 response:
177 description: The HTTP response from the APIC
178 returned: failure or debug
179 type: str
180 sample: OK (30 bytes)
181 status:
182 description: The HTTP status from the APIC
183 returned: failure or debug
184 type: int
185 sample: 200
186 url:
187 description: The HTTP url used for the request to the APIC
188 returned: failure or debug
189 type: str
190 sample: https://10.11.12.13/api/mo/uni/tn-production.json
191 """
192
193
194 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
195 from ansible.module_utils.basic import AnsibleModule
196
197
198 def main():
199 argument_spec = aci_argument_spec()
200 argument_spec.update(aci_annotation_spec())
201 argument_spec.update(aci_owner_spec())
202 argument_spec.update(
203 name=dict(type="str", aliases=["leaf_switch_profile", "leaf_profile"]),
204 description=dict(type="str", aliases=["descr"]),
205 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
206 )
207
208 module = AnsibleModule(
209 argument_spec=argument_spec,
210 supports_check_mode=True,
211 required_if=[
212 ["state", "absent", ["name"]],
213 ["state", "present", ["name"]],
214 ],
215 )
216
217 aci = ACIModule(module)
218
219 name = module.params.get("name")
220 description = module.params.get("description")
221 state = module.params.get("state")
222 child_classes = ["fabricLeafS"]
223
224 aci.construct_url(
225 root_class=dict(
226 aci_class="fabricLeafP",
227 aci_rn="fabric/leprof-{0}".format(name),
228 module_object=name,
229 target_filter={"name": name},
230 ),
231 child_classes=child_classes,
232 )
233
234 aci.get_existing()
235
236 if state == "present":
237 aci.payload(
238 aci_class="fabricLeafP",
239 class_config=dict(name=name, descr=description),
240 )
241
242 aci.get_diff(aci_class="fabricLeafP")
243
244 aci.post_config()
245
246 elif state == "absent":
247 aci.delete_config()
248
249 aci.exit_json()
250
251
252 if __name__ == "__main__":
253 main()