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