mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
ACI EPG: Update module to use new URL Method (#28647)
This commit is contained in:
parent
eaea574e3b
commit
05a17164e3
1 changed files with 70 additions and 38 deletions
|
@ -33,21 +33,21 @@ options:
|
||||||
description:
|
description:
|
||||||
- Name of an existing tenant.
|
- Name of an existing tenant.
|
||||||
aliases: [ tenant_name ]
|
aliases: [ tenant_name ]
|
||||||
app_profile:
|
ap:
|
||||||
description:
|
description:
|
||||||
- Name of an existing application network profile, that will contain the EPGs.
|
- Name of an existing application network profile, that will contain the EPGs.
|
||||||
required: yes
|
required: yes
|
||||||
aliases: [ app_profile_name ]
|
aliases: [ app_proifle, app_profile_name ]
|
||||||
epg:
|
epg:
|
||||||
description:
|
description:
|
||||||
- Name of the end point group.
|
- Name of the end point group.
|
||||||
required: yes
|
required: yes
|
||||||
aliases: [ name, epg_name ]
|
aliases: [ name, epg_name ]
|
||||||
bridge_domain:
|
bd:
|
||||||
description:
|
description:
|
||||||
- Name of the bridge domain being associated with the EPG.
|
- Name of the bridge domain being associated with the EPG.
|
||||||
required: yes
|
required: yes
|
||||||
aliases: [ bd_name ]
|
aliases: [ bd_name, bridge_domain ]
|
||||||
priority:
|
priority:
|
||||||
description:
|
description:
|
||||||
- QoS class.
|
- QoS class.
|
||||||
|
@ -65,7 +65,7 @@ options:
|
||||||
fwd_control:
|
fwd_control:
|
||||||
description:
|
description:
|
||||||
- The forwarding control used by the EPG.
|
- The forwarding control used by the EPG.
|
||||||
- The APIC defaults new EPGs to none.
|
- The APIC defaults new EPGs to C(none).
|
||||||
choices: [ none, proxy-arp ]
|
choices: [ none, proxy-arp ]
|
||||||
default: none
|
default: none
|
||||||
state:
|
state:
|
||||||
|
@ -84,22 +84,38 @@ EXAMPLES = r'''
|
||||||
username: admin
|
username: admin
|
||||||
password: SomeSecretPassword
|
password: SomeSecretPassword
|
||||||
tenant: production
|
tenant: production
|
||||||
app_profile: default
|
ap: intranet
|
||||||
epg: app_epg
|
epg: web_epg
|
||||||
description: application EPG
|
description: Web Intranet EPG
|
||||||
bridge_domain: vlan_bd
|
bd: prod_bd
|
||||||
|
|
||||||
|
aci_epg:
|
||||||
|
hostname: apic
|
||||||
|
username: admin
|
||||||
|
password: SomeSecretPassword
|
||||||
|
tenant: production
|
||||||
|
ap: ticketing
|
||||||
|
epg: "{{ item.epg }}"
|
||||||
|
description: Ticketing EPG
|
||||||
|
bd: "{{ item.bd }}"
|
||||||
priority: unspecified
|
priority: unspecified
|
||||||
intra_epg_isolation: unenforced
|
intra_epg_isolation: unenforced
|
||||||
state: present
|
state: present
|
||||||
|
with_items:
|
||||||
|
- epg: web
|
||||||
|
bd: web_bd
|
||||||
|
- epg: database
|
||||||
|
bd: database_bd
|
||||||
|
|
||||||
- name: Remove an EPG
|
- name: Remove an EPG
|
||||||
aci_epg:
|
aci_epg:
|
||||||
hostname: apic
|
hostname: apic
|
||||||
username: admin
|
username: admin
|
||||||
password: SomeSecretPassword
|
password: SomeSecretPassword
|
||||||
|
validate_certs: false
|
||||||
tenant: production
|
tenant: production
|
||||||
app_profile: default
|
app_profile: intranet
|
||||||
epg: app_epg
|
epg: web_epg
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
- name: Query an EPG
|
- name: Query an EPG
|
||||||
|
@ -108,16 +124,34 @@ EXAMPLES = r'''
|
||||||
username: admin
|
username: admin
|
||||||
password: SomeSecretPassword
|
password: SomeSecretPassword
|
||||||
tenant: production
|
tenant: production
|
||||||
app_profile: default
|
ap: ticketing
|
||||||
epg: app_epg
|
epg: web_epg
|
||||||
state: query
|
state: query
|
||||||
|
|
||||||
- name: Query all EPgs
|
- name: Query all EPGs
|
||||||
aci_epg:
|
aci_epg:
|
||||||
hostname: apic
|
hostname: apic
|
||||||
username: admin
|
username: admin
|
||||||
password: SomeSecretPassword
|
password: SomeSecretPassword
|
||||||
state: query
|
state: query
|
||||||
|
|
||||||
|
- name: Query all EPGs with a Specific Name
|
||||||
|
aci_epg:
|
||||||
|
hostname: apic
|
||||||
|
username: admin
|
||||||
|
password: SomeSecretPassword
|
||||||
|
validate_certs: false
|
||||||
|
epg: web_epg
|
||||||
|
state: query
|
||||||
|
|
||||||
|
- name: Query all EPGs of an App Profile
|
||||||
|
aci_epg:
|
||||||
|
hostname: apic
|
||||||
|
username: admin
|
||||||
|
password: SomeSecretPassword
|
||||||
|
validate_certs: false
|
||||||
|
ap: ticketing
|
||||||
|
state: query
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = r'''
|
RETURN = r'''
|
||||||
|
@ -132,8 +166,8 @@ def main():
|
||||||
argument_spec = aci_argument_spec
|
argument_spec = aci_argument_spec
|
||||||
argument_spec.update(
|
argument_spec.update(
|
||||||
epg=dict(type='str', aliases=['name', 'epg_name']),
|
epg=dict(type='str', aliases=['name', 'epg_name']),
|
||||||
bridge_domain=dict(type='str', aliases=['bd_name']),
|
bd=dict(type='str', aliases=['bd_name', 'bridge_domain']),
|
||||||
app_profile=dict(type='str', aliases=['app_profile_name']),
|
ap=dict(type='str', aliases=['app_profile', 'app_profile_name']),
|
||||||
tenant=dict(type='str', aliases=['tenant_name']),
|
tenant=dict(type='str', aliases=['tenant_name']),
|
||||||
description=dict(type='str', aliases=['descr']),
|
description=dict(type='str', aliases=['descr']),
|
||||||
priority=dict(type='str', choices=['level1', 'level2', 'level3', 'unspecified']),
|
priority=dict(type='str', choices=['level1', 'level2', 'level3', 'unspecified']),
|
||||||
|
@ -146,14 +180,14 @@ def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=argument_spec,
|
argument_spec=argument_spec,
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
required_if=[['state', 'absent', ['app_profile', 'epg', 'tenant']],
|
required_if=[
|
||||||
['state', 'present', ['app_profile', 'epg', 'tenant']]]
|
['state', 'absent', ['ap', 'epg', 'tenant']],
|
||||||
|
['state', 'present', ['ap', 'epg', 'tenant']],
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
epg = module.params['epg']
|
epg = module.params['epg']
|
||||||
# app_profile = module.params['app_profile']
|
bd = module.params['bd']
|
||||||
# tenant = module.params['tenant']
|
|
||||||
bridge_domain = module.params['bridge_domain']
|
|
||||||
description = module.params['description']
|
description = module.params['description']
|
||||||
priority = module.params['priority']
|
priority = module.params['priority']
|
||||||
intra_epg_isolation = module.params['intra_epg_isolation']
|
intra_epg_isolation = module.params['intra_epg_isolation']
|
||||||
|
@ -161,26 +195,24 @@ def main():
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
|
|
||||||
aci = ACIModule(module)
|
aci = ACIModule(module)
|
||||||
|
aci.construct_url(root_class="tenant", subclass_1="ap", subclass_2="epg", child_classes=['fvRsBd'])
|
||||||
# TODO: Add logic to handle multiple input variations when query
|
aci.get_existing()
|
||||||
if state != 'query':
|
|
||||||
# Work with a specific EPG
|
|
||||||
path = 'api/mo/uni/tn-%(tenant)s/ap-%(app_profile)s/epg-%(epg)s.json' % module.params
|
|
||||||
filter_string = '?rsp-subtree=children&rsp-subtree-class=fvRsBd&rsp-prop-include=config-only'
|
|
||||||
else:
|
|
||||||
# Query all EPGs
|
|
||||||
path = 'api/class/fvAEPg.json'
|
|
||||||
filter_string = '?rsp-subtree=children&rsp-subtree-class=fvRsBd'
|
|
||||||
|
|
||||||
aci.result['url'] = '%(protocol)s://%(hostname)s/' % aci.params + path
|
|
||||||
|
|
||||||
aci.get_existing(filter_string=filter_string)
|
|
||||||
|
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
# Filter out module parameters with null values
|
# Filter out module parameters with null values
|
||||||
aci.payload(aci_class='fvAEPg', class_config=dict(name=epg, descr=description, prio=priority, pcEnfPref=intra_epg_isolation,
|
aci.payload(
|
||||||
fwdCtrl=fwd_control),
|
aci_class='fvAEPg',
|
||||||
child_configs=[dict(fvRsBd=dict(attributes=dict(tnFvBDName=bridge_domain)))])
|
class_config=dict(
|
||||||
|
name=epg,
|
||||||
|
descr=description,
|
||||||
|
prio=priority,
|
||||||
|
pcEnfPref=intra_epg_isolation,
|
||||||
|
fwdCtrl=fwd_control,
|
||||||
|
),
|
||||||
|
child_configs=[
|
||||||
|
dict(fvRsBd=dict(attributes=dict(tnFvBDName=bd))),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
# Generate config diff which will be used as POST request body
|
# Generate config diff which will be used as POST request body
|
||||||
aci.get_diff(aci_class='fvAEPg')
|
aci.get_diff(aci_class='fvAEPg')
|
||||||
|
|
Loading…
Reference in a new issue