"Fossies" - the Fresh Open Source Software Archive

Member "ansible-2.9.27/lib/ansible/modules/network/aci/aci_aep.py" (11 Oct 2021, 7095 Bytes) of package /linux/misc/ansible-2.9.27.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "aci_aep.py" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.9.24_vs_4.3.0.

    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 
    6 from __future__ import absolute_import, division, print_function
    7 __metaclass__ = type
    8 
    9 ANSIBLE_METADATA = {'metadata_version': '1.1',
   10                     'status': ['preview'],
   11                     'supported_by': 'certified'}
   12 
   13 DOCUMENTATION = r'''
   14 ---
   15 module: aci_aep
   16 short_description: Manage attachable Access Entity Profile (AEP) objects (infra:AttEntityP, infra:ProvAcc)
   17 description:
   18 - Connect to external virtual and physical domains by using
   19   attachable Access Entity Profiles (AEP) on Cisco ACI fabrics.
   20 version_added: '2.4'
   21 options:
   22   aep:
   23     description:
   24     - The name of the Attachable Access Entity Profile.
   25     type: str
   26     required: yes
   27     aliases: [ aep_name, name ]
   28   description:
   29     description:
   30     - Description for the AEP.
   31     type: str
   32     aliases: [ descr ]
   33   infra_vlan:
   34     description:
   35     - Enable infrastructure VLAN.
   36     - The hypervisor functions of the AEP.
   37     - C(no) will disable the infrastructure vlan if it is enabled.
   38     type: bool
   39     aliases: [ infrastructure_vlan ]
   40     version_added: '2.5'
   41   state:
   42     description:
   43     - Use C(present) or C(absent) for adding or removing.
   44     - Use C(query) for listing an object or multiple objects.
   45     type: str
   46     default: present
   47     choices: [ absent, present, query ]
   48 extends_documentation_fragment: aci
   49 seealso:
   50 - module: aci_aep_to_domain
   51 - name: APIC Management Information Model reference
   52   description: More information about the internal APIC classes B(infra:AttEntityP) and B(infra:ProvAcc).
   53   link: https://developer.cisco.com/docs/apic-mim-ref/
   54 author:
   55 - Swetha Chunduri (@schunduri)
   56 '''
   57 
   58 EXAMPLES = r'''
   59 - name: Add a new AEP
   60   aci_aep:
   61     host: apic
   62     username: admin
   63     password: SomeSecretPassword
   64     aep: ACI-AEP
   65     description: default
   66     state: present
   67   delegate_to: localhost
   68 
   69 - name: Remove an existing AEP
   70   aci_aep:
   71     host: apic
   72     username: admin
   73     password: SomeSecretPassword
   74     aep: ACI-AEP
   75     state: absent
   76   delegate_to: localhost
   77 
   78 - name: Query all AEPs
   79   aci_aep:
   80     host: apic
   81     username: admin
   82     password: SomeSecretPassword
   83     state: query
   84   delegate_to: localhost
   85   register: query_result
   86 
   87 - name: Query a specific AEP
   88   aci_aep:
   89     host: apic
   90     username: admin
   91     password: SomeSecretPassword
   92     aep: ACI-AEP
   93     state: query
   94   delegate_to: localhost
   95   register: query_result
   96 '''
   97 
   98 RETURN = r'''
   99 current:
  100   description: The existing configuration from the APIC after the module has finished
  101   returned: success
  102   type: list
  103   sample:
  104     [
  105         {
  106             "fvTenant": {
  107                 "attributes": {
  108                     "descr": "Production environment",
  109                     "dn": "uni/tn-production",
  110                     "name": "production",
  111                     "nameAlias": "",
  112                     "ownerKey": "",
  113                     "ownerTag": ""
  114                 }
  115             }
  116         }
  117     ]
  118 error:
  119   description: The error information as returned from the APIC
  120   returned: failure
  121   type: dict
  122   sample:
  123     {
  124         "code": "122",
  125         "text": "unknown managed object class foo"
  126     }
  127 raw:
  128   description: The raw output returned by the APIC REST API (xml or json)
  129   returned: parse error
  130   type: str
  131   sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
  132 sent:
  133   description: The actual/minimal configuration pushed to the APIC
  134   returned: info
  135   type: list
  136   sample:
  137     {
  138         "fvTenant": {
  139             "attributes": {
  140                 "descr": "Production environment"
  141             }
  142         }
  143     }
  144 previous:
  145   description: The original configuration from the APIC before the module has started
  146   returned: info
  147   type: list
  148   sample:
  149     [
  150         {
  151             "fvTenant": {
  152                 "attributes": {
  153                     "descr": "Production",
  154                     "dn": "uni/tn-production",
  155                     "name": "production",
  156                     "nameAlias": "",
  157                     "ownerKey": "",
  158                     "ownerTag": ""
  159                 }
  160             }
  161         }
  162     ]
  163 proposed:
  164   description: The assembled configuration from the user-provided parameters
  165   returned: info
  166   type: dict
  167   sample:
  168     {
  169         "fvTenant": {
  170             "attributes": {
  171                 "descr": "Production environment",
  172                 "name": "production"
  173             }
  174         }
  175     }
  176 filter_string:
  177   description: The filter string used for the request
  178   returned: failure or debug
  179   type: str
  180   sample: ?rsp-prop-include=config-only
  181 method:
  182   description: The HTTP method used for the request to the APIC
  183   returned: failure or debug
  184   type: str
  185   sample: POST
  186 response:
  187   description: The HTTP response from the APIC
  188   returned: failure or debug
  189   type: str
  190   sample: OK (30 bytes)
  191 status:
  192   description: The HTTP status from the APIC
  193   returned: failure or debug
  194   type: int
  195   sample: 200
  196 url:
  197   description: The HTTP url used for the request to the APIC
  198   returned: failure or debug
  199   type: str
  200   sample: https://10.11.12.13/api/mo/uni/tn-production.json
  201 '''
  202 
  203 from ansible.module_utils.basic import AnsibleModule
  204 from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
  205 
  206 
  207 def main():
  208     argument_spec = aci_argument_spec()
  209     argument_spec.update(
  210         aep=dict(type='str', aliases=['name', 'aep_name']),  # Not required for querying all objects
  211         description=dict(type='str', aliases=['descr']),
  212         infra_vlan=dict(type='bool', aliases=['infrastructure_vlan']),
  213         state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
  214     )
  215 
  216     module = AnsibleModule(
  217         argument_spec=argument_spec,
  218         supports_check_mode=True,
  219         required_if=[
  220             ['state', 'absent', ['aep']],
  221             ['state', 'present', ['aep']],
  222         ],
  223     )
  224 
  225     aep = module.params['aep']
  226     description = module.params['description']
  227     infra_vlan = module.params['infra_vlan']
  228     state = module.params['state']
  229 
  230     if infra_vlan:
  231         child_configs = [dict(infraProvAcc=dict(attributes=dict(name='provacc')))]
  232     elif infra_vlan is False:
  233         child_configs = [dict(infraProvAcc=dict(attributes=dict(name='provacc', status='deleted')))]
  234     else:
  235         child_configs = []
  236 
  237     aci = ACIModule(module)
  238     aci.construct_url(
  239         root_class=dict(
  240             aci_class='infraAttEntityP',
  241             aci_rn='infra/attentp-{0}'.format(aep),
  242             module_object=aep,
  243             target_filter={'name': aep},
  244         ),
  245     )
  246     aci.get_existing()
  247 
  248     if state == 'present':
  249         aci.payload(
  250             aci_class='infraAttEntityP',
  251             class_config=dict(
  252                 name=aep,
  253                 descr=description,
  254             ),
  255             child_configs=child_configs,
  256         )
  257 
  258         aci.get_diff(aci_class='infraAttEntityP')
  259 
  260         aci.post_config()
  261 
  262     elif state == 'absent':
  263         aci.delete_config()
  264 
  265     aci.exit_json()
  266 
  267 
  268 if __name__ == "__main__":
  269     main()