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