Debian Codegraph @

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