Debian Codegraph @

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

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