Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added subject label functionality to external EPGs #320

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,7 @@ $RECYCLE.BIN/
.vscode

# Ansible Collection tarball
cisco-aci-*.tar.gz
cisco-aci-*.tar.gz

# Virtualenv
.venv/
46 changes: 46 additions & 0 deletions plugins/modules/aci_contract_subject.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@
description:
- The alias for the current object. This relates to the nameAlias field in ACI.
type: str
subject_label:
description:
- The label applid to this contract subject
type: str
subject_label_direction:
description:
- Use C(consumer) to add a consumed label and C(provider) to add a provided label to this contract
type: str
choices: [ consumer, provider ]
extends_documentation_fragment:
- cisco.aci.aci
- cisco.aci.annotation
Expand All @@ -94,6 +103,7 @@
link: https://developer.cisco.com/docs/apic-mim-ref/
author:
- Swetha Chunduri (@schunduri)
- Mark Ciecior (@markciecior)
"""

EXAMPLES = r"""
Expand All @@ -112,6 +122,23 @@
state: present
register: query_result

- name: Add a label to a contract subject
cisco.aci.aci_contract_subject:
host: apic
username: admin
password: SomeSecretPassword
tenant: production
contract: web_to_db
subject: default
description: test
reverse_filter: yes
priority: level1
dscp: unspecified
subject_label: MyLabel
subject_label_direction: consumer
state: present
register: query_result

- name: Remove a contract subject
cisco.aci.aci_contract_subject:
host: apic
Expand Down Expand Up @@ -260,6 +287,10 @@
none="None",
)

SUBJ_LABEL_MAPPING = dict(
consumer="vzConsSubjLbl",
provider="vzProvSubjLbl",
)

def main():
argument_spec = aci_argument_spec()
Expand Down Expand Up @@ -304,6 +335,8 @@ def main():
provider_match=dict(type="str", choices=["all", "at_least_one", "at_most_one", "none"]),
state=dict(type="str", default="present", choices=["absent", "present", "query"]),
name_alias=dict(type="str"),
subject_label=dict(type="str"),
subject_label_direction=dict(type="str", choices=["consumer", "provider"]),
)

module = AnsibleModule(
Expand Down Expand Up @@ -332,6 +365,12 @@ def main():
state = module.params.get("state")
tenant = module.params.get("tenant")
name_alias = module.params.get("name_alias")
subject_label = module.params.get("subject_label")
subject_label_direction = module.params.get("subject_label_direction")

subject_label_class = SUBJ_LABEL_MAPPING[subject_label_direction]

child_classes = [subject_label_class]

aci.construct_url(
root_class=dict(
Expand All @@ -352,11 +391,17 @@ def main():
module_object=subject,
target_filter={"name": subject},
),
child_classes=child_classes,
)

aci.get_existing()

if state == "present":
child_configs = []
if subject_label:
child_configs.append(
{subject_label_class: {"attributes": {"name": subject_label}}}
)
aci.payload(
aci_class="vzSubj",
class_config=dict(
Expand All @@ -369,6 +414,7 @@ def main():
descr=description,
nameAlias=name_alias,
),
child_configs=child_configs
)

aci.get_diff(aci_class="vzSubj")
Expand Down
18 changes: 17 additions & 1 deletion plugins/modules/aci_epg.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec

SUBJ_LABEL_MAPPING = dict(
consumer="vzConsSubjLbl",
provider="vzProvSubjLbl",
)

def main():
argument_spec = aci_argument_spec()
Expand All @@ -341,6 +345,8 @@ def main():
name_alias=dict(type="str"),
monitoring_policy=dict(type="str"),
custom_qos_policy=dict(type="str"),
subject_label=dict(type="str"),
subject_label_direction=dict(type="str", choices=["consumer", "provider"]),
useg=dict(type="str", choices=['yes', 'no']),
)

Expand Down Expand Up @@ -369,9 +375,19 @@ def main():
monitoring_policy = module.params.get("monitoring_policy")
custom_qos_policy = module.params.get("custom_qos_policy")
useg = module.params.get("useg")
subject_label = module.params.get("subject_label")
subject_label_direction = module.params.get("subject_label_direction")

