Skip to content

Commit

Permalink
[minor_change] Added support for configuring Azure cloud subnets usin…
Browse files Browse the repository at this point in the history
…g the aci_cloud_subnet module.
  • Loading branch information
samiib authored and lhercot committed Feb 28, 2024
1 parent 7e78df2 commit 0ac0017
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 147 deletions.
55 changes: 43 additions & 12 deletions plugins/modules/aci_cloud_subnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# Copyright: (c) 2020, nkatarmal-crest <[email protected]>
# Copyright: (c) 2020, Cindy Zhao <[email protected]>
# Copyright: (c) 2024, Samita Bhattacharjee <[email protected]>
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
Expand All @@ -21,6 +22,7 @@
author:
- Nirav (@nirav)
- Cindy Zhao (@cizhao)
- Samita Bhattacharjee (@samitab)
options:
name:
description:
Expand Down Expand Up @@ -54,17 +56,24 @@
- Address of cloud cidr.
type: str
required: true
availability_zone:
aws_availability_zone:
description:
- The cloud zone which is attached to the given cloud context profile.
- Only used when it is an aws cloud apic.
- Only used when it is an AWS cloud apic.
type: str
aliases: [availability_zone, av_zone, zone]
vnet_gateway:
description:
- Determine if a vNet Gateway Router will be deployed or not.
- Only used when it is an azure cloud apic.
- Only used when it is an Azure cloud apic.
type: bool
default: false
azure_region:
description:
- The Azure cloud region to attach this subnet to.
- Only used when it is an Azure cloud apic.
type: str
aliases: [az_region]
state:
description:
- Use C(present) or C(absent) for adding or removing.
Expand All @@ -78,7 +87,7 @@
"""

EXAMPLES = r"""
- name: Create aci cloud subnet
- name: Create AWS aci cloud subnet
cisco.aci.aci_cloud_subnet:
host: apic
username: userName
Expand All @@ -87,7 +96,21 @@
tenant: anstest
cloud_context_profile: aws_cloudCtxProfile
cidr: '10.10.0.0/16'
availability_zone: us-west-1a
aws_availability_zone: us-west-1a
address: 10.10.0.1
delegate_to: localhost
- name: Create Azure aci cloud subnet
cisco.aci.aci_cloud_subnet:
host: apic
username: userName
password: somePassword
validate_certs: false
tenant: anstest
cloud_context_profile: azure_cloudCtxProfile
cidr: '10.10.0.0/16'
azure_region: westus2
vnet_gateway: true
address: 10.10.0.1
delegate_to: localhost
Expand Down Expand Up @@ -239,15 +262,16 @@ def main():
cloud_context_profile=dict(type="str", required=True),
cidr=dict(type="str", required=True),
state=dict(type="str", default="present", choices=["absent", "present", "query"]),
availability_zone=dict(type="str"),
aws_availability_zone=dict(type="str", aliases=["availability_zone", "av_zone", "zone"]),
azure_region=dict(type="str", aliases=["az_region"]),
)

module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_if=[
["state", "absent", ["address"]],
["state", "present", ["address"]],
["state", "absent", ["tenant", "cloud_context_profile", "cidr", "address"]],
["state", "present", ["tenant", "cloud_context_profile", "cidr", "address"]],
],
)

Expand All @@ -260,9 +284,13 @@ def main():
cloud_context_profile = module.params.get("cloud_context_profile")
cidr = module.params.get("cidr")
state = module.params.get("state")
availability_zone = module.params.get("availability_zone")
aws_availability_zone = module.params.get("aws_availability_zone")
azure_region = module.params.get("azure_region")
child_configs = []

if aws_availability_zone and azure_region:
module.fail_json(msg="Configuring both an AWS availability zone and an Azure region is invalid.")

aci = ACIModule(module)
aci.construct_url(
root_class=dict(aci_class="fvTenant", aci_rn="tn-{0}".format(tenant), target_filter='eq(fvTenant.name, "{0}")'.format(tenant), module_object=tenant),
Expand All @@ -283,11 +311,14 @@ def main():

if state == "present":
# in aws cloud apic
if availability_zone:
region = availability_zone[:-1]
tDn = "uni/clouddomp/provp-aws/region-{0}/zone-{1}".format(region, availability_zone)
if aws_availability_zone:
region = aws_availability_zone[:-1]
tDn = "uni/clouddomp/provp-aws/region-{0}/zone-{1}".format(region, aws_availability_zone)
child_configs.append({"cloudRsZoneAttach": {"attributes": {"tDn": tDn}}})
# in azure cloud apic
if azure_region:
tDn = "uni/clouddomp/provp-azure/region-{0}/zone-default".format(azure_region)
child_configs.append({"cloudRsZoneAttach": {"attributes": {"tDn": tDn}}})
if vnet_gateway:
usage = "gateway"
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/inventory.networking
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cn-dmz-apic-m1-02-v42 ansible_host=173.36.219.68 aci_hostname=173.36.219.68
cn-dmz-apic-m1-03-v52 ansible_host=173.36.219.69 aci_hostname=173.36.219.69
cn-dmz-apic-m1-04-v602h ansible_host=173.36.219.70 aci_hostname=173.36.219.70
aws_cloud ansible_host=52.52.20.121 aci_hostname=52.52.20.121 cloud_type=aws region=us-east-1 region_2=us-west-1 availability_zone=us-west-1a
azure_cloud ansible_host=20.245.236.136 aci_hostname=20.245.236.136 cloud_type=azure region=westus region_2=westus2 vnet_gateway=true
azure_cloud ansible_host=20.245.236.136 aci_hostname=20.245.236.136 cloud_type=azure region=westus region_2=westus2 vnet_gateway=true az_region=westus2

[aci:vars]
aci_username=ansible_github_ci
Expand Down
Loading

0 comments on commit 0ac0017

Please sign in to comment.