Skip to content

Commit

Permalink
[ignore] Addition of sub class 6 function to 'aci.py' of module_utils…
Browse files Browse the repository at this point in the history
… to accommodate creation of a class deeper in the aci object hierarchy
  • Loading branch information
shrsr committed Oct 2, 2023
1 parent 05acd43 commit 79c2824
Show file tree
Hide file tree
Showing 10 changed files with 520 additions and 177 deletions.
87 changes: 85 additions & 2 deletions plugins/module_utils/aci.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ def construct_url(
subclass_3=None,
subclass_4=None,
subclass_5=None,
subclass_6=None,
child_classes=None,
config_only=True,
):
Expand All @@ -796,6 +797,7 @@ def construct_url(
:type subclass_3: dict
:type subclass_4: dict
:type subclass_5: dict
:type subclass_6: dict
:type child_classes: list
:return: The path and filter_string needed to build the full URL.
"""
Expand All @@ -806,7 +808,9 @@ def construct_url(
else:
self.child_classes = set(child_classes)

if subclass_5 is not None:
if subclass_6 is not None:
self._construct_url_7(root_class, subclass_1, subclass_2, subclass_3, subclass_4, subclass_5, subclass_6, config_only)
elif subclass_5 is not None:
self._construct_url_6(root_class, subclass_1, subclass_2, subclass_3, subclass_4, subclass_5, config_only)
elif subclass_4 is not None:
self._construct_url_5(root_class, subclass_1, subclass_2, subclass_3, subclass_4, config_only)
Expand Down Expand Up @@ -1077,7 +1081,7 @@ def _construct_url_5(self, root, ter, sec, parent, obj, config_only=True):

def _construct_url_6(self, root, quad, ter, sec, parent, obj, config_only=True):
"""
This method is used by construct_url when the object is the fourth-level class.
This method is used by construct_url when the object is the fifth-level class.
"""
root_rn = root.get("aci_rn")
root_obj = root.get("module_object")
Expand Down Expand Up @@ -1145,6 +1149,85 @@ def _construct_url_6(self, root, quad, ter, sec, parent, obj, config_only=True):
# Query for a specific object of the module's class
self.path = "api/mo/uni/{0}/{1}/{2}/{3}/{4}/{5}.json".format(root_rn, quad_rn, ter_rn, sec_rn, parent_rn, obj_rn)

def _construct_url_7(self, root, quin, quad, ter, sec, parent, obj, config_only=True):
"""
This method is used by construct_url when the object is the sixth-level class.
"""
root_rn = root.get("aci_rn")
root_obj = root.get("module_object")
quin_rn = quin.get("aci_rn")
quin_obj = quin.get("module_object")
quad_rn = quad.get("aci_rn")
quad_obj = quad.get("module_object")
ter_rn = ter.get("aci_rn")
ter_obj = ter.get("module_object")
sec_rn = sec.get("aci_rn")
sec_obj = sec.get("module_object")
parent_rn = parent.get("aci_rn")
parent_obj = parent.get("module_object")
obj_class = obj.get("aci_class")
obj_rn = obj.get("aci_rn")
obj_filter = obj.get("target_filter")
mo = obj.get("module_object")

if self.child_classes is None:
self.child_classes = [obj_class]

if self.module.params.get("state") in ("absent", "present"):
# State is absent or present
self.path = "api/mo/uni/{0}/{1}/{2}/{3}/{4}/{5}/{6}.json".format(root_rn, quin_rn, quad_rn, ter_rn, sec_rn, parent_rn, obj_rn)
if config_only:
self.update_qs({"rsp-prop-include": "config-only"})
self.obj_filter = obj_filter
# TODO: Add all missing cases
elif root_obj is None:
self.child_classes.add(obj_class)
self.path = "api/class/{0}.json".format(obj_class)
self.update_qs({"query-target-filter": self.build_filter(obj_class, obj_filter)})
elif quin_obj is None:
self.child_classes.add(obj_class)
self.path = "api/mo/uni/{0}.json".format(root_rn)
# NOTE: No need to select by root_filter
# self.update_qs({'query-target-filter': self.build_filter(root_class, root_filter)})
# TODO: Filter by quin_filter, parent and obj_filter
self.update_qs({"rsp-subtree-filter": self.build_filter(obj_class, obj_filter)})
elif quad_obj is None:
self.child_classes.add(obj_class)
self.path = "api/mo/uni/{0}/{1}.json".format(root_rn, quin_rn)
# NOTE: No need to select by root_filter
# self.update_qs({'query-target-filter': self.build_filter(root_class, root_filter)})
# TODO: Filter by quin_filter, parent and obj_filter
self.update_qs({"rsp-subtree-filter": self.build_filter(obj_class, obj_filter)})
elif ter_obj is None:
self.child_classes.add(obj_class)
self.path = "api/mo/uni/{0}/{1}/{2}.json".format(root_rn, quin_rn, quad_rn)
# NOTE: No need to select by quad_filter
# self.update_qs({'query-target-filter': self.build_filter(quin_class, quin_filter)})
# TODO: Filter by ter_filter, parent and obj_filter
self.update_qs({"rsp-subtree-filter": self.build_filter(obj_class, obj_filter)})
elif sec_obj is None:
self.child_classes.add(obj_class)
self.path = "api/mo/uni/{0}/{1}/{2}/{3}.json".format(root_rn, quin_rn, quad_rn, ter_rn)
# NOTE: No need to select by ter_filter
# self.update_qs({'query-target-filter': self.build_filter(ter_class, ter_filter)})
# TODO: Filter by sec_filter, parent and obj_filter
self.update_qs({"rsp-subtree-filter": self.build_filter(obj_class, obj_filter)})
elif parent_obj is None:
self.child_classes.add(obj_class)
self.path = "api/mo/uni/{0}/{1}/{2}/{3}/{4}.json".format(root_rn, quin_rn, quad_rn, ter_rn, sec_rn)
# NOTE: No need to select by sec_filter
# self.update_qs({'query-target-filter': self.build_filter(sec_class, sec_filter)})
# TODO: Filter by parent_filter and obj_filter
self.update_qs({"rsp-subtree-filter": self.build_filter(obj_class, obj_filter)})
elif mo is None:
self.child_classes.add(obj_class)
self.path = "api/mo/uni/{0}/{1}/{2}/{3}/{4}/{5}.json".format(root_rn, quin_rn, quad_rn, ter_rn, sec_rn, parent_rn)
# NOTE: No need to select by parent_filter
# self.update_qs({'query-target-filter': self.build_filter(parent_class, parent_filter)})
else:
# Query for a specific object of the module's class
self.path = "api/mo/uni/{0}/{1}/{2}/{3}/{4}/{5}/{6}.json".format(root_rn, quin_rn, quad_rn, ter_rn, sec_rn, parent_rn, obj_rn)

def delete_config(self):
"""
This method is used to handle the logic when the modules state is equal to absent. The method only pushes a change if
Expand Down
23 changes: 20 additions & 3 deletions plugins/modules/aci_l3out_floating_svi.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@
- IP address.
type: str
aliases: [ addr, ip_address ]
mac_address:
description:
- The MAC address option of the interface.
type: str
link_local_address:
description:
- The link local address option of the interface.
type: str
mtu:
description:
- Interface MTU.
Expand Down Expand Up @@ -325,7 +333,6 @@ def main():
encap=dict(type="str"),
encap_scope=dict(type="str", choices=["vrf", "local"]),
auto_state=dict(type="str", choices=["enabled", "disabled"]),
description=dict(type="str", aliases=["descr"]),
external_bridge_group_profile=dict(type="str"),
dscp=dict(
type="str",
Expand Down Expand Up @@ -374,6 +381,8 @@ def main():
address = module.params.get("address")
mtu = module.params.get("mtu")
ipv6_dad = module.params.get("ipv6_dad")
link_local_address = module.params.get("link_local_address")
mac_address = module.params.get("mac_address")
mode = module.params.get("mode")
encap = module.params.get("encap")
encap_scope = "ctx" if module.params.get("encap_scope") == "vrf" else module.params.get("encap_scope")
Expand Down Expand Up @@ -441,7 +450,6 @@ def main():
l3extRsBdProfile=dict(
attributes=dict(
tDn="uni/tn-{0}/bdprofile-{1}".format(tenant, external_bridge_group_profile),

),
)
)
Expand All @@ -453,7 +461,16 @@ def main():
aci.payload(
aci_class="l3extVirtualLIfP",
class_config=dict(
addr=address, ipv6Dad=ipv6_dad, mtu=mtu, ifInstT="ext-svi", mode=mode, encap=encap, encapScope=encap_scope, autostate=auto_state
addr=address,
ipv6Dad=ipv6_dad,
mtu=mtu,
ifInstT="ext-svi",
mode=mode,
encap=encap,
encapScope=encap_scope,
autostate=auto_state,
llAddr=link_local_address,
mac=mac_address,
),
child_configs=child_configs,
)
Expand Down
49 changes: 34 additions & 15 deletions plugins/modules/aci_l3out_floating_svi_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,34 @@
description:
- Pod to build the interface on.
type: str
required: true
node_id:
description:
- Node to build the interface on for Port-channels and single ports.
type: str
required: true
encap:
description:
- Encapsulation on the interface (e.g. "vlan-500")
type: str
required: true
address:
description:
- IP address of the floating SVI interface.
type: str
aliases: [ addr, ip_address ]
domain:
description:
- This option allows virtual machines to send frames with a mac address.
type: str
choices: [ enable, disable ]
domain_type:
description:
- The domain type of the path.
type: str
choices: [ physical, vmware ]
access_encap:
description:
- The port encapsulation.
- The port encapsulation option.
type: str
floating_ip:
description:
Expand All @@ -71,17 +82,20 @@
description:
- This option allows virtual machines to send frames with a mac address.
type: str
choices: [ enable, disable ]
choices: [ enabled, disabled ]
default: disabled
mac_change:
description:
- The status of the mac address change support for port groups in an external VMM controller.
type: str
choices: [ enable, disable ]
choices: [ enabled, disabled ]
default: disabled
promiscuous_mode:
description:
- The status of promiscuous mode for port groups in an external VMM controller.
type: str
choices: [ enable, disable ]
choices: [ enabled, disabled ]
default: disabled
enhanced_lag_policy:
description:
- The enhanced lag policy of the path.
Expand Down Expand Up @@ -320,13 +334,15 @@ def main():
pod_id=dict(type="str", required=True),
node_id=dict(type="str", required=True),
encap=dict(type="str", required=True),
floating_ip=dict(type="str", aliases=["floating_address"], required=True),
forged_transmit=dict(type="str", choices=["enabled", "disabled"]),
mac_change=dict(type="str", choices=["enabled", "disabled"]),
promiscuous_mode=dict(type="str", choices=["enabled", "disabled"]),
domain_type=dict(type="str", choices=["physical", "vmware"], required=True),
domain=dict(type="str", required=True),
address=dict(type="str", aliases=["addr", "ip_address"]),
floating_ip=dict(type="str", aliases=["floating_address"]),
forged_transmit=dict(type="str", choices=["enabled", "disabled"], default="disabled"),
mac_change=dict(type="str", choices=["enabled", "disabled"], default="disabled"),
promiscuous_mode=dict(type="str", choices=["enabled", "disabled"], default="disabled"),
domain_type=dict(type="str", choices=["physical", "vmware"]),
domain=dict(type="str"),
enhanced_lag_policy=dict(type="str"),
access_encap=dict(type="str"),
)

