We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
aci_epg_to_domain: Module does not need to support OpenStack
_From @nilloBE on October 10, 2017 9:11_

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
aci_epg_to_domain

##### ANSIBLE VERSION
v2.5

##### SUMMARY
The module aci_epg_to_domain allows mapping an EPG to a Physical or Virtual Domain in ACI. The Virtual Domain allows the user to specify the domain type selecting VMware, Microsoft or OpenStack.

In this setting, OpenStack should be removed because the OpenStack EPGs should not be created or manipulated directly via Ansible, but instead via Neutron. 

_Copied from original issue: datacenter/aci-ansible#163_

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `lib/ansible/modules/network/aci/aci_epg_to_domain.py`
Content:
```
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': 'community'}
12 
13 DOCUMENTATION = r'''
14 ---
15 module: aci_epg_to_domain
16 short_description: Bind EPGs to Domains on Cisco ACI fabrics (fv:RsDomAtt)
17 description:
18 - Bind EPGs to Physical and Virtual Domains on Cisco ACI fabrics.
19 - More information from the internal APIC class I(fv:RsDomAtt) at
20   U(https://developer.cisco.com/media/mim-ref/MO-fvRsDomAtt.html).
21 author:
22 - Jacob McGill (@jmcgill298)
23 version_added: '2.4'
24 notes:
25 - The C(tenant), C(ap), C(epg), and C(domain) used must exist before using this module in your playbook.
26   The M(aci_tenant) M(aci_ap), M(aci_epg) M(aci_domain) modules can be used for this.
27 options:
28   allow_useg:
29     description:
30     - Allows micro-segmentation.
31     - The APIC defaults new EPG to Domain bindings to use C(encap).
32     choices: [ encap, useg ]
33     default: encap
34   ap:
35     description:
36     - Name of an existing application network profile, that will contain the EPGs.
37     aliases: [ app_profile, app_profile_name ]
38   deploy_immediacy:
39     description:
40     - Determines when the policy is pushed to hardware Policy CAM.
41     - The APIC defaults new EPG to Domain bindings to C(lazy).
42     choices: [ immediate, lazy ]
43     default: lazy
44   domain:
45     description:
46     - Name of the physical or virtual domain being associated with the EPG.
47     aliases: [ domain_name, domain_profile ]
48   domain_type:
49     description:
50     - Determines if the Domain is physical (phys) or virtual (vmm).
51     choices: [ phys, vmm ]
52     aliases: [ type ]
53   encap:
54     description:
55     - The VLAN encapsulation for the EPG when binding a VMM Domain with static encap_mode.
56     - This acts as the secondary encap when using useg.
57     choices: [ range from 1 to 4096 ]
58   encap_mode:
59     description:
60     - The ecapsulataion method to be used.
61     - The APIC defaults new EPG to Domain bindings to C(auto).
62     choices: [ auto, vlan, vxlan ]
63     default: auto
64   epg:
65     description:
66     - Name of the end point group.
67     aliases: [ epg_name ]
68   netflow:
69     description:
70     - Determines if netflow should be enabled.
71     - The APIC defaults new EPG to Domain binings to C(disabled).
72     choices: [ disabled, enabled ]
73     default: disabled
74   primary_encap:
75     description:
76     - Determines the primary VLAN ID when using useg.
77     choices: [ range from 1 to 4096 ]
78   resolution_immediacy:
79     description:
80     - Determines when the policies should be resolved and available.
81     - The APIC defaults new EPG to Domain bindings to C(lazy).
82     choices: [ immediate, lazy, pre-provision ]
83     default: lazy
84   state:
85     description:
86     - Use C(present) or C(absent) for adding or removing.
87     - Use C(query) for listing an object or multiple objects.
88     choices: [ absent, present, query ]
89     default: present
90   tenant:
91     description:
92     - Name of an existing tenant.
93     aliases: [ tenant_name ]
94   vm_provider:
95     description:
96     - The VM platform for VMM Domains.
97     choices: [ microsoft, openstack, vmware ]
98 extends_documentation_fragment: aci
99 '''
100 
101 EXAMPLES = r''' # '''
102 
103 RETURN = r''' # '''
104 
105 from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
106 from ansible.module_utils.basic import AnsibleModule
107 
108 VM_PROVIDER_MAPPING = dict(
109     microsoft="uni/vmmp-Microsoft/dom-",
110     openstack="uni/vmmp-OpenStack/dom-",
111     vmware="uni/vmmp-VMware/dom-",
112 )
113 
114 
115 def main():
116     argument_spec = aci_argument_spec
117     argument_spec.update(
118         allow_useg=dict(type='str', choices=['encap', 'useg']),
119         ap=dict(type='str', aliases=['app_profile', 'app_profile_name']),
120         deploy_immediacy=dict(type='str', choices=['immediate', 'on-demand']),
121         domain=dict(type='str', aliases=['domain_name', 'domain_profile']),
122         domain_type=dict(type='str', choices=['phys', 'vmm'], aliases=['type']),
123         encap=dict(type='int'),
124         encap_mode=dict(type='str', choices=['auto', 'vlan', 'vxlan']),
125         epg=dict(type='str', aliases=['name', 'epg_name']),
126         netflow=dict(type='str', choices=['disabled', 'enabled']),
127         primary_encap=dict(type='int'),
128         resolution_immediacy=dict(type='str', choices=['immediate', 'lazy', 'pre-provision']),
129         state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
130         tenant=dict(type='str', aliases=['tenant_name']),
131         vm_provider=dict(type='str', choices=['microsoft', 'openstack', 'vmware']),
132         method=dict(type='str', choices=['delete', 'get', 'post'], aliases=['action'], removed_in_version='2.6'),  # Deprecated starting from v2.6
133     )
134 
135     module = AnsibleModule(
136         argument_spec=argument_spec,
137         supports_check_mode=True,
138         required_if=[
139             ['domain_type', 'vmm', ['vm_provider']],
140             ['state', 'absent', ['ap', 'domain', 'domain_type', 'epg', 'tenant']],
141             ['state', 'present', ['ap', 'domain', 'domain_type', 'epg', 'tenant']],
142         ],
143     )
144 
145     allow_useg = module.params['allow_useg']
146     ap = module.params['ap']
147     deploy_immediacy = module.params['deploy_immediacy']
148     domain = module.params['domain']
149     domain_type = module.params['domain_type']
150     vm_provider = module.params['vm_provider']
151     encap = module.params['encap']
152     if encap is not None:
153         if encap in range(1, 4097):
154             encap = 'vlan-{0}'.format(encap)
155         else:
156             module.fail_json(msg='Valid VLAN assigments are from 1 to 4096')
157     encap_mode = module.params['encap_mode']
158     epg = module.params['epg']
159     netflow = module.params['netflow']
160     primary_encap = module.params['primary_encap']
161     if primary_encap is not None:
162         if primary_encap in range(1, 4097):
163             primary_encap = 'vlan-{0}'.format(primary_encap)
164         else:
165             module.fail_json(msg='Valid VLAN assigments are from 1 to 4096')
166     resolution_immediacy = module.params['resolution_immediacy']
167     state = module.params['state']
168     tenant = module.params['tenant']
169 
170     if domain_type == 'phys' and vm_provider is not None:
171         module.fail_json(msg="Domain type 'phys' cannot have a 'vm_provider'")
172 
173     # Compile the full domain for URL building
174     if domain_type == 'vmm':
175         epg_domain = '{0}{1}'.format(VM_PROVIDER_MAPPING[vm_provider], domain)
176     elif domain_type is not None:
177         epg_domain = 'uni/phys-{0}'.format(domain)
178     else:
179         epg_domain = None
180 
181     aci = ACIModule(module)
182     aci.construct_url(
183         root_class=dict(
184             aci_class='fvTenant',
185             aci_rn='tn-{0}'.format(tenant),
186             filter_target='eq(fvTenant.name, "{0}")'.format(tenant),
187             module_object=tenant,
188         ),
189         subclass_1=dict(
190             aci_class='fvAp',
191             aci_rn='ap-{0}'.format(ap),
192             filter_target='eq(fvAp.name, "{0}")'.format(ap),
193             module_object=ap,
194         ),
195         subclass_2=dict(
196             aci_class='fvAEPg',
197             aci_rn='epg-{0}'.format(epg),
198             filter_target='eq(fvTenant.name, "{0}")'.format(epg),
199             module_object=epg,
200         ),
201         subclass_3=dict(
202             aci_class='fvRsDomAtt',
203             aci_rn='rsdomAtt-[{0}]'.format(epg_domain),
204             filter_target='eq(fvRsDomAtt.tDn, "{0}")'.format(epg_domain),
205             module_object=epg_domain,
206         ),
207     )
208 
209     aci.get_existing()
210 
211     if state == 'present':
212         # Filter out module parameters with null values
213         aci.payload(
214             aci_class='fvRsDomAtt',
215             class_config=dict(
216                 classPref=allow_useg,
217                 encap=encap,
218                 encapMode=encap_mode,
219                 instrImedcy=deploy_immediacy,
220                 netflowPref=netflow,
221                 primaryEncap=primary_encap,
222                 resImedcy=resolution_immediacy,
223             ),
224         )
225 
226         # Generate config diff which will be used as POST request body
227         aci.get_diff(aci_class='fvRsDomAtt')
228 
229         # Submit changes if module not in check_mode and the proposed is different than existing
230         aci.post_config()
231 
232     elif state == 'absent':
233         aci.delete_config()
234 
235     module.exit_json(**aci.result)
236 
237 
238 if __name__ == "__main__":
239     main()
240
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/lib/ansible/modules/network/aci/aci_epg_to_domain.py b/lib/ansible/modules/network/aci/aci_epg_to_domain.py
--- a/lib/ansible/modules/network/aci/aci_epg_to_domain.py
+++ b/lib/ansible/modules/network/aci/aci_epg_to_domain.py
@@ -24,6 +24,9 @@
 notes:
 - The C(tenant), C(ap), C(epg), and C(domain) used must exist before using this module in your playbook.
   The M(aci_tenant) M(aci_ap), M(aci_epg) M(aci_domain) modules can be used for this.
+- OpenStack VMM domains must not be created using this module. The OpenStack VMM domain is created directly
+  by the Cisco APIC Neutron plugin as part of the installation and configuration.
+  This module can be used to query status of an OpenStack VMM domain.
 options:
   allow_useg:
     description:

{"golden_diff": "diff --git a/lib/ansible/modules/network/aci/aci_epg_to_domain.py b/lib/ansible/modules/network/aci/aci_epg_to_domain.py\n--- a/lib/ansible/modules/network/aci/aci_epg_to_domain.py\n+++ b/lib/ansible/modules/network/aci/aci_epg_to_domain.py\n@@ -24,6 +24,9 @@\n notes:\n - The C(tenant), C(ap), C(epg), and C(domain) used must exist before using this module in your playbook.\n   The M(aci_tenant) M(aci_ap), M(aci_epg) M(aci_domain) modules can be used for this.\n+- OpenStack VMM domains must not be created using this module. The OpenStack VMM domain is created directly\n+  by the Cisco APIC Neutron plugin as part of the installation and configuration.\n+  This module can be used to query status of an OpenStack VMM domain.\n options:\n   allow_useg:\n     description:\n", "issue": "aci_epg_to_domain: Module does not need to support OpenStack\n_From @nilloBE on October 10, 2017 9:11_\r\n\r\n##### ISSUE TYPE\r\n - Bug Report\r\n\r\n##### COMPONENT NAME\r\naci_epg_to_domain\r\n\r\n##### ANSIBLE VERSION\r\nv2.5\r\n\r\n##### SUMMARY\r\nThe module aci_epg_to_domain allows mapping an EPG to a Physical or Virtual Domain in ACI. The Virtual Domain allows the user to specify the domain type selecting VMware, Microsoft or OpenStack.\r\n\r\nIn this setting, OpenStack should be removed because the OpenStack EPGs should not be created or manipulated directly via Ansible, but instead via Neutron. \r\n\r\n_Copied from original issue: datacenter/aci-ansible#163_\n", "before_files": [{"content": "#!/usr/bin/python\n# -*- coding: utf-8 -*-\n\n# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)\n\nfrom __future__ import absolute_import, division, print_function\n__metaclass__ = type\n\nANSIBLE_METADATA = {'metadata_version': '1.1',\n                    'status': ['preview'],\n                    'supported_by': 'community'}\n\nDOCUMENTATION = r'''\n---\nmodule: aci_epg_to_domain\nshort_description: Bind EPGs to Domains on Cisco ACI fabrics (fv:RsDomAtt)\ndescription:\n- Bind EPGs to Physical and Virtual Domains on Cisco ACI fabrics.\n- More information from the internal APIC class I(fv:RsDomAtt) at\n  U(https://developer.cisco.com/media/mim-ref/MO-fvRsDomAtt.html).\nauthor:\n- Jacob McGill (@jmcgill298)\nversion_added: '2.4'\nnotes:\n- The C(tenant), C(ap), C(epg), and C(domain) used must exist before using this module in your playbook.\n  The M(aci_tenant) M(aci_ap), M(aci_epg) M(aci_domain) modules can be used for this.\noptions:\n  allow_useg:\n    description:\n    - Allows micro-segmentation.\n    - The APIC defaults new EPG to Domain bindings to use C(encap).\n    choices: [ encap, useg ]\n    default: encap\n  ap:\n    description:\n    - Name of an existing application network profile, that will contain the EPGs.\n    aliases: [ app_profile, app_profile_name ]\n  deploy_immediacy:\n    description:\n    - Determines when the policy is pushed to hardware Policy CAM.\n    - The APIC defaults new EPG to Domain bindings to C(lazy).\n    choices: [ immediate, lazy ]\n    default: lazy\n  domain:\n    description:\n    - Name of the physical or virtual domain being associated with the EPG.\n    aliases: [ domain_name, domain_profile ]\n  domain_type:\n    description:\n    - Determines if the Domain is physical (phys) or virtual (vmm).\n    choices: [ phys, vmm ]\n    aliases: [ type ]\n  encap:\n    description:\n    - The VLAN encapsulation for the EPG when binding a VMM Domain with static encap_mode.\n    - This acts as the secondary encap when using useg.\n    choices: [ range from 1 to 4096 ]\n  encap_mode:\n    description:\n    - The ecapsulataion method to be used.\n    - The APIC defaults new EPG to Domain bindings to C(auto).\n    choices: [ auto, vlan, vxlan ]\n    default: auto\n  epg:\n    description:\n    - Name of the end point group.\n    aliases: [ epg_name ]\n  netflow:\n    description:\n    - Determines if netflow should be enabled.\n    - The APIC defaults new EPG to Domain binings to C(disabled).\n    choices: [ disabled, enabled ]\n    default: disabled\n  primary_encap:\n    description:\n    - Determines the primary VLAN ID when using useg.\n    choices: [ range from 1 to 4096 ]\n  resolution_immediacy:\n    description:\n    - Determines when the policies should be resolved and available.\n    - The APIC defaults new EPG to Domain bindings to C(lazy).\n    choices: [ immediate, lazy, pre-provision ]\n    default: lazy\n  state:\n    description:\n    - Use C(present) or C(absent) for adding or removing.\n    - Use C(query) for listing an object or multiple objects.\n    choices: [ absent, present, query ]\n    default: present\n  tenant:\n    description:\n    - Name of an existing tenant.\n    aliases: [ tenant_name ]\n  vm_provider:\n    description:\n    - The VM platform for VMM Domains.\n    choices: [ microsoft, openstack, vmware ]\nextends_documentation_fragment: aci\n'''\n\nEXAMPLES = r''' # '''\n\nRETURN = r''' # '''\n\nfrom ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec\nfrom ansible.module_utils.basic import AnsibleModule\n\nVM_PROVIDER_MAPPING = dict(\n    microsoft=\"uni/vmmp-Microsoft/dom-\",\n    openstack=\"uni/vmmp-OpenStack/dom-\",\n    vmware=\"uni/vmmp-VMware/dom-\",\n)\n\n\ndef main():\n    argument_spec = aci_argument_spec\n    argument_spec.update(\n        allow_useg=dict(type='str', choices=['encap', 'useg']),\n        ap=dict(type='str', aliases=['app_profile', 'app_profile_name']),\n        deploy_immediacy=dict(type='str', choices=['immediate', 'on-demand']),\n        domain=dict(type='str', aliases=['domain_name', 'domain_profile']),\n        domain_type=dict(type='str', choices=['phys', 'vmm'], aliases=['type']),\n        encap=dict(type='int'),\n        encap_mode=dict(type='str', choices=['auto', 'vlan', 'vxlan']),\n        epg=dict(type='str', aliases=['name', 'epg_name']),\n        netflow=dict(type='str', choices=['disabled', 'enabled']),\n        primary_encap=dict(type='int'),\n        resolution_immediacy=dict(type='str', choices=['immediate', 'lazy', 'pre-provision']),\n        state=dict(type='str', default='present', choices=['absent', 'present', 'query']),\n        tenant=dict(type='str', aliases=['tenant_name']),\n        vm_provider=dict(type='str', choices=['microsoft', 'openstack', 'vmware']),\n        method=dict(type='str', choices=['delete', 'get', 'post'], aliases=['action'], removed_in_version='2.6'),  # Deprecated starting from v2.6\n    )\n\n    module = AnsibleModule(\n        argument_spec=argument_spec,\n        supports_check_mode=True,\n        required_if=[\n            ['domain_type', 'vmm', ['vm_provider']],\n            ['state', 'absent', ['ap', 'domain', 'domain_type', 'epg', 'tenant']],\n            ['state', 'present', ['ap', 'domain', 'domain_type', 'epg', 'tenant']],\n        ],\n    )\n\n    allow_useg = module.params['allow_useg']\n    ap = module.params['ap']\n    deploy_immediacy = module.params['deploy_immediacy']\n    domain = module.params['domain']\n    domain_type = module.params['domain_type']\n    vm_provider = module.params['vm_provider']\n    encap = module.params['encap']\n    if encap is not None:\n        if encap in range(1, 4097):\n            encap = 'vlan-{0}'.format(encap)\n        else:\n            module.fail_json(msg='Valid VLAN assigments are from 1 to 4096')\n    encap_mode = module.params['encap_mode']\n    epg = module.params['epg']\n    netflow = module.params['netflow']\n    primary_encap = module.params['primary_encap']\n    if primary_encap is not None:\n        if primary_encap in range(1, 4097):\n            primary_encap = 'vlan-{0}'.format(primary_encap)\n        else:\n            module.fail_json(msg='Valid VLAN assigments are from 1 to 4096')\n    resolution_immediacy = module.params['resolution_immediacy']\n    state = module.params['state']\n    tenant = module.params['tenant']\n\n    if domain_type == 'phys' and vm_provider is not None:\n        module.fail_json(msg=\"Domain type 'phys' cannot have a 'vm_provider'\")\n\n    # Compile the full domain for URL building\n    if domain_type == 'vmm':\n        epg_domain = '{0}{1}'.format(VM_PROVIDER_MAPPING[vm_provider], domain)\n    elif domain_type is not None:\n        epg_domain = 'uni/phys-{0}'.format(domain)\n    else:\n        epg_domain = None\n\n    aci = ACIModule(module)\n    aci.construct_url(\n        root_class=dict(\n            aci_class='fvTenant',\n            aci_rn='tn-{0}'.format(tenant),\n            filter_target='eq(fvTenant.name, \"{0}\")'.format(tenant),\n            module_object=tenant,\n        ),\n        subclass_1=dict(\n            aci_class='fvAp',\n            aci_rn='ap-{0}'.format(ap),\n            filter_target='eq(fvAp.name, \"{0}\")'.format(ap),\n            module_object=ap,\n        ),\n        subclass_2=dict(\n            aci_class='fvAEPg',\n            aci_rn='epg-{0}'.format(epg),\n            filter_target='eq(fvTenant.name, \"{0}\")'.format(epg),\n            module_object=epg,\n        ),\n        subclass_3=dict(\n            aci_class='fvRsDomAtt',\n            aci_rn='rsdomAtt-[{0}]'.format(epg_domain),\n            filter_target='eq(fvRsDomAtt.tDn, \"{0}\")'.format(epg_domain),\n            module_object=epg_domain,\n        ),\n    )\n\n    aci.get_existing()\n\n    if state == 'present':\n        # Filter out module parameters with null values\n        aci.payload(\n            aci_class='fvRsDomAtt',\n            class_config=dict(\n                classPref=allow_useg,\n                encap=encap,\n                encapMode=encap_mode,\n                instrImedcy=deploy_immediacy,\n                netflowPref=netflow,\n                primaryEncap=primary_encap,\n                resImedcy=resolution_immediacy,\n            ),\n        )\n\n        # Generate config diff which will be used as POST request body\n        aci.get_diff(aci_class='fvRsDomAtt')\n\n        # Submit changes if module not in check_mode and the proposed is different than existing\n        aci.post_config()\n\n    elif state == 'absent':\n        aci.delete_config()\n\n    module.exit_json(**aci.result)\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "lib/ansible/modules/network/aci/aci_epg_to_domain.py"}], "after_files": [{"content": "#!/usr/bin/python\n# -*- coding: utf-8 -*-\n\n# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)\n\nfrom __future__ import absolute_import, division, print_function\n__metaclass__ = type\n\nANSIBLE_METADATA = {'metadata_version': '1.1',\n                    'status': ['preview'],\n                    'supported_by': 'community'}\n\nDOCUMENTATION = r'''\n---\nmodule: aci_epg_to_domain\nshort_description: Bind EPGs to Domains on Cisco ACI fabrics (fv:RsDomAtt)\ndescription:\n- Bind EPGs to Physical and Virtual Domains on Cisco ACI fabrics.\n- More information from the internal APIC class I(fv:RsDomAtt) at\n  U(https://developer.cisco.com/media/mim-ref/MO-fvRsDomAtt.html).\nauthor:\n- Jacob McGill (@jmcgill298)\nversion_added: '2.4'\nnotes:\n- The C(tenant), C(ap), C(epg), and C(domain) used must exist before using this module in your playbook.\n  The M(aci_tenant) M(aci_ap), M(aci_epg) M(aci_domain) modules can be used for this.\n- OpenStack VMM domains must not be created using this module. The OpenStack VMM domain is created directly\n  by the Cisco APIC Neutron plugin as part of the installation and configuration.\n  This module can be used to query status of an OpenStack VMM domain.\noptions:\n  allow_useg:\n    description:\n    - Allows micro-segmentation.\n    - The APIC defaults new EPG to Domain bindings to use C(encap).\n    choices: [ encap, useg ]\n    default: encap\n  ap:\n    description:\n    - Name of an existing application network profile, that will contain the EPGs.\n    aliases: [ app_profile, app_profile_name ]\n  deploy_immediacy:\n    description:\n    - Determines when the policy is pushed to hardware Policy CAM.\n    - The APIC defaults new EPG to Domain bindings to C(lazy).\n    choices: [ immediate, lazy ]\n    default: lazy\n  domain:\n    description:\n    - Name of the physical or virtual domain being associated with the EPG.\n    aliases: [ domain_name, domain_profile ]\n  domain_type:\n    description:\n    - Determines if the Domain is physical (phys) or virtual (vmm).\n    choices: [ phys, vmm ]\n    aliases: [ type ]\n  encap:\n    description:\n    - The VLAN encapsulation for the EPG when binding a VMM Domain with static encap_mode.\n    - This acts as the secondary encap when using useg.\n    choices: [ range from 1 to 4096 ]\n  encap_mode:\n    description:\n    - The ecapsulataion method to be used.\n    - The APIC defaults new EPG to Domain bindings to C(auto).\n    choices: [ auto, vlan, vxlan ]\n    default: auto\n  epg:\n    description:\n    - Name of the end point group.\n    aliases: [ epg_name ]\n  netflow:\n    description:\n    - Determines if netflow should be enabled.\n    - The APIC defaults new EPG to Domain binings to C(disabled).\n    choices: [ disabled, enabled ]\n    default: disabled\n  primary_encap:\n    description:\n    - Determines the primary VLAN ID when using useg.\n    choices: [ range from 1 to 4096 ]\n  resolution_immediacy:\n    description:\n    - Determines when the policies should be resolved and available.\n    - The APIC defaults new EPG to Domain bindings to C(lazy).\n    choices: [ immediate, lazy, pre-provision ]\n    default: lazy\n  state:\n    description:\n    - Use C(present) or C(absent) for adding or removing.\n    - Use C(query) for listing an object or multiple objects.\n    choices: [ absent, present, query ]\n    default: present\n  tenant:\n    description:\n    - Name of an existing tenant.\n    aliases: [ tenant_name ]\n  vm_provider:\n    description:\n    - The VM platform for VMM Domains.\n    choices: [ microsoft, openstack, vmware ]\nextends_documentation_fragment: aci\n'''\n\nEXAMPLES = r''' # '''\n\nRETURN = r''' # '''\n\nfrom ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec\nfrom ansible.module_utils.basic import AnsibleModule\n\nVM_PROVIDER_MAPPING = dict(\n    microsoft=\"uni/vmmp-Microsoft/dom-\",\n    openstack=\"uni/vmmp-OpenStack/dom-\",\n    vmware=\"uni/vmmp-VMware/dom-\",\n)\n\n\ndef main():\n    argument_spec = aci_argument_spec\n    argument_spec.update(\n        allow_useg=dict(type='str', choices=['encap', 'useg']),\n        ap=dict(type='str', aliases=['app_profile', 'app_profile_name']),\n        deploy_immediacy=dict(type='str', choices=['immediate', 'on-demand']),\n        domain=dict(type='str', aliases=['domain_name', 'domain_profile']),\n        domain_type=dict(type='str', choices=['phys', 'vmm'], aliases=['type']),\n        encap=dict(type='int'),\n        encap_mode=dict(type='str', choices=['auto', 'vlan', 'vxlan']),\n        epg=dict(type='str', aliases=['name', 'epg_name']),\n        netflow=dict(type='str', choices=['disabled', 'enabled']),\n        primary_encap=dict(type='int'),\n        resolution_immediacy=dict(type='str', choices=['immediate', 'lazy', 'pre-provision']),\n        state=dict(type='str', default='present', choices=['absent', 'present', 'query']),\n        tenant=dict(type='str', aliases=['tenant_name']),\n        vm_provider=dict(type='str', choices=['microsoft', 'openstack', 'vmware']),\n        method=dict(type='str', choices=['delete', 'get', 'post'], aliases=['action'], removed_in_version='2.6'),  # Deprecated starting from v2.6\n    )\n\n    module = AnsibleModule(\n        argument_spec=argument_spec,\n        supports_check_mode=True,\n        required_if=[\n            ['domain_type', 'vmm', ['vm_provider']],\n            ['state', 'absent', ['ap', 'domain', 'domain_type', 'epg', 'tenant']],\n            ['state', 'present', ['ap', 'domain', 'domain_type', 'epg', 'tenant']],\n        ],\n    )\n\n    allow_useg = module.params['allow_useg']\n    ap = module.params['ap']\n    deploy_immediacy = module.params['deploy_immediacy']\n    domain = module.params['domain']\n    domain_type = module.params['domain_type']\n    vm_provider = module.params['vm_provider']\n    encap = module.params['encap']\n    if encap is not None:\n        if encap in range(1, 4097):\n            encap = 'vlan-{0}'.format(encap)\n        else:\n            module.fail_json(msg='Valid VLAN assigments are from 1 to 4096')\n    encap_mode = module.params['encap_mode']\n    epg = module.params['epg']\n    netflow = module.params['netflow']\n    primary_encap = module.params['primary_encap']\n    if primary_encap is not None:\n        if primary_encap in range(1, 4097):\n            primary_encap = 'vlan-{0}'.format(primary_encap)\n        else:\n            module.fail_json(msg='Valid VLAN assigments are from 1 to 4096')\n    resolution_immediacy = module.params['resolution_immediacy']\n    state = module.params['state']\n    tenant = module.params['tenant']\n\n    if domain_type == 'phys' and vm_provider is not None:\n        module.fail_json(msg=\"Domain type 'phys' cannot have a 'vm_provider'\")\n\n    # Compile the full domain for URL building\n    if domain_type == 'vmm':\n        epg_domain = '{0}{1}'.format(VM_PROVIDER_MAPPING[vm_provider], domain)\n    elif domain_type is not None:\n        epg_domain = 'uni/phys-{0}'.format(domain)\n    else:\n        epg_domain = None\n\n    aci = ACIModule(module)\n    aci.construct_url(\n        root_class=dict(\n            aci_class='fvTenant',\n            aci_rn='tn-{0}'.format(tenant),\n            filter_target='eq(fvTenant.name, \"{0}\")'.format(tenant),\n            module_object=tenant,\n        ),\n        subclass_1=dict(\n            aci_class='fvAp',\n            aci_rn='ap-{0}'.format(ap),\n            filter_target='eq(fvAp.name, \"{0}\")'.format(ap),\n            module_object=ap,\n        ),\n        subclass_2=dict(\n            aci_class='fvAEPg',\n            aci_rn='epg-{0}'.format(epg),\n            filter_target='eq(fvTenant.name, \"{0}\")'.format(epg),\n            module_object=epg,\n        ),\n        subclass_3=dict(\n            aci_class='fvRsDomAtt',\n            aci_rn='rsdomAtt-[{0}]'.format(epg_domain),\n            filter_target='eq(fvRsDomAtt.tDn, \"{0}\")'.format(epg_domain),\n            module_object=epg_domain,\n        ),\n    )\n\n    aci.get_existing()\n\n    if state == 'present':\n        # Filter out module parameters with null values\n        aci.payload(\n            aci_class='fvRsDomAtt',\n            class_config=dict(\n                classPref=allow_useg,\n                encap=encap,\n                encapMode=encap_mode,\n                instrImedcy=deploy_immediacy,\n                netflowPref=netflow,\n                primaryEncap=primary_encap,\n                resImedcy=resolution_immediacy,\n            ),\n        )\n\n        # Generate config diff which will be used as POST request body\n        aci.get_diff(aci_class='fvRsDomAtt')\n\n        # Submit changes if module not in check_mode and the proposed is different than existing\n        aci.post_config()\n\n    elif state == 'absent':\n        aci.delete_config()\n\n    module.exit_json(**aci.result)\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "lib/ansible/modules/network/aci/aci_epg_to_domain.py"}]}