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