module = AnsibleModule(
Expand All @@ -344,17 +360,19 @@ def main():
node_id = module.params.get("node_id")
floating_ip = module.params.get("floating_ip")
encap = module.params.get("encap")
forged_transmit = module.params.get("forged_transmit")
mac_change = module.params.get("mac_change")
promiscuous_mode = module.params.get("promiscuous_mode")
forged_transmit = module.params.get("forged_transmit").capitalize()
mac_change = module.params.get("mac_change").capitalize()
promiscuous_mode = module.params.get("promiscuous_mode").capitalize()
domain_type = module.params.get("domain_type")
domain = module.params.get("domain")
enhanced_lag_policy = module.params.get("enhanced_lag_policy")
access_encap = module.params.get("access_encap")

aci = ACIModule(module)

node_dn = "topology/pod-{0}/node-{1}".format(pod_id, node_id)

tDn = None
if domain_type == "physical":
tDn = "uni/phys-{0}".format(domain)
elif domain_type == "vmware":
Expand Down Expand Up @@ -401,7 +419,7 @@ def main():

if state == "present":
child_configs = []
if enhanced_lag_policy is not None and domain_type == "virtual":
if enhanced_lag_policy is not None and domain_type == "vmware":
existing_enhanced_lag_policy = ""
if isinstance(aci.existing, list) and len(aci.existing) > 0:
for child in aci.existing[0].get("l3extRsDynPathAtt", {}).get("children", {}):
Expand Down Expand Up @@ -448,6 +466,7 @@ def main():
forgedTransmit=forged_transmit,
macChange=mac_change,
promMode=promiscuous_mode,
encap=access_encap,
),
child_configs=child_configs,
)
Expand Down
Loading

0 comments on commit 79c2824

Please sign in to comment.