"Fossies" - the Fresh Open Source Software Archive

Member "ansible-2.9.27/lib/ansible/modules/network/aci/aci_aep_to_domain.py" (11 Oct 2021, 8979 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_to_domain.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 # Copyright: (c) 2017, Dag Wieers <dag@wieers.com>
    5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
    6 
    7 from __future__ import absolute_import, division, print_function
    8 __metaclass__ = type
    9 
   10 ANSIBLE_METADATA = {'metadata_version': '1.1',
   11                     'status': ['preview'],
   12                     'supported_by': 'certified'}
   13 
   14 DOCUMENTATION = r'''
   15 ---
   16 module: aci_aep_to_domain
   17 short_description: Bind AEPs to Physical or Virtual Domains (infra:RsDomP)
   18 description:
   19 - Bind AEPs to Physical or Virtual Domains on Cisco ACI fabrics.
   20 version_added: '2.5'
   21 options:
   22   aep:
   23     description:
   24     - The name of the Attachable Access Entity Profile.
   25     type: str
   26     aliases: [ aep_name ]
   27   domain:
   28     description:
   29     - Name of the physical or virtual domain being associated with the AEP.
   30     type: str
   31     aliases: [ domain_name, domain_profile ]
   32   domain_type:
   33     description:
   34     - Determines if the Domain is physical (phys) or virtual (vmm).
   35     type: str
   36     choices: [ fc, l2dom, l3dom, phys, vmm ]
   37     aliases: [ type ]
   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
   45   vm_provider:
   46     description:
   47     - The VM platform for VMM Domains.
   48     - Support for Kubernetes was added in ACI v3.0.
   49     - Support for CloudFoundry, OpenShift and Red Hat was added in ACI v3.1.
   50     type: str
   51     choices: [ cloudfoundry, kubernetes, microsoft, openshift, openstack, redhat, vmware ]
   52 extends_documentation_fragment: aci
   53 notes:
   54 - The C(aep) and C(domain) parameters should exist before using this module.
   55   The M(aci_aep) and M(aci_domain) can be used for these.
   56 seealso:
   57 - module: aci_aep
   58 - module: aci_domain
   59 - name: APIC Management Information Model reference
   60   description: More information about the internal APIC class B(infra:RsDomP).
   61   link: https://developer.cisco.com/docs/apic-mim-ref/
   62 author:
   63 - Dag Wieers (@dagwieers)
   64 '''
   65 
   66 EXAMPLES = r'''
   67 - name: Add AEP to domain binding
   68   aci_aep_to_domain: &binding_present
   69     host: apic
   70     username: admin
   71     password: SomeSecretPassword
   72     aep: test_aep
   73     domain: phys_dom
   74     domain_type: phys
   75     state: present
   76   delegate_to: localhost
   77 
   78 - name: Remove AEP to domain binding
   79   aci_aep_to_domain: &binding_absent
   80     host: apic
   81     username: admin
   82     password: SomeSecretPassword
   83     aep: test_aep
   84     domain: phys_dom
   85     domain_type: phys
   86     state: absent
   87   delegate_to: localhost
   88 
   89 - name: Query our AEP to domain binding
   90   aci_aep_to_domain:
   91     host: apic
   92     username: admin
   93     password: SomeSecretPassword
   94     aep: test_aep
   95     domain: phys_dom
   96     domain_type: phys
   97     state: query
   98   delegate_to: localhost
   99   register: query_result
  100 
  101 - name: Query all AEP to domain bindings
  102   aci_aep_to_domain: &binding_query
  103     host: apic
  104     username: admin
  105     password: SomeSecretPassword
  106     state: query
  107   delegate_to: localhost
  108   register: query_result
  109 '''
  110 
  111 RETURN = r'''
  112 current:
  113   description: The existing configuration from the APIC after the module has finished
  114   returned: success
  115   type: list
  116   sample:
  117     [
  118         {
  119             "fvTenant": {
  120                 "attributes": {
  121                     "descr": "Production environment",
  122                     "dn": "uni/tn-production",
  123                     "name": "production",
  124                     "nameAlias": "",
  125                     "ownerKey": "",
  126                     "ownerTag": ""
  127                 }
  128             }
  129         }
  130     ]
  131 error:
  132   description: The error information as returned from the APIC
  133   returned: failure
  134   type: dict
  135   sample:
  136     {
  137         "code": "122",
  138         "text": "unknown managed object class foo"
  139     }
  140 raw:
  141   description: The raw output returned by the APIC REST API (xml or json)
  142   returned: parse error
  143   type: str
  144   sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
  145 sent:
  146   description: The actual/minimal configuration pushed to the APIC
  147   returned: info
  148   type: list
  149   sample:
  150     {
  151         "fvTenant": {
  152             "attributes": {
  153                 "descr": "Production environment"
  154             }
  155         }
  156     }
  157 previous:
  158   description: The original configuration from the APIC before the module has started
  159   returned: info
  160   type: list
  161   sample:
  162     [
  163         {
  164             "fvTenant": {
  165                 "attributes": {
  166                     "descr": "Production",
  167                     "dn": "uni/tn-production",
  168                     "name": "production",
  169                     "nameAlias": "",
  170                     "ownerKey": "",
  171                     "ownerTag": ""
  172                 }
  173             }
  174         }
  175     ]
  176 proposed:
  177   description: The assembled configuration from the user-provided parameters
  178   returned: info
  179   type: dict
  180   sample:
  181     {
  182         "fvTenant": {
  183             "attributes": {
  184                 "descr": "Production environment",
  185                 "name": "production"
  186             }
  187         }
  188     }
  189 filter_string:
  190   description: The filter string used for the request
  191   returned: failure or debug
  192   type: str
  193   sample: ?rsp-prop-include=config-only
  194 method:
  195   description: The HTTP method used for the request to the APIC
  196   returned: failure or debug
  197   type: str
  198   sample: POST
  199 response:
  200   description: The HTTP response from the APIC
  201   returned: failure or debug
  202   type: str
  203   sample: OK (30 bytes)
  204 status:
  205   description: The HTTP status from the APIC
  206   returned: failure or debug
  207   type: int
  208   sample: 200
  209 url:
  210   description: The HTTP url used for the request to the APIC
  211   returned: failure or debug
  212   type: str
  213   sample: https://10.11.12.13/api/mo/uni/tn-production.json
  214 '''
  215 
  216 from ansible.module_utils.basic import AnsibleModule
  217 from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
  218 
  219 VM_PROVIDER_MAPPING = dict(
  220     cloudfoundry='CloudFoundry',
  221     kubernetes='Kubernetes',
  222     microsoft='Microsoft',
  223     openshift='OpenShift',
  224     openstack='OpenStack',
  225     redhat='Redhat',
  226     vmware='VMware',
  227 )
  228 
  229 
  230 def main():
  231     argument_spec = aci_argument_spec()
  232     argument_spec.update(
  233         aep=dict(type='str', aliases=['aep_name']),  # Not required for querying all objects
  234         domain=dict(type='str', aliases=['domain_name', 'domain_profile']),  # Not required for querying all objects
  235         domain_type=dict(type='str', choices=['fc', 'l2dom', 'l3dom', 'phys', 'vmm'], aliases=['type']),  # Not required for querying all objects
  236         state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
  237         vm_provider=dict(type='str', choices=['cloudfoundry', 'kubernetes', 'microsoft', 'openshift', 'openstack', 'redhat', 'vmware']),
  238     )
  239 
  240     module = AnsibleModule(
  241         argument_spec=argument_spec,
  242         supports_check_mode=True,
  243         required_if=[
  244             ['domain_type', 'vmm', ['vm_provider']],
  245             ['state', 'absent', ['aep', 'domain', 'domain_type']],
  246             ['state', 'present', ['aep', 'domain', 'domain_type']],
  247         ],
  248         required_together=[
  249             ['domain', 'domain_type'],
  250         ],
  251     )
  252 
  253     aep = module.params['aep']
  254     domain = module.params['domain']
  255     domain_type = module.params['domain_type']
  256     vm_provider = module.params['vm_provider']
  257     state = module.params['state']
  258 
  259     # Report when vm_provider is set when type is not virtual
  260     if domain_type != 'vmm' and vm_provider is not None:
  261         module.fail_json(msg="Domain type '{0}' cannot have a 'vm_provider'".format(domain_type))
  262 
  263     # Compile the full domain for URL building
  264     if domain_type == 'fc':
  265         domain_mo = 'uni/fc-{0}'.format(domain)
  266     elif domain_type == 'l2dom':
  267         domain_mo = 'uni/l2dom-{0}'.format(domain)
  268     elif domain_type == 'l3dom':
  269         domain_mo = 'uni/l3dom-{0}'.format(domain)
  270     elif domain_type == 'phys':
  271         domain_mo = 'uni/phys-{0}'.format(domain)
  272     elif domain_type == 'vmm':
  273         domain_mo = 'uni/vmmp-{0}/dom-{1}'.format(VM_PROVIDER_MAPPING[vm_provider], domain)
  274     else:
  275         domain_mo = None
  276 
  277     aci = ACIModule(module)
  278     aci.construct_url(
  279         root_class=dict(
  280             aci_class='infraAttEntityP',
  281             aci_rn='infra/attentp-{0}'.format(aep),
  282             module_object=aep,
  283             target_filter={'name': aep},
  284         ),
  285         subclass_1=dict(
  286             aci_class='infraRsDomP',
  287             aci_rn='rsdomP-[{0}]'.format(domain_mo),
  288             module_object=domain_mo,
  289             target_filter={'tDn': domain_mo},
  290         ),
  291     )
  292 
  293     aci.get_existing()
  294 
  295     if state == 'present':
  296         aci.payload(
  297             aci_class='infraRsDomP',
  298             class_config=dict(tDn=domain_mo),
  299         )
  300 
  301         aci.get_diff(aci_class='infraRsDomP')
  302 
  303         aci.post_config()
  304 
  305     elif state == 'absent':
  306         aci.delete_config()
  307 
  308     aci.exit_json()
  309 
  310 
  311 if __name__ == "__main__":
  312     main()