subject_label_class = SUBJ_LABEL_MAPPING[subject_label_direction]

child_classes = ["fvRsBd", "fvRsAEPgMonPol", "fvRsCustQosPol"]

child_configs = [dict(fvRsBd=dict(attributes=dict(tnFvBDName=bd))), dict(fvRsAEPgMonPol=dict(attributes=dict(tnMonEPGPolName=monitoring_policy)))]

if subject_label_direction is not None:
child_classes.append(subject_label_class)
child_configs.append({subject_label_class: {"attributes": {"name": subject_label}}})

if custom_qos_policy is not None:
child_configs.append(dict(fvRsCustQosPol=dict(attributes=dict(tnQosCustomPolName=custom_qos_policy))))

Expand All @@ -394,7 +410,7 @@ def main():
module_object=epg,
target_filter={"name": epg},
),
child_classes=["fvRsBd", "fvRsAEPgMonPol", "fvRsCustQosPol"],
child_classes=child_classes,
)

aci.get_existing()
Expand Down
35 changes: 35 additions & 0 deletions plugins/modules/aci_l3out_extepg_to_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
- This is configurable for provided contracts.
type: str
choices: ['all', 'at_least_one', 'at_most_one', 'none']
subject_label:
description:
- The label to be applied to this contract relationship
type: str
state:
description:
- Use C(present) or C(absent) for adding or removing.
Expand Down Expand Up @@ -89,6 +93,20 @@
state: present
delegate_to: localhost

- name: Add a subject label to an external EPG
cisco.aci.aci_l3out_extepg_to_contract:
host: apic
username: admin
password: SomeSecretePassword
tenant: Auto-Demo
l3out: l3out
extepg : testEpg
contract: contract1
contract_type: provider
subject_label: my_test_label
state: present
delegate_to: localhost

- name: Remove existing contract from an external EPG
cisco.aci.aci_l3out_extepg_to_contract:
host: apic
Expand Down Expand Up @@ -253,6 +271,11 @@
none="None",
)

SUBJ_LABEL_MAPPING = dict(
consumer="vzConsSubjLbl",
provider="vzProvSubjLbl",
)


def main():
argument_spec = aci_argument_spec()
Expand All @@ -266,6 +289,7 @@ def main():
state=dict(type="str", default="present", choices=["absent", "present", "query"]),
tenant=dict(type="str"),
extepg=dict(type="str", aliases=["extepg_name", "external_epg"]),
subject_label=dict(type="str")
)
module = AnsibleModule(
argument_spec=argument_spec,
Expand All @@ -286,13 +310,17 @@ def main():
provider_match = PROVIDER_MATCH_MAPPING.get(provider_match)
state = module.params.get("state")
tenant = module.params.get("tenant")
subject_label = module.params.get("subject_label")

aci_class = ACI_CLASS_MAPPING.get(contract_type)["class"]
aci_rn = ACI_CLASS_MAPPING.get(contract_type)["rn"]
subject_label_class = SUBJ_LABEL_MAPPING[contract_type]

if contract_type == "consumer" and provider_match is not None:
module.fail_json(msg="the 'provider_match' is only configurable for Provided Contracts")

child_classes = [subject_label_class]

aci = ACIModule(module)
aci.construct_url(
root_class=dict(
Expand All @@ -319,18 +347,25 @@ def main():
module_object=contract,
target_filter={"tnVzBrCPName": contract},
),
child_classes=child_classes,
)

aci.get_existing()

if state == "present":
child_configs = []
if subject_label:
child_configs.append(
{subject_label_class: {"attributes": {"name": subject_label}}}
)
aci.payload(
aci_class=aci_class,
class_config=dict(
matchT=provider_match,
prio=priority,
tnVzBrCPName=contract,
),
child_configs=child_configs,
)

aci.get_diff(aci_class=aci_class)
Expand Down
Loading